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 $ */
22
33#define POSTGRES_ECPG_INTERNAL
44#include "postgres_fe.h"
@@ -24,6 +24,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
2424{
2525struct sqlca_t * sqlca = ECPGget_sqlca ();
2626char * pval = (char * )PQgetvalue (results ,act_tuple ,act_field );
27+ int value_for_indicator = 0 ;
2728
2829ECPGlog ("ECPGget_data line %d: RESULT: %s offset: %ld\n" ,lineno ,pval ?pval :"" ,offset );
2930
@@ -53,31 +54,34 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
5354/* We will have to decode the value */
5455
5556/*
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
5758 */
5859if (PQgetisnull (results ,act_tuple ,act_field ))
60+ value_for_indicator = -1 ;
61+
62+ switch (ind_type )
5963{
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 ;
7476#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 ;
7981#endif /* HAVE_LONG_LONG_INT_64 */
80- case ECPGt_NO_INDICATOR :
82+ case ECPGt_NO_INDICATOR :
83+ if (value_for_indicator == -1 )
84+ {
8185if (force_indicator == false)
8286{
8387/* 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,
8993ECPGraise (lineno ,ECPG_MISSING_INDICATOR ,NULL );
9094return (false);
9195}
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+ }
98103
104+ if (value_for_indicator == -1 )
99105return (true);
100- }
101106
102107do
103108{