Skip to content

Commit fd3ca52

Browse files
author
Michael Meskes
committed
Implemented Informix special way to treat NULLs, removed warnings, synced.
1 parent ff4c69e commit fd3ca52

20 files changed

+373
-156
lines changed

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <math.h>
55
#include <ctype.h>
66

7+
#include <ecpgtype.h>
78
#include <ecpg_informix.h>
89
#include <pgtypes_error.h>
910
#include <pgtypes_date.h>
@@ -645,18 +646,6 @@ rgetmsg(int msgnum, char *s, int maxsize)
645646
return 0;
646647
}
647648

648-
int
649-
risnull(int vtype, char *pcvar)
650-
{
651-
return 0;
652-
}
653-
654-
int
655-
rsetnull(int vtype, char *pcvar)
656-
{
657-
return 0;
658-
}
659-
660649
int
661650
rtypalign(int offset, int type)
662651
{
@@ -681,30 +670,6 @@ dtcvfmtasc (char *inbuf, char *fmtstr, dtime_t *dtvalue)
681670
return 0;
682671
}
683672

684-
bool
685-
ECPGconnect_informix(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
686-
{
687-
char *informix_name = (char *)name, *envname;
688-
689-
/* Informix uses an environment variable DBPATH that overrides
690-
* the connection parameters given here.
691-
* We do the same with PG_DBPATH as the syntax is different. */
692-
envname = getenv("PG_DBPATH");
693-
if (envname)
694-
informix_name = envname;
695-
return (ECPGconnect(lineno, informix_name, user, passwd, connection_name , autocommit));
696-
}
697-
698-
bool
699-
ECPGdeallocate_informix(int lineno, char *name)
700-
{
701-
ECPGdeallocate_one(lineno, name);
702-
703-
/* Just ignore all errors since we do not know the list of cursors we
704-
* are allowed to free. We have to trust that the software. */
705-
return true;
706-
}
707-
708673
static struct var_list
709674
{
710675
int number;
@@ -744,3 +709,14 @@ ECPG_informix_get_var(int number)
744709
return (ptr) ? ptr->pointer : NULL;
745710
}
746711

712+
int rsetnull(int t, char *ptr)
713+
{
714+
ECPGset_informix_null(t, ptr);
715+
return 0;
716+
}
717+
718+
int risnull(int t, char *ptr)
719+
{
720+
return(ECPGis_informix_null(t, ptr));
721+
}
722+

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.7 2003/06/15 04:07:58 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.8 2003/06/25 10:44:21 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -173,7 +173,7 @@ ECPGnoticeProcessor(void *arg, const char *message)
173173
struct sqlca_t *sqlca = ECPGget_sqlca();
174174

175175
/* these notices raise an error */
176-
if (strncmp(message, "WARNING: ", 9))
176+
if (strncmp(message, "WARNING: ", 9) && strncmp(message, "NOTICE: ", 8))
177177
{
178178
ECPGlog("ECPGnoticeProcessor: strange warning '%s'\n", message);
179179
ECPGnoticeProcessor_raise(ECPG_WARNING_UNRECOGNIZED, message);
@@ -290,9 +290,10 @@ ECPGnoticeProcessor(void *arg, const char *message)
290290

291291
/* this contains some quick hacks, needs to be cleaned up, but it works */
292292
bool
293-
ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
293+
ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
294294
{
295295
struct sqlca_t *sqlca = ECPGget_sqlca();
296+
enum COMPAT_MODE compat = c;
296297
struct connection *this;
297298
char *dbname = strdup(name),
298299
*host = NULL,
@@ -302,6 +303,22 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
302303
*options = NULL;
303304

304305
ECPGinit_sqlca(sqlca);
306+
307+
if (compat == ECPG_COMPAT_INFORMIX)
308+
{
309+
char *envname;
310+
311+
/* Informix uses an environment variable DBPATH that overrides
312+
* the connection parameters given here.
313+
* We do the same with PG_DBPATH as the syntax is different. */
314+
envname = getenv("PG_DBPATH");
315+
if (envname)
316+
{
317+
free(dbname);
318+
dbname = envname;
319+
}
320+
321+
}
305322

306323
if ((this = (struct connection *) ECPGalloc(sizeof(struct connection), lineno)) == NULL)
307324
return false;
@@ -358,7 +375,7 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
358375
*tmp = '\0';
359376
}
360377

361-
tmp = last_path_separator(dbname + offset);
378+
tmp = last_path_separator(dbname + offset);
362379
if (tmp != NULL) /* database name given */
363380
{
364381
realname = strdup(tmp + 1);

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 40 additions & 36 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.7 2003/06/22 11:00:48 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.8 2003/06/25 10:44:21 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -20,7 +20,7 @@ bool
2020
ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
2121
enum ECPGttype type, enum ECPGttype ind_type,
2222
char *var, char *ind, long varcharsize, long offset,
23-
long ind_offset, bool isarray)
23+
long ind_offset, bool isarray, enum COMPAT_MODE compat, bool force_indicator)
2424
{
2525
struct sqlca_t *sqlca = ECPGget_sqlca();
2626
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
@@ -55,44 +55,48 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
5555
/*
5656
* check for null value and set indicator accordingly
5757
*/
58-
switch (ind_type)
58+
if (PQgetisnull(results, act_tuple, act_field))
5959
{
60-
case ECPGt_short:
61-
case ECPGt_unsigned_short:
62-
/* ((short *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
63-
*((short *) (ind + ind_offset * act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
64-
break;
65-
case ECPGt_int:
66-
case ECPGt_unsigned_int:
67-
/* ((int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
68-
*((int *) (ind + ind_offset * act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
69-
break;
70-
case ECPGt_long:
71-
case ECPGt_unsigned_long:
72-
/* ((long *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
73-
*((long *) (ind + ind_offset * act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
74-
break;
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;
7574
#ifdef HAVE_LONG_LONG_INT_64
76-
case ECPGt_long_long:
77-
case ECPGt_unsigned_long_long:
78-
/* ((long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
79-
*((long long int *) (ind + ind_offset * act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
80-
break;
81-
/* case ECPGt_unsigned_long_long:
82-
((unsigned long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
83-
break;*/
75+
case ECPGt_long_long:
76+
case ECPGt_unsigned_long_long:
77+
*((long long int *) (ind + ind_offset * act_tuple)) = -1;
78+
break;
8479
#endif /* HAVE_LONG_LONG_INT_64 */
85-
case ECPGt_NO_INDICATOR:
86-
if (PQgetisnull(results, act_tuple, act_field))
87-
{
88-
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
80+
case ECPGt_NO_INDICATOR:
81+
if (force_indicator == false && compat == ECPG_COMPAT_INFORMIX)
82+
{
83+
/* Informix has an additional way to specify NULLs
84+
* note that this uses special values to denote NULL */
85+
ECPGset_informix_null(type, var + offset * act_tuple);
86+
}
87+
else
88+
{
89+
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
90+
return (false);
91+
}
92+
break;
93+
default:
94+
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(ind_type));
8995
return (false);
90-
}
91-
break;
92-
default:
93-
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(ind_type));
94-
return (false);
95-
break;
96+
break;
97+
}
98+
99+
return (true);
96100
}
97101

98102
do

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 17 additions & 8 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.11 2003/06/20 12:00:59 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.12 2003/06/25 10:44:21 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -88,7 +88,7 @@ quote_postgres(char *arg, int lineno)
8888
* ind_offset - indicator offset
8989
*/
9090
static bool
91-
create_statement(int lineno, struct connection * connection, struct statement ** stmt, char *query, va_list ap)
91+
create_statement(int lineno, int compat, int force_indicator, struct connection * connection, struct statement ** stmt, char *query, va_list ap)
9292
{
9393
struct variable **list = &((*stmt)->inlist);
9494
enum ECPGttype type;
@@ -99,6 +99,8 @@ create_statement(int lineno, struct connection * connection, struct statement **
9999
(*stmt)->command = query;
100100
(*stmt)->connection = connection;
101101
(*stmt)->lineno = lineno;
102+
(*stmt)->compat = compat;
103+
(*stmt)->force_indicator = force_indicator;
102104

103105
list = &((*stmt)->inlist);
104106

@@ -428,7 +430,7 @@ ECPGstore_result(const PGresult *results, int act_field,
428430

429431
if (!ECPGget_data(results, act_tuple, act_field, stmt->lineno,
430432
var->type, var->ind_type, current_data_location,
431-
var->ind_value, len, 0, 0, isarray))
433+
var->ind_value, len, 0, 0, isarray, stmt->compat, stmt->force_indicator))
432434
status = false;
433435
else
434436
{
@@ -447,7 +449,7 @@ ECPGstore_result(const PGresult *results, int act_field,
447449
{
448450
if (!ECPGget_data(results, act_tuple, act_field, stmt->lineno,
449451
var->type, var->ind_type, var->value,
450-
var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray))
452+
var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
451453
status = false;
452454
}
453455
}
@@ -505,10 +507,16 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
505507
*tobeinserted_p = "null";
506508
break;
507509
#endif /* HAVE_LONG_LONG_INT_64 */
510+
case ECPGt_NO_INDICATOR:
511+
if (stmt->force_indicator == false && stmt->compat == ECPG_COMPAT_INFORMIX)
512+
{
513+
if (ECPGis_informix_null(var->type, var->value))
514+
*tobeinserted_p = "null";
515+
}
516+
break;
508517
default:
509518
break;
510519
}
511-
512520
if (**tobeinserted_p == '\0')
513521
{
514522
switch (var->type)
@@ -1222,7 +1230,7 @@ ECPGexecute(struct statement * stmt)
12221230
}
12231231

12241232
bool
1225-
ECPGdo(int lineno, const char *connection_name, char *query,...)
1233+
ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, char *query,...)
12261234
{
12271235
va_list args;
12281236
struct statement *stmt;
@@ -1244,7 +1252,7 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
12441252

12451253
/* construct statement in our own structure */
12461254
va_start(args, query);
1247-
if (create_statement(lineno, con, &stmt, query, args) == false)
1255+
if (create_statement(lineno, compat, force_indicator, con, &stmt, query, args) == false)
12481256
{
12491257
setlocale(LC_NUMERIC, oldlocale);
12501258
ECPGfree(oldlocale);
@@ -1280,7 +1288,8 @@ bool
12801288
ECPGdo_descriptor(int line, const char *connection,
12811289
const char *descriptor, const char *query)
12821290
{
1283-
return ECPGdo(line, connection, (char *) query, ECPGt_EOIT,
1291+
return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, (char *) query, ECPGt_EOIT,
12841292
ECPGt_descriptor, descriptor, 0L, 0L, 0L,
12851293
ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
12861294
}
1295+

src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "libpq-fe.h"
66
#include "sqlca.h"
77

8+
enum COMPAT_MODE { ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX};
9+
810
/* Here are some methods used by the lib. */
911

1012
/* Stores the backend error message for client access */
@@ -18,7 +20,7 @@ char *ECPGerrmsg(void);
1820
void ECPGadd_mem(void *ptr, int lineno);
1921

2022
bool ECPGget_data(const PGresult *, int, int, int, enum ECPGttype type,
21-
enum ECPGttype, char *, char *, long, long, long, bool);
23+
enum ECPGttype, char *, char *, long, long, long, bool, enum COMPAT_MODE, bool);
2224
struct connection *ECPGget_connection(const char *);
2325
char *ECPGalloc(long, int);
2426
char *ECPGrealloc(void *, long, int);
@@ -54,6 +56,8 @@ struct statement
5456
int lineno;
5557
char *command;
5658
struct connection *connection;
59+
enum COMPAT_MODE compat;
60+
bool force_indicator;
5761
struct variable *inlist;
5862
struct variable *outlist;
5963
};

0 commit comments

Comments
 (0)