Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 26188e8

Browse files
author
Michael Meskes
committed
- Enable FETCH without INTO.
- Compatibility functions for INFORMIX handling of DECLARE statement.
1 parent a2d08b9 commit 26188e8

File tree

10 files changed

+123
-30
lines changed

10 files changed

+123
-30
lines changed

src/interfaces/ecpg/ChangeLog

+5
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

+55
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
return 0;
674676
}
675677

678+
bool
679+
ECPGconnect_informix(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
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+
static struct var_list
693+
{
694+
int number;
695+
void *pointer;
696+
struct var_list *next;
697+
} *ivlist = NULL;
698+
699+
void
700+
ECPG_informix_set_var(int number, void *pointer, int lineno)
701+
{
702+
struct var_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 = (struct var_list *) ECPGalloc (sizeof(struct var_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(int number)
724+
{
725+
struct var_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

+2-17
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(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
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(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
@@ -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

+2-2
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
return status;

src/interfaces/ecpg/include/ecpg_informix.h

+5-1
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
#define SQLNOTFOUND 100
910

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

3233
extern int byleng(char *, int);
3334
extern void ldchar(char *, int, char *);
34-
35+
36+
extern bool ECPGconnect_informix(int, const char *, const char *, const char *, const char *, int);
37+
extern void ECPG_informix_set_var(int, void *, int);
38+
extern void *ECPG_informix_get_var(int);

src/interfaces/ecpg/include/ecpglib.h

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ void ECPGdebug(int, FILE *);
4242
bool ECPGstatus(int, const char *);
4343
bool ECPGsetcommit(int, const char *, const char *);
4444
bool ECPGsetconn(int, const char *);
45-
bool ECPGconnect_informix(int, const char *, const char *, const char *, const char *, int);
4645
bool ECPGconnect(int, const char *, const char *, const char *, const char *, int);
4746
bool ECPGdo(int, const char *, char *,...);
4847
bool ECPGtrans(int, const char *, const char *);

src/interfaces/ecpg/preproc/ecpg.c

+4-1
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern int braces_open,
1717
auto_create_c,
1818
system_includes,
1919
ret_value,
20-
struct_level;
20+
struct_level,
21+
ecpg_informix_var;
2122
extern char *descriptor_index;
2223
extern char *descriptor_name;
2324
extern char *connection;

src/interfaces/ecpg/preproc/preproc.y

+45-4
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
char errortext[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
static char *
145147
make_name(void)
146148
{
@@ -186,6 +188,36 @@ create_questionmarks(char *name, bool array)
186188
return(result);
187189
}
188190

191+
static char *
192+
adjust_informix(struct arguments *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+
struct arguments *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: CLOSE name { $$ = cat2_str(make_str("close"), $2); }
1133+
ClosePortalStmt: CLOSE name
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
| FETCH name ecpg_into_using
17361771
{ $$ = cat2_str(make_str("fetch"), $2); }
1772+
| FETCH fetch_direction from_in name
1773+
{ $$ = cat_str(4, make_str("fetch"), $2, $3, $4); }
1774+
| FETCH name
1775+
{ $$ = cat2_str(make_str("fetch"), $2); }
17371776
| MOVE fetch_direction from_in name
17381777
{ $$ = cat_str(4, make_str("move"), $2, $3, $4); }
17391778
| MOVE name
@@ -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

+3-3
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)