Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd3ca52

Browse files
author
Michael Meskes
committed
Implemented Informix special way to treat NULLs, removed warnings, synced.
1 parentff4c69e commitfd3ca52

File tree

20 files changed

+373
-156
lines changed

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
return0;
646647
}
647648

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

684-
bool
685-
ECPGconnect_informix(intlineno,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
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(intlineno,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
staticstructvar_list
709674
{
710675
intnumber;
@@ -744,3 +709,14 @@ ECPG_informix_get_var(int number)
744709
return (ptr) ?ptr->pointer :NULL;
745710
}
746711

712+
intrsetnull(intt,char*ptr)
713+
{
714+
ECPGset_informix_null(t,ptr);
715+
return0;
716+
}
717+
718+
intrisnull(intt,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
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -173,7 +173,7 @@ ECPGnoticeProcessor(void *arg, const char *message)
173173
structsqlca_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(intlineno,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
293+
ECPGconnect(intlineno,intc,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
294294
{
295295
structsqlca_t*sqlca=ECPGget_sqlca();
296+
enumCOMPAT_MODEcompat=c;
296297
structconnection*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= (structconnection*)ECPGalloc(sizeof(structconnection),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
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -20,7 +20,7 @@ bool
2020
ECPGget_data(constPGresult*results,intact_tuple,intact_field,intlineno,
2121
enumECPGttypetype,enumECPGttypeind_type,
2222
char*var,char*ind,longvarcharsize,longoffset,
23-
longind_offset,boolisarray)
23+
longind_offset,boolisarray,enumCOMPAT_MODEcompat,boolforce_indicator)
2424
{
2525
structsqlca_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-
caseECPGt_short:
61-
caseECPGt_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-
caseECPGt_int:
66-
caseECPGt_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-
caseECPGt_long:
71-
caseECPGt_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+
caseECPGt_short:
63+
caseECPGt_unsigned_short:
64+
*((short*) (ind+ind_offset*act_tuple))=-1;
65+
break;
66+
caseECPGt_int:
67+
caseECPGt_unsigned_int:
68+
*((int*) (ind+ind_offset*act_tuple))=-1;
69+
break;
70+
caseECPGt_long:
71+
caseECPGt_unsigned_long:
72+
*((long*) (ind+ind_offset*act_tuple))=-1;
73+
break;
7574
#ifdefHAVE_LONG_LONG_INT_64
76-
caseECPGt_long_long:
77-
caseECPGt_unsigned_long_long:
78-
/*((long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
79-
*((long longint*) (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+
caseECPGt_long_long:
76+
caseECPGt_unsigned_long_long:
77+
*((long longint*) (ind+ind_offset*act_tuple))=-1;
78+
break;
8479
#endif/* HAVE_LONG_LONG_INT_64 */
85-
caseECPGt_NO_INDICATOR:
86-
if (PQgetisnull(results,act_tuple,act_field))
87-
{
88-
ECPGraise(lineno,ECPG_MISSING_INDICATOR,NULL);
80+
caseECPGt_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
staticbool
91-
create_statement(intlineno,structconnection*connection,structstatement**stmt,char*query,va_listap)
91+
create_statement(intlineno,intcompat,intforce_indicator,structconnection*connection,structstatement**stmt,char*query,va_listap)
9292
{
9393
structvariable**list=&((*stmt)->inlist);
9494
enumECPGttypetype;
@@ -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+
caseECPGt_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(intlineno,constchar*connection_name,char*query,...)
1233+
ECPGdo(intlineno,intcompat,intforce_indicator,constchar*connection_name,char*query,...)
12261234
{
12271235
va_listargs;
12281236
structstatement*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(intline,constchar*connection,
12811289
constchar*descriptor,constchar*query)
12821290
{
1283-
returnECPGdo(line,connection, (char*)query,ECPGt_EOIT,
1291+
returnECPGdo(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+
enumCOMPAT_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
voidECPGadd_mem(void*ptr,intlineno);
1921

2022
boolECPGget_data(constPGresult*,int,int,int,enumECPGttypetype,
21-
enumECPGttype,char*,char*,long,long,long,bool);
23+
enumECPGttype,char*,char*,long,long,long,bool,enumCOMPAT_MODE,bool);
2224
structconnection*ECPGget_connection(constchar*);
2325
char*ECPGalloc(long,int);
2426
char*ECPGrealloc(void*,long,int);
@@ -54,6 +56,8 @@ struct statement
5456
intlineno;
5557
char*command;
5658
structconnection*connection;
59+
enumCOMPAT_MODEcompat;
60+
boolforce_indicator;
5761
structvariable*inlist;
5862
structvariable*outlist;
5963
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp