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

Commit26188e8

Browse files
author
Michael Meskes
committed
- Enable FETCH without INTO.
- Compatibility functions for INFORMIX handling of DECLARE statement.
1 parenta2d08b9 commit26188e8

File tree

10 files changed

+123
-30
lines changed

10 files changed

+123
-30
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,11 @@ Wed Jun 11 08:30:41 CEST 2003
14821482

14831483
- Make sure a variable is no longer referenced when it is removed.
14841484
- Fixed counting bug in parsing "->" operator.
1485+
1486+
Fri Jun 13 10:11:12 CEST 2003
1487+
1488+
- Enable FETCH without INTO.
1489+
- Compatibility functions for INFORMIX handling of DECLARE statement.
14851490
- Set ecpg version to 2.12.0.
14861491
- Set ecpg library to 3.4.2.
14871492
- Set pgtypes library to 1.0.0

‎src/interfaces/ecpg/compatlib/informix.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include<pgtypes_error.h>
99
#include<pgtypes_date.h>
1010

11+
char*ECPGalloc(long,int);
12+
1113
/* we start with the numeric functions */
1214
int
1315
decadd(Numeric*arg1,Numeric*arg2,Numeric*sum)
@@ -673,3 +675,56 @@ dtcvfmtasc (char *inbuf, char *fmtstr, dtime_t *dtvalue)
673675
return0;
674676
}
675677

678+
bool
679+
ECPGconnect_informix(intlineno,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
680+
{
681+
char*informix_name= (char*)name,*envname;
682+
683+
/* Informix uses an environment variable DBPATH that overrides
684+
* the connection parameters given here.
685+
* We do the same with PG_DBPATH as the syntax is different. */
686+
envname=getenv("PG_DBPATH");
687+
if (envname)
688+
informix_name=envname;
689+
return (ECPGconnect(lineno,informix_name,user,passwd,connection_name ,autocommit));
690+
}
691+
692+
staticstructvar_list
693+
{
694+
intnumber;
695+
void*pointer;
696+
structvar_list*next;
697+
}*ivlist=NULL;
698+
699+
void
700+
ECPG_informix_set_var(intnumber,void*pointer,intlineno)
701+
{
702+
structvar_list*ptr;
703+
704+
for (ptr=ivlist;ptr!=NULL;ptr=ptr->next)
705+
{
706+
if (ptr->number==number)
707+
{
708+
/* already known => just change pointer value */
709+
ptr->pointer=pointer;
710+
return;
711+
}
712+
}
713+
714+
/* a new one has to be added */
715+
ptr= (structvar_list*)ECPGalloc (sizeof(structvar_list),lineno);
716+
ptr->number=number;
717+
ptr->pointer=pointer;
718+
ptr->next=ivlist;
719+
ivlist=ptr;
720+
}
721+
722+
void*
723+
ECPG_informix_get_var(intnumber)
724+
{
725+
structvar_list*ptr;
726+
727+
for (ptr=ivlist;ptr!=NULL&&ptr->number!=number;ptr=ptr->next);
728+
return (ptr) ?ptr->pointer :NULL;
729+
}
730+

‎src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 2 additions & 17 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.5 2003/05/20 11:05:27 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.6 2003/06/13 10:50:57 meskes Exp $ */
22

33
#include"postgres_fe.h"
44

@@ -257,21 +257,6 @@ ECPGnoticeProcessor(void *arg, const char *message)
257257
sqlca.sqlwarn[0]='W';
258258
}
259259

260-
/* this contains some quick hacks, needs to be cleaned up, but it works */
261-
bool
262-
ECPGconnect_informix(intlineno,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
263-
{
264-
char*informix_name= (char*)name,*envname;
265-
266-
/* Informix uses an environment variable DBPATH that overrides
267-
* the connection parameters given here.
268-
* We do the same with PG_DBPATH as the syntax is different. */
269-
envname=getenv("PG_DBPATH");
270-
if (envname)
271-
informix_name=envname;
272-
return (ECPGconnect(lineno,informix_name,user,passwd,connection_name,autocommit));
273-
}
274-
275260
/* this contains some quick hacks, needs to be cleaned up, but it works */
276261
bool
277262
ECPGconnect(intlineno,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
@@ -341,7 +326,7 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
341326
*tmp='\0';
342327
}
343328

344-
tmp=last_path_separator(dbname+offset);
329+
tmp=last_path_separator(dbname+offset);
345330
if (tmp!=NULL)/* database name given */
346331
{
347332
realname=strdup(tmp+1);

‎src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 2 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.8 2003/04/01 14:37:25 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.9 2003/06/13 10:50:57 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -1239,7 +1239,7 @@ ECPGexecute(struct statement * stmt)
12391239
{
12401240
ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
12411241
stmt->lineno,notify->relname,notify->be_pid);
1242-
PQfreemem(notify);
1242+
PQfreemem(notify);
12431243
}
12441244

12451245
returnstatus;

‎src/interfaces/ecpg/include/ecpg_informix.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include<decimal.h>
66
#include<datetime.h>
7+
#include<ecpglib.h>
78

89
#defineSQLNOTFOUND 100
910

@@ -31,4 +32,7 @@ extern void rupshift(char *);
3132

3233
externintbyleng(char*,int);
3334
externvoidldchar(char*,int,char*);
34-
35+
36+
externboolECPGconnect_informix(int,constchar*,constchar*,constchar*,constchar*,int);
37+
externvoidECPG_informix_set_var(int,void*,int);
38+
externvoid*ECPG_informix_get_var(int);

‎src/interfaces/ecpg/include/ecpglib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ voidECPGdebug(int, FILE *);
4242
boolECPGstatus(int,constchar*);
4343
boolECPGsetcommit(int,constchar*,constchar*);
4444
boolECPGsetconn(int,constchar*);
45-
boolECPGconnect_informix(int,constchar*,constchar*,constchar*,constchar*,int);
4645
boolECPGconnect(int,constchar*,constchar*,constchar*,constchar*,int);
4746
boolECPGdo(int,constchar*,char*,...);
4847
boolECPGtrans(int,constchar*,constchar*);

‎src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.72 2003/05/30 08:39:00 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.73 2003/06/13 10:50:57 meskes Exp $ */
22

33
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
44
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -359,6 +359,9 @@ main(int argc, char *const argv[])
359359
/* and structure member lists */
360360
memset(struct_member_list,0,sizeof(struct_member_list));
361361

362+
/* and our variable counter for Informix compatibility */
363+
ecpg_informix_var=0;
364+
362365
/* finally the actual connection */
363366
connection=NULL;
364367

‎src/interfaces/ecpg/preproc/extern.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern intbraces_open,
1717
auto_create_c,
1818
system_includes,
1919
ret_value,
20-
struct_level;
20+
struct_level,
21+
ecpg_informix_var;
2122
externchar*descriptor_index;
2223
externchar*descriptor_name;
2324
externchar*connection;

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 45 additions & 4 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.230 2003/06/11 06:39:12 meskes Exp $*/
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.231 2003/06/13 10:50:57 meskes Exp $*/
22

33
/* Copyright comment*/
44
%{
@@ -11,6 +11,7 @@
1111
*/
1212
int struct_level =0;
1313
int braces_open;/* brace level counter*/
14+
int ecpg_informix_var =0;
1415
charerrortext[128];
1516
char*connection =NULL;
1617
char*input_filename =NULL;
@@ -141,6 +142,7 @@ make3_str(char *str1, char *str2, char *str3)
141142
return(res_str);
142143
}
143144

145+
/* and the rest*/
144146
staticchar *
145147
make_name(void)
146148
{
@@ -186,6 +188,36 @@ create_questionmarks(char *name, bool array)
186188
return(result);
187189
}
188190

191+
staticchar *
192+
adjust_informix(structarguments *list)
193+
{
194+
/* Informix accepts DECLARE with variables that are out of scope when OPEN is called.
195+
* This breaks standard and leads to some very dangerous programming.
196+
* Since they do, we have to work around and accept their syntax as well.
197+
* But we will do so ONLY in Informix mode.
198+
* We have to change the variables to our own struct and just store the pointer instead of the variable*/
199+
200+
structarguments *ptr;
201+
char *result =make_str("");
202+
203+
for (ptr = list; ptr !=NULL; ptr = ptr->next)
204+
{
205+
char temp[sizeof(int)+sizeof(", &()")];
206+
char *original_var;
207+
208+
/* change variable name to "ECPG_informix_get_var(<counter>)"*/
209+
original_var = ptr->variable->name;
210+
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);
212+
213+
/* create call to "ECPG_informix_set_var(<counter>, <pointer>. <linen number>)"*/
214+
sprintf(temp,"%d, &(", ecpg_informix_var++);
215+
result =cat_str(5, result,make_str("ECPG_informix_set_var("),mm_strdup(temp),mm_strdup(original_var),make_str("), __LINE__);\n"));
216+
}
217+
218+
return result;
219+
}
220+
189221
%}
190222

191223
%union {
@@ -1098,7 +1130,10 @@ opt_drop_behavior: CASCADE { $$ = make_str("cascade"); }
10981130
*
10991131
*****************************************************************************/
11001132

1101-
ClosePortalStmt:CLOSEname{$$ = cat2_str(make_str("close"),$2); }
1133+
ClosePortalStmt:CLOSEname
1134+
{
1135+
$$ = cat2_str(make_str("close"),$2);
1136+
}
11021137
;
11031138

11041139
/*****************************************************************************
@@ -1734,6 +1769,10 @@ FetchStmt: FETCH fetch_direction from_in name ecpg_into_using
17341769
{$$ = cat_str(4, make_str("fetch"),$2,$3,$4); }
17351770
|FETCHnameecpg_into_using
17361771
{$$ = cat2_str(make_str("fetch"),$2); }
1772+
|FETCHfetch_directionfrom_inname
1773+
{$$ = cat_str(4, make_str("fetch"),$2,$3,$4); }
1774+
|FETCHname
1775+
{$$ = cat2_str(make_str("fetch"),$2); }
17371776
|MOVEfetch_directionfrom_inname
17381777
{$$ = cat_str(4, make_str("move"),$2,$3,$4); }
17391778
|MOVEname
@@ -2630,10 +2669,12 @@ DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
26302669
this->argsinsert = argsinsert;
26312670
this->argsresult = argsresult;
26322671
argsinsert = argsresult =NULL;
2633-
26342672
cur =this;
26352673

2636-
$$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
2674+
if (compat == ECPG_COMPAT_INFORMIX)
2675+
$$ = cat_str(5, adjust_informix(this->argsinsert), adjust_informix(this->argsresult), make_str("/*"), mm_strdup(this->command), make_str("*/"));
2676+
else
2677+
$$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
26372678
}
26382679
;
26392680

‎src/interfaces/ecpg/test/test2.pgc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ typedef union { int integer; short smallint; } ind;
1212
#define BUFFERSIZ 8
1313
exec sql type str is varchar[BUFFERSIZ];
1414

15+
exec sql declare cur cursor for
16+
select name, born, age, married, children from meskes;
17+
1518
int
1619
main ()
1720
{
@@ -34,9 +37,6 @@ exec sql end declare section;
3437

3538
exec sql var ind_married is long;
3639

37-
exec sql declare cur cursor for
38-
select name, born, age, married, children from meskes;
39-
4040
char msg[128];
4141
FILE *dbgs;
4242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp