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

Commit98e4005

Browse files
author
Michael Meskes
committed
Added variable handling for RETURNING clause to ecpg.
While the values were correctly returned they were not moved into C variablesas they should be.Closes: #5489
1 parentdcd52a6 commit98e4005

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

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

Lines changed: 2 additions & 1 deletion
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.8 2010/05/30 18:10:41 tgl Exp $
2+
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.9 2010/06/0410:09:58 meskes Exp $
33
# parser generater for ecpg
44
# call with backend parser as stdin
55
#
@@ -83,6 +83,7 @@
8383
$replace_line{'VariableShowStmtSHOWTIMEZONE'} ='SHOW TIME ZONE ecpg_into';
8484
$replace_line{'VariableShowStmtSHOWTRANSACTIONISOLATIONLEVEL'} ='SHOW TRANSACTION ISOLATION LEVEL ecpg_into';
8585
$replace_line{'VariableShowStmtSHOWSESSIONAUTHORIZATION'} ='SHOW SESSION AUTHORIZATION ecpg_into';
86+
$replace_line{'returning_clauseRETURNINGtarget_list'} ='RETURNING target_list ecpg_into';
8687
$replace_line{'ExecuteStmtEXECUTEnameexecute_param_clause'} ='EXECUTE prepared_name execute_param_clause execute_rest';
8788
$replace_line{'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'} ='CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause';
8889
$replace_line{'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'} ='PREPARE prepared_name prep_type_clause AS PreparableStmt';

‎src/interfaces/ecpg/test/expected/sql-insupd.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
intmain() {
2626
/* exec sql begin declare section */
27-
27+
2828

2929
#line 9 "insupd.pgc"
30-
inti1 [3 ] ,i2 [3 ] ;
30+
inti1 [3 ] ,i2 [3 ],i3 [3 ] ,i4;
3131
/* exec sql end declare section */
3232
#line 10 "insupd.pgc"
3333

@@ -72,7 +72,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
7272
if (sqlca.sqlcode<0)sqlprint();}
7373
#line 21 "insupd.pgc"
7474

75-
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into insupd_test ( a , b ) values ( 3 , 3 )",ECPGt_EOIT,ECPGt_EORT);
75+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into insupd_test ( a , b ) values ( 3 , 3 ) returning a",ECPGt_EOIT,
76+
ECPGt_int,&(i4),(long)1,(long)1,sizeof(int),
77+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
7678
#line 22 "insupd.pgc"
7779

7880
if (sqlca.sqlwarn[0]=='W')sqlprint();
@@ -82,7 +84,9 @@ if (sqlca.sqlcode < 0) sqlprint();}
8284
#line 22 "insupd.pgc"
8385

8486

85-
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"update insupd_test set a = a + 1",ECPGt_EOIT,ECPGt_EORT);
87+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"update insupd_test set a = a + 1 returning a",ECPGt_EOIT,
88+
ECPGt_int,(i3),(long)1,(long)3,sizeof(int),
89+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
8690
#line 24 "insupd.pgc"
8791

8892
if (sqlca.sqlwarn[0]=='W')sqlprint();
@@ -124,16 +128,17 @@ if (sqlca.sqlcode < 0) sqlprint();}
124128
#line 28 "insupd.pgc"
125129

126130

131+
printf("changes\n%d %d %d %d\n",i3[0],i3[1],i3[2],i4);
127132
printf("test\na b\n%d %d\n%d %d\n%d %d\n",i1[0],i2[0],i1[1],i2[1],i1[2],i2[2]);
128133

129134
{ECPGdisconnect(__LINE__,"ALL");
130-
#line32 "insupd.pgc"
135+
#line33 "insupd.pgc"
131136

132137
if (sqlca.sqlwarn[0]=='W')sqlprint();
133-
#line32 "insupd.pgc"
138+
#line33 "insupd.pgc"
134139

135140
if (sqlca.sqlcode<0)sqlprint();}
136-
#line32 "insupd.pgc"
141+
#line33 "insupd.pgc"
137142

138143

139144
return0;

‎src/interfaces/ecpg/test/expected/sql-insupd.stderr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@
2020
[NO_PID]: sqlca: code: 0, state: 00000
2121
[NO_PID]: ecpg_execute on line 21: OK: INSERT 0 1
2222
[NO_PID]: sqlca: code: 0, state: 00000
23-
[NO_PID]: ecpg_execute on line 22: query: insert into insupd_test ( a , b ) values ( 3 , 3 ); with 0 parameter(s) on connection regress1
23+
[NO_PID]: ecpg_execute on line 22: query: insert into insupd_test ( a , b ) values ( 3 , 3 ) returning a; with 0 parameter(s) on connection regress1
2424
[NO_PID]: sqlca: code: 0, state: 00000
2525
[NO_PID]: ecpg_execute on line 22: using PQexec
2626
[NO_PID]: sqlca: code: 0, state: 00000
27-
[NO_PID]: ecpg_execute on line 22:OK: INSERT 0 1
27+
[NO_PID]: ecpg_execute on line 22:correctly got 1 tuples with 1 fields
2828
[NO_PID]: sqlca: code: 0, state: 00000
29-
[NO_PID]: ecpg_execute on line 24: query: update insupd_test set a = a + 1; with 0 parameter(s) on connection regress1
29+
[NO_PID]: ecpg_get_data on line 22: RESULT: 3 offset: -1; array: no
30+
[NO_PID]: sqlca: code: 0, state: 00000
31+
[NO_PID]: ecpg_execute on line 24: query: update insupd_test set a = a + 1 returning a; with 0 parameter(s) on connection regress1
3032
[NO_PID]: sqlca: code: 0, state: 00000
3133
[NO_PID]: ecpg_execute on line 24: using PQexec
3234
[NO_PID]: sqlca: code: 0, state: 00000
33-
[NO_PID]: ecpg_execute on line 24: OK: UPDATE 3
35+
[NO_PID]: ecpg_execute on line 24: correctly got 3 tuples with 1 fields
36+
[NO_PID]: sqlca: code: 0, state: 00000
37+
[NO_PID]: ecpg_get_data on line 24: RESULT: 2 offset: -1; array: no
38+
[NO_PID]: sqlca: code: 0, state: 00000
39+
[NO_PID]: ecpg_get_data on line 24: RESULT: 3 offset: -1; array: no
40+
[NO_PID]: sqlca: code: 0, state: 00000
41+
[NO_PID]: ecpg_get_data on line 24: RESULT: 4 offset: -1; array: no
3442
[NO_PID]: sqlca: code: 0, state: 00000
3543
[NO_PID]: ecpg_execute on line 25: query: update insupd_test set ( a , b ) = ( 5 , 5 ) where a = 4; with 0 parameter(s) on connection regress1
3644
[NO_PID]: sqlca: code: 0, state: 00000

‎src/interfaces/ecpg/test/expected/sql-insupd.stdout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
changes
2+
2 3 4 3
13
test
24
a b
35
2 1

‎src/interfaces/ecpg/test/sql/insupd.pgc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ EXEC SQL INCLUDE ../regression;
66

77
int main() {
88
EXEC SQL BEGIN DECLARE SECTION;
9-
int i1[3], i2[3];
9+
int i1[3], i2[3], i3[3], i4;
1010
EXEC SQL END DECLARE SECTION;
1111

1212
ECPGdebug(1, stderr);
@@ -19,14 +19,15 @@ int main() {
1919

2020
EXEC SQL INSERT INTO insupd_test (a,b) values (1, 1);
2121
EXEC SQL INSERT INTO insupd_test (a,b) values (2, 2);
22-
EXEC SQL INSERT INTO insupd_test (a,b) values (3, 3);
22+
EXEC SQL INSERT INTO insupd_test (a,b) values (3, 3) returning a into :i4;
2323

24-
EXEC SQL UPDATE insupd_test set a=a+1;
24+
EXEC SQL UPDATE insupd_test set a=a+1 returning a into :i3;
2525
EXEC SQL UPDATE insupd_test set (a,b)=(5,5) where a = 4;
2626
EXEC SQL UPDATE insupd_test set a=4 where a=3;;
2727

2828
EXEC SQL SELECT a,b into :i1,:i2 from insupd_test order by a;
2929

30+
printf("changes\n%d %d %d %d\n", i3[0], i3[1], i3[2], i4);
3031
printf("test\na b\n%d %d\n%d %d\n%d %d\n", i1[0], i2[0], i1[1], i2[1], i1[2], i2[2]);
3132

3233
EXEC SQL DISCONNECT ALL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp