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

Commita160c42

Browse files
author
Michael Meskes
committed
Added dynamic cursor names to ecpg. Almost the whole patch was done by
Boszormenyi Zoltan, with only a minor tweak or two from me.
1 parentda29cc8 commita160c42

File tree

9 files changed

+162
-13
lines changed

9 files changed

+162
-13
lines changed

‎src/interfaces/ecpg/preproc/ecpg.addons

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.8 2009/11/11 20:31:26 alvherre Exp $ */
2-
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.9 2009/11/26 15:06:47 meskes Exp $ */
32
ECPG: stmtClosePortalStmt block
43
{
54
if (INFORMIX_MODE)
@@ -213,18 +212,36 @@ ECPG: var_valueNumericOnly addon
213212
}
214213
ECPG: fetch_argscursor_name addon
215214
add_additional_variables($1, false);
215+
if ($1[0] == ':')
216+
{
217+
free($1);
218+
$1 = make_str("$0");
219+
}
216220
ECPG: fetch_argsfrom_incursor_name addon
217221
add_additional_variables($2, false);
222+
if ($2[0] == ':')
223+
{
224+
free($2);
225+
$2 = make_str("$0");
226+
}
218227
ECPG: fetch_argsNEXTopt_from_incursor_name addon
219228
ECPG: fetch_argsPRIORopt_from_incursor_name addon
220229
ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
221230
ECPG: fetch_argsLAST_Popt_from_incursor_name addon
222231
ECPG: fetch_argsALLopt_from_incursor_name addon
223-
ECPG: fetch_argsFORWARDopt_from_incursor_name addon
224-
ECPG: fetch_argsBACKWARDopt_from_incursor_name addon
225232
add_additional_variables($3, false);
233+
if ($3[0] == ':')
234+
{
235+
free($3);
236+
$3 = make_str("$0");
237+
}
226238
ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
227239
add_additional_variables($3, false);
240+
if ($3[0] == ':')
241+
{
242+
free($3);
243+
$3 = make_str("$0");
244+
}
228245
if ($1[0] == '$')
229246
{
230247
free($1);
@@ -233,16 +250,35 @@ ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
233250
ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
234251
ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
235252
add_additional_variables($4, false);
253+
if ($4[0] == ':')
254+
{
255+
free($4);
256+
$4 = make_str("$0");
257+
}
236258
ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon
237259
ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
238260
ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
239261
ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
240262
add_additional_variables($4, false);
263+
if ($4[0] == ':')
264+
{
265+
free($4);
266+
$4 = make_str("$0");
267+
}
241268
if ($2[0] == '$')
242269
{
243270
free($2);
244271
$2 = make_str("$0");
245272
}
273+
ECPG: cursor_namename rule
274+
| char_civar
275+
{
276+
char *curname = mm_alloc(strlen($1) + 2);
277+
sprintf(curname, ":%s", $1);
278+
free($1);
279+
$1 = curname;
280+
$$ = $1;
281+
}
246282
ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
247283
{
248284
$$.name = $2;
@@ -260,6 +296,7 @@ ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
260296
ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
261297
{
262298
struct cursor *ptr, *this;
299+
char *cursor_marker = $2[0] == ':' ? make_str("$0") : mm_strdup($2);
263300
char *comment;
264301

265302
for (ptr = cur; ptr != NULL; ptr = ptr->next)
@@ -274,7 +311,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
274311
this->name = $2;
275312
this->connection = connection;
276313
this->opened = false;
277-
this->command = cat_str(7, make_str("declare"),mm_strdup($2), $3, make_str("cursor"), $5, make_str("for"), $7);
314+
this->command = cat_str(7, make_str("declare"),cursor_marker, $3, make_str("cursor"), $5, make_str("for"), $7);
278315
this->argsinsert = argsinsert;
279316
this->argsresult = argsresult;
280317
argsinsert = argsresult = NULL;
@@ -294,6 +331,11 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
294331
else
295332
$$ = comment;
296333
}
334+
ECPG: ClosePortalStmtCLOSEcursor_name block
335+
{
336+
char *cursor_marker = $2[0] == ':' ? make_str("$0") : $2;
337+
$$ = cat2_str(make_str("close"), cursor_marker);
338+
}
297339
ECPG: opt_hold block
298340
{
299341
if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit == true)
@@ -363,6 +405,54 @@ ECPG: FetchStmtMOVEfetch_args rule
363405
{
364406
$$ = cat2_str(make_str("fetch"), $2);
365407
}
408+
| FETCH FORWARD cursor_name opt_ecpg_into
409+
{
410+
char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
411+
add_additional_variables($3, false);
412+
$$ = cat_str(2, make_str("fetch forward"), cursor_marker);
413+
}
414+
| FETCH FORWARD from_in cursor_name opt_ecpg_into
415+
{
416+
char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
417+
add_additional_variables($4, false);
418+
$$ = cat_str(2, make_str("fetch forward from"), cursor_marker);
419+
}
420+
| FETCH BACKWARD cursor_name opt_ecpg_into
421+
{
422+
char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
423+
add_additional_variables($3, false);
424+
$$ = cat_str(2, make_str("fetch backward"), cursor_marker);
425+
}
426+
| FETCH BACKWARD from_in cursor_name opt_ecpg_into
427+
{
428+
char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
429+
add_additional_variables($4, false);
430+
$$ = cat_str(2, make_str("fetch backward from"), cursor_marker);
431+
}
432+
| MOVE FORWARD cursor_name
433+
{
434+
char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
435+
add_additional_variables($3, false);
436+
$$ = cat_str(2, make_str("move forward"), cursor_marker);
437+
}
438+
| MOVE FORWARD from_in cursor_name
439+
{
440+
char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
441+
add_additional_variables($4, false);
442+
$$ = cat_str(2, make_str("move forward from"), cursor_marker);
443+
}
444+
| MOVE BACKWARD cursor_name
445+
{
446+
char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
447+
add_additional_variables($3, false);
448+
$$ = cat_str(2, make_str("move backward"), cursor_marker);
449+
}
450+
| MOVE BACKWARD from_in cursor_name
451+
{
452+
char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
453+
add_additional_variables($4, false);
454+
$$ = cat_str(2, make_str("move backward from"), cursor_marker);
455+
}
366456
ECPG: select_limitLIMITselect_limit_value','select_offset_value block
367457
{
368458
mmerror(PARSE_ERROR, ET_WARNING, "no longer supported LIMIT #,# syntax passed to server");

‎src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.15 2009/11/21 05:44:05 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.16 2009/11/26 15:06:47 meskes Exp $ */
22

33
statements: /*EMPTY*/
44
| statements statement
@@ -278,6 +278,7 @@ prepared_name: name {
278278
ECPGCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared_name
279279
{
280280
struct cursor *ptr, *this;
281+
char *cursor_marker = $2[0] == ':' ? make_str("$0") : mm_strdup($2);
281282
struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
282283
const char *con = connection ? connection : "NULL";
283284

@@ -294,7 +295,7 @@ ECPGCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared
294295
this->next = cur;
295296
this->name = $2;
296297
this->connection = connection;
297-
this->command = cat_str(6, make_str("declare"),mm_strdup($2), $3, make_str("cursor"), $5, make_str("for $1"));
298+
this->command = cat_str(6, make_str("declare"),cursor_marker, $3, make_str("cursor"), $5, make_str("for $1"));
298299
this->argsresult = NULL;
299300

300301
thisquery->type = &ecpg_query;
@@ -304,6 +305,12 @@ ECPGCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared
304305
sprintf(thisquery->name, "ECPGprepared_statement(%s, %s, __LINE__)", con, $7);
305306

306307
this->argsinsert = NULL;
308+
if ($2[0] == ':')
309+
{
310+
struct variable *var = find_variable($2 + 1);
311+
remove_variable_from_list(&argsinsert, var);
312+
add_variable_to_head(&(this->argsinsert), var, &no_indicator);
313+
}
307314
add_variable_to_head(&(this->argsinsert), thisquery, &no_indicator);
308315

309316
cur = this;
@@ -947,7 +954,13 @@ ECPGFree:SQL_FREE name{ $$ = $2; }
947954
/*
948955
* open is an open cursor, at the moment this has to be removed
949956
*/
950-
ECPGOpen: SQL_OPEN cursor_name opt_ecpg_using { $$ = $2; };
957+
ECPGOpen: SQL_OPEN cursor_name opt_ecpg_using
958+
{
959+
if ($2[0] == ':')
960+
remove_variable_from_list(&argsinsert, find_variable($2 + 1));
961+
$$ = $2;
962+
}
963+
;
951964

952965
opt_ecpg_using: /*EMPTY*/{ $$ = EMPTY; }
953966
| ecpg_using{ $$ = $1; }
@@ -1567,6 +1580,17 @@ civarind: cvariable indicator
15671580
}
15681581
;
15691582

1583+
char_civar: char_variable
1584+
{
1585+
char *ptr = strstr($1, ".arr");
1586+
1587+
if (ptr) /* varchar, we need the struct name here, not the struct element */
1588+
*ptr = '\0';
1589+
add_variable_to_head(&argsinsert, find_variable($1), &no_indicator);
1590+
$$ = $1;
1591+
}
1592+
;
1593+
15701594
civar: cvariable
15711595
{
15721596
add_variable_to_head(&argsinsert, find_variable($1), &no_indicator);
@@ -1782,6 +1806,10 @@ ecpg_into: INTO into_list{ $$ = EMPTY; }
17821806
| into_descriptor{ $$ = $1; }
17831807
;
17841808

1809+
opt_ecpg_into:/* EMPTY */{ $$ = EMPTY; }
1810+
| ecpg_into{ $$ = $1; }
1811+
;
1812+
17851813
%%
17861814

17871815
void base_yyerror(const char *error)

‎src/interfaces/ecpg/preproc/ecpg.type

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.type,v 1.3 2009/11/21 05:44:05 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.type,v 1.4 2009/11/26 15:06:47 meskes Exp $ */
22
%type <str> ECPGAllocateDescr
33
%type <str> ECPGCKeywords
44
%type <str> ECPGColId
@@ -42,6 +42,7 @@
4242
%type <str> c_term
4343
%type <str> c_thing
4444
%type <str> char_variable
45+
%type <str> char_civar
4546
%type <str> civar
4647
%type <str> civarind
4748
%type <str> ColId
@@ -75,6 +76,7 @@
7576
%type <str> opt_bit_field
7677
%type <str> opt_connection_name
7778
%type <str> opt_database_name
79+
%type <str> opt_ecpg_into
7880
%type <str> opt_ecpg_using
7981
%type <str> opt_initializer
8082
%type <str> opt_options

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.75 2009/09/08 04:25:00 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.76 2009/11/26 15:06:47 meskes Exp $ */
22

33
#ifndef_ECPG_PREPROC_EXTERN_H
44
#define_ECPG_PREPROC_EXTERN_H
@@ -90,6 +90,7 @@ extern struct descriptor *lookup_descriptor(char *, char *);
9090
externstructvariable*descriptor_variable(constchar*name,intinput);
9191
externvoidadd_variable_to_head(structarguments**,structvariable*,structvariable*);
9292
externvoidadd_variable_to_tail(structarguments**,structvariable*,structvariable*);
93+
externvoidremove_variable_from_list(structarguments**list,structvariable*var);
9394
externvoiddump_variables(structarguments*,int);
9495
externstructtypedefs*get_typedef(char*);
9596
externvoidadjust_array(enumECPGttype,char**,char**,char*,char*,int,bool);

‎src/interfaces/ecpg/preproc/parse.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl
2-
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.5 2009/11/21 05:44:05 tgl Exp $
2+
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.6 2009/11/26 15:06:47 meskes Exp $
33
# parser generater for ecpg
44
# call with backend parser as stdin
55
#
@@ -74,7 +74,8 @@
7474
$replace_line{'reserved_keywordUNION'} ='ignore';
7575

7676
# some other production rules have to be ignored or replaced
77-
$replace_line{'fetch_direction'} ='ignore';
77+
$replace_line{'fetch_argsFORWARDopt_from_incursor_name'} ='ignore';
78+
$replace_line{'fetch_argsBACKWARDopt_from_incursor_name'} ='ignore';
7879
$replace_line{"opt_array_boundsopt_array_bounds'['Iconst']'"} ='ignore';
7980
$replace_line{'VariableShowStmtSHOWvar_name'} ='SHOW var_name ecpg_into';
8081
$replace_line{'VariableShowStmtSHOWTIMEZONE'} ='SHOW TIME ZONE ecpg_into';

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.50 2009/08/07 10:51:20 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.51 2009/11/26 15:06:47 meskes Exp $ */
22

33
#include"postgres_fe.h"
44

@@ -401,6 +401,30 @@ add_variable_to_tail(struct arguments ** list, struct variable * var, struct var
401401
*list=new;
402402
}
403403

404+
void
405+
remove_variable_from_list(structarguments**list,structvariable*var)
406+
{
407+
structarguments*p,*prev=NULL;
408+
boolfound= false;
409+
410+
for (p=*list;p;p=p->next)
411+
{
412+
if (p->variable==var)
413+
{
414+
found= true;
415+
break;
416+
}
417+
prev=p;
418+
}
419+
if (found)
420+
{
421+
if (prev)
422+
prev->next=p->next;
423+
else
424+
*list=p->next;
425+
}
426+
}
427+
404428
/* Dump out a list of all the variable on this list.
405429
This is a recursive function that works from the end of the list and
406430
deletes the list as we go on.

‎src/interfaces/ecpg/test/ecpg_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ test: pgtypeslib/num_test2
1616
test: preproc/array_of_struct
1717
test: preproc/autoprep
1818
test: preproc/comment
19+
test: preproc/cursor
1920
test: preproc/define
2021
test: preproc/init
2122
test: preproc/strings

‎src/interfaces/ecpg/test/ecpg_schedule_tcp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ test: pgtypeslib/num_test2
1616
test: preproc/array_of_struct
1717
test: preproc/autoprep
1818
test: preproc/comment
19+
test: preproc/cursor
1920
test: preproc/define
2021
test: preproc/init
2122
test: preproc/strings

‎src/interfaces/ecpg/test/preproc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include $(top_srcdir)/$(subdir)/../Makefile.regress
77
TESTS = array_of_struct array_of_struct.c\
88
autoprep autoprep.c\
99
comment comment.c\
10+
cursor cursor.c\
1011
define define.c\
1112
init init.c\
1213
strings strings.c\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp