Skip to content

Commit f207718

Browse files
author
Michael Meskes
committed
More informix fixes.
1 parent fee6fd7 commit f207718

File tree

7 files changed

+78
-37
lines changed

7 files changed

+78
-37
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,11 @@ Mon Jul 7 14:13:43 CEST 2003
15581558
Tue Jul 8 09:04:31 CEST 2003
15591559

15601560
- Fixed segfault in ECPGconnect in Informix mode.
1561+
1562+
Tue Jul 8 12:34:00 CEST 2003
1563+
1564+
- Made Informix decimal-ascii conversion honor Informix NULLs.
1565+
- Informix variable handling didn't cope well with arrays.
15611566
- Set ecpg version to 3.0.0
15621567
- Set ecpg library to 4.0.0
15631568
- Set pgtypes library to 1.0.0

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ecpg_informix.h>
99
#include <pgtypes_error.h>
1010
#include <pgtypes_date.h>
11+
#include <sqltypes.h>
1112

1213
char * ECPGalloc(long, int);
1314

@@ -147,8 +148,13 @@ deccvasc(char *cp, int len, Decimal *np)
147148
char *str = strndup(cp, len); /* Decimal_in always converts the complete string */
148149
int ret = 0;
149150
Numeric *result;
150-
151-
151+
152+
if (risnull(CSTRINGTYPE, cp))
153+
{
154+
rsetnull(CDECIMALTYPE, (char *)np);
155+
return 0;
156+
}
157+
152158
if (!str)
153159
ret = -1201;
154160
else
@@ -292,6 +298,12 @@ dectoasc(Decimal *np, char *cp, int len, int right)
292298
if (nres == NULL)
293299
return -1211;
294300

301+
if (risnull(CDECIMALTYPE, (char *)np))
302+
{
303+
rsetnull(CSTRINGTYPE, (char *)cp);
304+
return 0;
305+
}
306+
295307
if (PGTYPESnumeric_from_decimal(np, nres) != 0)
296308
return -1211;
297309

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
{
2525
struct sqlca_t *sqlca = ECPGget_sqlca();
2626
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
27+
int value_for_indicator = 0;
2728

2829
ECPGlog("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
*/
5859
if (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 long int *) (ind + ind_offset * act_tuple)) = -1;
78-
break;
77+
case ECPGt_long_long:
78+
case ECPGt_unsigned_long_long:
79+
*((long long int *) (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+
{
8185
if (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,
8993
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
9094
return (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)
99105
return (true);
100-
}
101106

102107
do
103108
{

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.17 2003/07/07 12:15:33 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.18 2003/07/08 12:11:29 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -144,7 +144,6 @@ create_statement(int lineno, int compat, int force_indicator, struct connection
144144
var->arrsize = 0;
145145
if (var->varcharsize < 0)
146146
var->varcharsize = 0;
147-
148147

149148
var->ind_type = va_arg(ap, enum ECPGttype);
150149
var->ind_pointer = va_arg(ap, char *);
@@ -158,6 +157,13 @@ create_statement(int lineno, int compat, int force_indicator, struct connection
158157
var->ind_value = *((char **) (var->ind_pointer));
159158
else
160159
var->ind_value = var->ind_pointer;
160+
161+
/* negative values are used to indicate an array without given bounds */
162+
/* reset to zero for us */
163+
if (var->ind_arrsize < 0)
164+
var->ind_arrsize = 0;
165+
if (var->ind_varcharsize < 0)
166+
var->ind_varcharsize = 0;
161167

162168
for (ptr = *list; ptr && ptr->next; ptr = ptr->next);
163169

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.244 2003/07/01 12:40:51 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.245 2003/07/08 12:11:32 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -208,10 +208,18 @@ adjust_informix(struct arguments *list)
208208
/* change variable name to "ECPG_informix_get_var(<counter>)" */
209209
original_var = ptr->variable->name;
210210
sprintf(temp, "%d))", ecpg_informix_var);
211-
ptr->variable = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size), 0);
212211

213212
/* create call to "ECPG_informix_set_var(<counter>, <pointer>. <linen number>)" */
214-
sprintf(temp, "%d, &(", ecpg_informix_var++);
213+
if (atoi(ptr->variable->type->size) > 1)
214+
{
215+
ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size), 0);
216+
sprintf(temp, "%d, (", ecpg_informix_var++);
217+
}
218+
else
219+
{
220+
ptr->variable = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size), 0);
221+
sprintf(temp, "%d, &(", ecpg_informix_var++);
222+
}
215223
result = cat_str(5, result, make_str("ECPG_informix_set_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
216224
}
217225

src/interfaces/ecpg/preproc/type.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,13 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
318318
{
319319
char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
320320
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1);
321-
321+
322322
switch (type)
323323
{
324+
/*
325+
* we have to use the & operator except for arrays and pointers
326+
*/
327+
324328
case ECPGt_varchar:
325329

326330
/*
@@ -342,7 +346,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
342346

343347
/*
344348
* we have to use the pointer except for arrays with given
345-
* bounds
349+
* bounds, ecpglib will distinguish between * and []
346350
*/
347351
if ((atoi(varcharsize) > 1 ||
348352
(atoi(arrsize) > 0) ||

src/interfaces/ecpg/test/test2.pgc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ exec sql end declare section;
6565

6666
p=&personal;
6767
i=&ind_personal;
68+
memset(i, 0, sizeof(ind_personal));
6869
while (1) {
6970
strcpy(msg, "fetch");
7071
exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;

0 commit comments

Comments
 (0)