Skip to content

Commit 3f5a164

Browse files
committed
Hello,
Two patches included: - the first one enables the use of bool variables in fields which might become NULL. Up to now the lib told you that NULL is not a bool variable, even if you provide a indicator. - the second patch checks whether a value is null and issues an error if no indicator is provided. Sidenote: IIRC, the variable should be left alone if the value is NULL. ECPGlib sets it's value to 0 on NULL. Is this a violation of the standard? Regards Christof
1 parent ebb618b commit 3f5a164

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Tue Aug 24 15:53:28 MEST 1999
2+
3+
- made NULL a valid bool value
4+
- check for indicator variables on NULL
5+
16
Wed Feb 11 10:58:13 CET 1998
27

38
- Added '-d' option to turn on debugging.

src/interfaces/ecpg/include/ecpgerrno.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define ECPG_FLOAT_FORMAT -206
2323
#define ECPG_CONVERT_BOOL -207
2424
#define ECPG_EMPTY -208
25+
#define ECPG_MISSING_INDICATOR -209
2526

2627
#define ECPG_NO_CONN -220
2728
#define ECPG_NOT_CONN -221

src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,16 @@ ECPGexecute(struct statement * stmt)
766766
case ECPGt_unsigned_long:
767767
((long *) var->ind_value)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
768768
break;
769+
case ECPGt_NO_INDICATOR:
770+
if (PQgetisnull(results, act_tuple, act_field))
771+
{
772+
register_error(ECPG_MISSING_INDICATOR, "NULL value without indicator variable on line %d.", stmt->lineno);
773+
status = false;
774+
}
775+
break;
769776
default:
777+
register_error(ECPG_UNSUPPORTED, "Unsupported indicator type %s on line %d.", ECPGtype_name(var->ind_type), stmt->lineno);
778+
status = false;
770779
break;
771780
}
772781

@@ -891,6 +900,11 @@ ECPGexecute(struct statement * stmt)
891900
((char *) var->value)[act_tuple] = true;
892901
break;
893902
}
903+
else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
904+
{
905+
// NULL is valid
906+
break;
907+
}
894908
}
895909

896910
register_error(ECPG_CONVERT_BOOL, "Unable to convert %s to bool on line %d.",

0 commit comments

Comments
 (0)