1
- /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.10 2003/07/01 12:40:51 meskes Exp $ */
1
+ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.11 2003/07/08 12:11:28 meskes Exp $ */
2
2
3
3
#define POSTGRES_ECPG_INTERNAL
4
4
#include "postgres_fe.h"
@@ -24,6 +24,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
24
24
{
25
25
struct sqlca_t * sqlca = ECPGget_sqlca ();
26
26
char * pval = (char * )PQgetvalue (results ,act_tuple ,act_field );
27
+ int value_for_indicator = 0 ;
27
28
28
29
ECPGlog ("ECPGget_data line %d: RESULT: %s offset: %ld\n" ,lineno ,pval ?pval :"" ,offset );
29
30
@@ -53,31 +54,34 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
53
54
/* We will have to decode the value */
54
55
55
56
/*
56
- * check for null value and set indicator accordingly
57
+ * check for null value and set indicator accordingly, i.e. -1 if NULL and 0 if not
57
58
*/
58
59
if (PQgetisnull (results ,act_tuple ,act_field ))
60
+ value_for_indicator = -1 ;
61
+
62
+ switch (ind_type )
59
63
{
60
- switch (ind_type )
61
- {
62
- case ECPGt_short :
63
- case ECPGt_unsigned_short :
64
- * ((short * ) (ind + ind_offset * act_tuple ))= -1 ;
65
- break ;
66
- case ECPGt_int :
67
- case ECPGt_unsigned_int :
68
- * ((int * ) (ind + ind_offset * act_tuple ))= -1 ;
69
- break ;
70
- case ECPGt_long :
71
- case ECPGt_unsigned_long :
72
- * ((long * ) (ind + ind_offset * act_tuple ))= -1 ;
73
- break ;
64
+ case ECPGt_short :
65
+ case ECPGt_unsigned_short :
66
+ * ((short * ) (ind + ind_offset * act_tuple ))= value_for_indicator ;
67
+ break ;
68
+ case ECPGt_int :
69
+ case ECPGt_unsigned_int :
70
+ * ((int * ) (ind + ind_offset * act_tuple ))= value_for_indicator ;
71
+ break ;
72
+ case ECPGt_long :
73
+ case ECPGt_unsigned_long :
74
+ * ((long * ) (ind + ind_offset * act_tuple ))= value_for_indicator ;
75
+ break ;
74
76
#ifdef HAVE_LONG_LONG_INT_64
75
- case ECPGt_long_long :
76
- case ECPGt_unsigned_long_long :
77
- * ((long longint * ) (ind + ind_offset * act_tuple ))= -1 ;
78
- break ;
77
+ case ECPGt_long_long :
78
+ case ECPGt_unsigned_long_long :
79
+ * ((long longint * ) (ind + ind_offset * act_tuple ))= value_for_indicator ;
80
+ break ;
79
81
#endif /* HAVE_LONG_LONG_INT_64 */
80
- case ECPGt_NO_INDICATOR :
82
+ case ECPGt_NO_INDICATOR :
83
+ if (value_for_indicator == -1 )
84
+ {
81
85
if (force_indicator == false)
82
86
{
83
87
/* Informix has an additional way to specify NULLs
@@ -89,15 +93,16 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
89
93
ECPGraise (lineno ,ECPG_MISSING_INDICATOR ,NULL );
90
94
return (false);
91
95
}
92
- break ;
93
- default :
94
- ECPGraise (lineno ,ECPG_UNSUPPORTED ,ECPGtype_name (ind_type ));
95
- return (false);
96
- break ;
97
- }
96
+ }
97
+ break ;
98
+ default :
99
+ ECPGraise (lineno ,ECPG_UNSUPPORTED ,ECPGtype_name (ind_type ));
100
+ return (false);
101
+ break ;
102
+ }
98
103
104
+ if (value_for_indicator == -1 )
99
105
return (true);
100
- }
101
106
102
107
do
103
108
{