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

Commit cf37d68

Browse files
author
Michael Meskes
committed
Made sure sqlca is reset for declare cursor in Informix mode as pointed out by
Böszörményi Zoltán <zb@cybertec.at>.
1 parent c74d8a7 commit cf37d68

12 files changed

+132
-70
lines changed

src/interfaces/ecpg/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -2419,5 +2419,11 @@ Fri, 07 Aug 2009 10:41:28 +0200
24192419

24202420
- Added STRING datatype for Informix compatibility mode. This work is
24212421
based on a patch send in by Böszörményi Zoltán <zb@cybertec.at>.
2422+
2423+
Fri, 14 Aug 2009 14:45:02 +0200
2424+
2425+
- Made sure sqlca is reset for declare cursor in Informix mode as
2426+
pointed out by Böszörményi Zoltán <zb@cybertec.at>.
24222427
- Set ecpg library version to 6.2.
2428+
- Set compat library version to 3.2.
24232429
- Set ecpg version to 4.6.

src/interfaces/ecpg/compatlib/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.44 2009/08/07 10:51:20 meskes Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.45 2009/08/14 13:28:22 meskes Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
1515

1616
NAME= ecpg_compat
1717
SO_MAJOR_VERSION= 3
18-
SO_MINOR_VERSION= 1
18+
SO_MINOR_VERSION= 2
1919

2020
override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2121
-I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS)

src/interfaces/ecpg/compatlib/exports.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/exports.txt,v 1.4 2007/10/04 17:49:31 meskes Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/exports.txt,v 1.5 2009/08/14 13:28:22 meskes Exp $
22
# Functions to be exported by ecpg_compatlib DLL
33
ECPG_informix_get_var 1
44
ECPG_informix_set_var 2
@@ -41,3 +41,4 @@ rtypwidth 38
4141
rupshift 39
4242
ldchar 40
4343
byleng 41
44+
ECPG_informix_reset_sqlca 42

src/interfaces/ecpg/compatlib/informix.c

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.59 2009/06/11 14:49:13 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.60 2009/08/14 13:28:22 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -16,6 +16,34 @@
1616
#include <sqlca.h>
1717
#include <ecpgerrno.h>
1818

19+
/* this is also defined in ecpglib/misc.c, by defining it twice we don't have to export the symbol */
20+
21+
static struct sqlca_t sqlca_init =
22+
{
23+
{
24+
'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
25+
},
26+
sizeof(struct sqlca_t),
27+
0,
28+
{
29+
0,
30+
{
31+
0
32+
}
33+
},
34+
{
35+
'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
36+
},
37+
{
38+
0, 0, 0, 0, 0, 0
39+
},
40+
{
41+
0, 0, 0, 0, 0, 0, 0, 0
42+
},
43+
{
44+
'0', '0', '0', '0', '0'
45+
}
46+
};
1947
static int
2048
deccall2(decimal *arg1, decimal *arg2, int (*ptr) (numeric *, numeric *))
2149
{
@@ -1033,6 +1061,14 @@ ECPG_informix_get_var(int number)
10331061
return (ptr) ? ptr->pointer : NULL;
10341062
}
10351063

1064+
void
1065+
ECPG_informix_reset_sqlca(void)
1066+
{
1067+
struct sqlca_t *sqlca = ECPGget_sqlca();
1068+
1069+
memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
1070+
}
1071+
10361072
int
10371073
rsetnull(int t, char *ptr)
10381074
{

src/interfaces/ecpg/include/ecpg_informix.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file contains stuff needed to be as compatible to Informix as possible.
3-
* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg_informix.h,v 1.22 2008/02/17 18:14:29 meskes Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg_informix.h,v 1.23 2009/08/14 13:28:22 meskes Exp $
44
*/
55
#ifndef _ECPG_INFORMIX_H
66
#define _ECPG_INFORMIX_H
@@ -34,7 +34,7 @@ extern "C"
3434
#endif
3535

3636
extern int rdatestr(date, char *);
37-
extern void rtoday(date *);
37+
extern void rtoday(date *);
3838
extern int rjulmdy(date, short *);
3939
extern int rdefmtdate(date *, char *, char *);
4040
extern int rfmtdate(date, char *, char *);
@@ -49,13 +49,14 @@ extern int rsetnull(int, char *);
4949
extern int rtypalign(int, int);
5050
extern int rtypmsize(int, int);
5151
extern int rtypwidth(int, int);
52-
extern void rupshift(char *);
52+
extern void rupshift(char *);
5353

5454
extern int byleng(char *, int);
5555
extern void ldchar(char *, int, char *);
5656

5757
extern void ECPG_informix_set_var(int, void *, int);
5858
extern void *ECPG_informix_get_var(int);
59+
extern void ECPG_informix_reset_sqlca(void);
5960

6061
/* Informix defines these in decimal.h */
6162
int decadd(decimal *, decimal *, decimal *);

src/interfaces/ecpg/preproc/ecpg.addons

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.4 2009/01/30 12:53:43 petere Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.5 2009/08/14 13:28:22 meskes Exp $ */
22

33
ECPG: stmtClosePortalStmt block
44
{
@@ -238,6 +238,7 @@ ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
238238
ECPG: DeclareCursorStmtDECLAREnamecursor_optionsCURSORopt_holdFORSelectStmt block
239239
{
240240
struct cursor *ptr, *this;
241+
char *comment;
241242

242243
for (ptr = cur; ptr != NULL; ptr = ptr->next)
243244
{
@@ -257,10 +258,19 @@ ECPG: DeclareCursorStmtDECLAREnamecursor_optionsCURSORopt_holdFORSelectStmt bloc
257258
argsinsert = argsresult = NULL;
258259
cur = this;
259260

261+
comment = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
262+
260263
if (INFORMIX_MODE)
261-
$$ = cat_str(5, adjust_informix(this->argsinsert), adjust_informix(this->argsresult), make_str("/*"), mm_strdup(this->command), make_str("*/"));
264+
{
265+
if (braces_open > 0) /* we're in a function */
266+
{
267+
$$ = cat_str(4, adjust_informix(this->argsinsert), adjust_informix(this->argsresult), make_str("ECPG_informix_reset_sqlca();"), comment);
268+
}
269+
else
270+
$$ = cat_str(3, adjust_informix(this->argsinsert), adjust_informix(this->argsresult), comment);
271+
}
262272
else
263-
$$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
273+
$$ = comment;
264274
}
265275
ECPG: opt_hold block
266276
{

src/interfaces/ecpg/preproc/ecpg.trailer

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.10 2009/08/07 10:51:20 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.11 2009/08/14 13:28:22 meskes Exp $ */
22

33
statements: /*EMPTY*/
44
| statements statement
@@ -318,7 +318,10 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
318318

319319
cur = this;
320320

321-
$$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
321+
if (INFORMIX_MODE && braces_open > 0) /* we're in a function */
322+
$$ = cat_str(4, make_str("ECPG_informix_reset_sqlca();"), make_str("/*"), mm_strdup(this->command), make_str("*/"));
323+
else
324+
$$ = cat_str(3, make_str("/*"), mm_strdup(this->command), make_str("*/"));
322325
}
323326
;
324327

src/interfaces/ecpg/test/compat_informix/test_informix.pgc

+2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ int main(void)
4545
printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
4646
if (sqlca.sqlcode != 0) $rollback;
4747

48+
sqlca.sqlcode = 100;
4849
$declare c cursor for select * from test where i <= :i;
50+
printf ("%ld\n", sqlca.sqlcode);
4951
openit();
5052

5153
deccvint(0, &j);

src/interfaces/ecpg/test/expected/compat_informix-test_informix.c

+22-20
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
146146
#line 46 "test_informix.pgc"
147147

148148

149+
sqlca.sqlcode = 100;
149150
ECPG_informix_set_var( 0, &( i ), __LINE__);\
150-
/* declare c cursor for select * from test where i <= $1 */
151-
#line 48 "test_informix.pgc"
151+
ECPG_informix_reset_sqlca(); /* declare c cursor for select * from test where i <= $1 */
152+
#line 49 "test_informix.pgc"
152153

154+
printf ("%ld\n", sqlca.sqlcode);
153155
openit();
154156

155157
deccvint(0, &j);
@@ -163,10 +165,10 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
163165
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
164166
ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char),
165167
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
166-
#line 55 "test_informix.pgc"
168+
#line 57 "test_informix.pgc"
167169

168170
if (sqlca.sqlcode < 0) dosqlprint ( );}
169-
#line 55 "test_informix.pgc"
171+
#line 57 "test_informix.pgc"
170172

171173
if (sqlca.sqlcode == 100) break;
172174
else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
@@ -188,53 +190,53 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
188190
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "delete from test where i = $1 :: decimal",
189191
ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal),
190192
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
191-
#line 73 "test_informix.pgc"
193+
#line 75 "test_informix.pgc"
192194

193195
if (sqlca.sqlcode < 0) dosqlprint ( );}
194-
#line 73 "test_informix.pgc"
196+
#line 75 "test_informix.pgc"
195197

196198
printf("DELETE: %ld\n", sqlca.sqlcode);
197199

198200
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 14", ECPGt_EOIT, ECPGt_EORT);
199-
#line 76 "test_informix.pgc"
201+
#line 78 "test_informix.pgc"
200202

201203
if (sqlca.sqlcode < 0) dosqlprint ( );}
202-
#line 76 "test_informix.pgc"
204+
#line 78 "test_informix.pgc"
203205

204206
printf("Exists: %ld\n", sqlca.sqlcode);
205207

206208
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT);
207-
#line 79 "test_informix.pgc"
209+
#line 81 "test_informix.pgc"
208210

209211
if (sqlca.sqlcode < 0) dosqlprint ( );}
210-
#line 79 "test_informix.pgc"
212+
#line 81 "test_informix.pgc"
211213

212214
printf("Does not exist: %ld\n", sqlca.sqlcode);
213215

214216
{ ECPGtrans(__LINE__, NULL, "commit");
215-
#line 82 "test_informix.pgc"
217+
#line 84 "test_informix.pgc"
216218

217219
if (sqlca.sqlcode < 0) dosqlprint ( );}
218-
#line 82 "test_informix.pgc"
220+
#line 84 "test_informix.pgc"
219221

220222
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
221-
#line 83 "test_informix.pgc"
223+
#line 85 "test_informix.pgc"
222224

223225
if (sqlca.sqlcode < 0) dosqlprint ( );}
224-
#line 83 "test_informix.pgc"
226+
#line 85 "test_informix.pgc"
225227

226228
{ ECPGtrans(__LINE__, NULL, "commit");
227-
#line 84 "test_informix.pgc"
229+
#line 86 "test_informix.pgc"
228230

229231
if (sqlca.sqlcode < 0) dosqlprint ( );}
230-
#line 84 "test_informix.pgc"
232+
#line 86 "test_informix.pgc"
231233

232234

233235
{ ECPGdisconnect(__LINE__, "CURRENT");
234-
#line 86 "test_informix.pgc"
236+
#line 88 "test_informix.pgc"
235237

236238
if (sqlca.sqlcode < 0) dosqlprint ( );}
237-
#line 86 "test_informix.pgc"
239+
#line 88 "test_informix.pgc"
238240

239241

240242
return 0;
@@ -245,10 +247,10 @@ static void openit(void)
245247
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare c cursor for select * from test where i <= $1 ",
246248
ECPGt_int,&(*( int *)(ECPG_informix_get_var( 0))),(long)1,(long)1,sizeof(int),
247249
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
248-
#line 93 "test_informix.pgc"
250+
#line 95 "test_informix.pgc"
249251

250252
if (sqlca.sqlcode < 0) dosqlprint ( );}
251-
#line 93 "test_informix.pgc"
253+
#line 95 "test_informix.pgc"
252254

253255
}
254256

0 commit comments

Comments
 (0)