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

Commite81f0e3

Browse files
author
Michael Meskes
committed
Sync ECPG's CREATE TABLE AS statement with backend's.
Author: Higuchi-san ("Higuchi, Daisuke" <higuchi.daisuke@jp.fujitsu.com>)
1 parent050710b commite81f0e3

File tree

7 files changed

+283
-1
lines changed

7 files changed

+283
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ CreateAsStmt: CREATE OptTemp TABLE create_as_target AS {FoundInto = 0;} SelectSt
3434
if (FoundInto == 1)
3535
mmerror(PARSE_ERROR, ET_ERROR, "CREATE TABLE AS cannot specify INTO");
3636

37-
$$ = cat_str(6, mm_strdup("create"), $2, mm_strdup("table"), $4, mm_strdup("as"), $7);
37+
$$ = cat_str(7, mm_strdup("create"), $2, mm_strdup("table"), $4, mm_strdup("as"), $7, $8);
38+
}
39+
| CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS {FoundInto = 0;} SelectStmt opt_with_data
40+
{
41+
if (FoundInto == 1)
42+
mmerror(PARSE_ERROR, ET_ERROR, "CREATE TABLE AS cannot specify INTO");
43+
44+
$$ = cat_str(7, mm_strdup("create"), $2, mm_strdup("table if not exists"), $7, mm_strdup("as"), $10, $11);
3845
}
3946
;
4047

‎src/interfaces/ecpg/test/ecpg_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test: sql/binary
3535
test: sql/bytea
3636
test: sql/code100
3737
test: sql/copystdout
38+
test: sql/createtableas
3839
test: sql/define
3940
test: sql/desc
4041
test: sql/sqlda
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/* Processed by ecpg (regression mode) */
2+
/* These include files are added by the preprocessor */
3+
#include<ecpglib.h>
4+
#include<ecpgerrno.h>
5+
#include<sqlca.h>
6+
/* End of automatic include section */
7+
#defineECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8+
9+
#line 1 "createtableas.pgc"
10+
#include<stdlib.h>
11+
#include<string.h>
12+
#include<stdlib.h>
13+
#include<stdio.h>
14+
15+
16+
#line 1 "regression.h"
17+
18+
19+
20+
21+
22+
23+
#line 6 "createtableas.pgc"
24+
25+
26+
/* exec sql whenever sqlerror sqlprint ; */
27+
#line 8 "createtableas.pgc"
28+
29+
30+
int
31+
main(void)
32+
{
33+
/* exec sql begin declare section */
34+
35+
36+
#line 14 "createtableas.pgc"
37+
intid ;
38+
/* exec sql end declare section */
39+
#line 15 "createtableas.pgc"
40+
41+
42+
ECPGdebug(1,stderr);
43+
{ECPGconnect(__LINE__,0,"ecpg1_regression" ,NULL,NULL ,NULL,0);
44+
#line 18 "createtableas.pgc"
45+
46+
if (sqlca.sqlcode<0)sqlprint();}
47+
#line 18 "createtableas.pgc"
48+
49+
50+
{ECPGsetcommit(__LINE__,"on",NULL);
51+
#line 20 "createtableas.pgc"
52+
53+
if (sqlca.sqlcode<0)sqlprint();}
54+
#line 20 "createtableas.pgc"
55+
56+
/* exec sql whenever sql_warning sqlprint ; */
57+
#line 21 "createtableas.pgc"
58+
59+
/* exec sql whenever sqlerror sqlprint ; */
60+
#line 22 "createtableas.pgc"
61+
62+
63+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"create table cta_test ( id int )",ECPGt_EOIT,ECPGt_EORT);
64+
#line 24 "createtableas.pgc"
65+
66+
if (sqlca.sqlwarn[0]=='W')sqlprint();
67+
#line 24 "createtableas.pgc"
68+
69+
if (sqlca.sqlcode<0)sqlprint();}
70+
#line 24 "createtableas.pgc"
71+
72+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into cta_test values ( 100 )",ECPGt_EOIT,ECPGt_EORT);
73+
#line 25 "createtableas.pgc"
74+
75+
if (sqlca.sqlwarn[0]=='W')sqlprint();
76+
#line 25 "createtableas.pgc"
77+
78+
if (sqlca.sqlcode<0)sqlprint();}
79+
#line 25 "createtableas.pgc"
80+
81+
82+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"create table if not exists cta_test1 as select * from cta_test",ECPGt_EOIT,ECPGt_EORT);
83+
#line 27 "createtableas.pgc"
84+
85+
if (sqlca.sqlwarn[0]=='W')sqlprint();
86+
#line 27 "createtableas.pgc"
87+
88+
if (sqlca.sqlcode<0)sqlprint();}
89+
#line 27 "createtableas.pgc"
90+
91+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"select id from cta_test1",ECPGt_EOIT,
92+
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
93+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
94+
#line 28 "createtableas.pgc"
95+
96+
if (sqlca.sqlwarn[0]=='W')sqlprint();
97+
#line 28 "createtableas.pgc"
98+
99+
if (sqlca.sqlcode<0)sqlprint();}
100+
#line 28 "createtableas.pgc"
101+
102+
printf("ID = %d\n",id);
103+
104+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"create table cta_test2 as select * from cta_test with no data",ECPGt_EOIT,ECPGt_EORT);
105+
#line 31 "createtableas.pgc"
106+
107+
if (sqlca.sqlwarn[0]=='W')sqlprint();
108+
#line 31 "createtableas.pgc"
109+
110+
if (sqlca.sqlcode<0)sqlprint();}
111+
#line 31 "createtableas.pgc"
112+
113+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"select count ( id ) from cta_test2",ECPGt_EOIT,
114+
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
115+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
116+
#line 32 "createtableas.pgc"
117+
118+
if (sqlca.sqlwarn[0]=='W')sqlprint();
119+
#line 32 "createtableas.pgc"
120+
121+
if (sqlca.sqlcode<0)sqlprint();}
122+
#line 32 "createtableas.pgc"
123+
124+
printf("ID = %d\n",id);
125+
126+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"drop table cta_test",ECPGt_EOIT,ECPGt_EORT);
127+
#line 35 "createtableas.pgc"
128+
129+
if (sqlca.sqlwarn[0]=='W')sqlprint();
130+
#line 35 "createtableas.pgc"
131+
132+
if (sqlca.sqlcode<0)sqlprint();}
133+
#line 35 "createtableas.pgc"
134+
135+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"drop table cta_test1",ECPGt_EOIT,ECPGt_EORT);
136+
#line 36 "createtableas.pgc"
137+
138+
if (sqlca.sqlwarn[0]=='W')sqlprint();
139+
#line 36 "createtableas.pgc"
140+
141+
if (sqlca.sqlcode<0)sqlprint();}
142+
#line 36 "createtableas.pgc"
143+
144+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"drop table cta_test2",ECPGt_EOIT,ECPGt_EORT);
145+
#line 37 "createtableas.pgc"
146+
147+
if (sqlca.sqlwarn[0]=='W')sqlprint();
148+
#line 37 "createtableas.pgc"
149+
150+
if (sqlca.sqlcode<0)sqlprint();}
151+
#line 37 "createtableas.pgc"
152+
153+
{ECPGdisconnect(__LINE__,"ALL");
154+
#line 38 "createtableas.pgc"
155+
156+
if (sqlca.sqlwarn[0]=='W')sqlprint();
157+
#line 38 "createtableas.pgc"
158+
159+
if (sqlca.sqlcode<0)sqlprint();}
160+
#line 38 "createtableas.pgc"
161+
162+
163+
return0;
164+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[NO_PID]: ECPGdebug: set to 1
2+
[NO_PID]: sqlca: code: 0, state: 00000
3+
[NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
4+
[NO_PID]: sqlca: code: 0, state: 00000
5+
[NO_PID]: ECPGsetcommit on line 20: action "on"; connection "ecpg1_regression"
6+
[NO_PID]: sqlca: code: 0, state: 00000
7+
[NO_PID]: ecpg_execute on line 24: query: create table cta_test ( id int ); with 0 parameter(s) on connection ecpg1_regression
8+
[NO_PID]: sqlca: code: 0, state: 00000
9+
[NO_PID]: ecpg_execute on line 24: using PQexec
10+
[NO_PID]: sqlca: code: 0, state: 00000
11+
[NO_PID]: ecpg_process_output on line 24: OK: CREATE TABLE
12+
[NO_PID]: sqlca: code: 0, state: 00000
13+
[NO_PID]: ecpg_execute on line 25: query: insert into cta_test values ( 100 ); with 0 parameter(s) on connection ecpg1_regression
14+
[NO_PID]: sqlca: code: 0, state: 00000
15+
[NO_PID]: ecpg_execute on line 25: using PQexec
16+
[NO_PID]: sqlca: code: 0, state: 00000
17+
[NO_PID]: ecpg_process_output on line 25: OK: INSERT 0 1
18+
[NO_PID]: sqlca: code: 0, state: 00000
19+
[NO_PID]: ecpg_execute on line 27: query: create table if not exists cta_test1 as select * from cta_test; with 0 parameter(s) on connection ecpg1_regression
20+
[NO_PID]: sqlca: code: 0, state: 00000
21+
[NO_PID]: ecpg_execute on line 27: using PQexec
22+
[NO_PID]: sqlca: code: 0, state: 00000
23+
[NO_PID]: ecpg_process_output on line 27: OK: SELECT 1
24+
[NO_PID]: sqlca: code: 0, state: 00000
25+
[NO_PID]: ecpg_execute on line 28: query: select id from cta_test1; with 0 parameter(s) on connection ecpg1_regression
26+
[NO_PID]: sqlca: code: 0, state: 00000
27+
[NO_PID]: ecpg_execute on line 28: using PQexec
28+
[NO_PID]: sqlca: code: 0, state: 00000
29+
[NO_PID]: ecpg_process_output on line 28: correctly got 1 tuples with 1 fields
30+
[NO_PID]: sqlca: code: 0, state: 00000
31+
[NO_PID]: ecpg_get_data on line 28: RESULT: 100 offset: -1; array: no
32+
[NO_PID]: sqlca: code: 0, state: 00000
33+
[NO_PID]: ecpg_execute on line 31: query: create table cta_test2 as select * from cta_test with no data; with 0 parameter(s) on connection ecpg1_regression
34+
[NO_PID]: sqlca: code: 0, state: 00000
35+
[NO_PID]: ecpg_execute on line 31: using PQexec
36+
[NO_PID]: sqlca: code: 0, state: 00000
37+
[NO_PID]: ecpg_process_output on line 31: OK: CREATE TABLE AS
38+
[NO_PID]: sqlca: code: 0, state: 00000
39+
[NO_PID]: ecpg_execute on line 32: query: select count ( id ) from cta_test2; with 0 parameter(s) on connection ecpg1_regression
40+
[NO_PID]: sqlca: code: 0, state: 00000
41+
[NO_PID]: ecpg_execute on line 32: using PQexec
42+
[NO_PID]: sqlca: code: 0, state: 00000
43+
[NO_PID]: ecpg_process_output on line 32: correctly got 1 tuples with 1 fields
44+
[NO_PID]: sqlca: code: 0, state: 00000
45+
[NO_PID]: ecpg_get_data on line 32: RESULT: 0 offset: -1; array: no
46+
[NO_PID]: sqlca: code: 0, state: 00000
47+
[NO_PID]: ecpg_execute on line 35: query: drop table cta_test; with 0 parameter(s) on connection ecpg1_regression
48+
[NO_PID]: sqlca: code: 0, state: 00000
49+
[NO_PID]: ecpg_execute on line 35: using PQexec
50+
[NO_PID]: sqlca: code: 0, state: 00000
51+
[NO_PID]: ecpg_process_output on line 35: OK: DROP TABLE
52+
[NO_PID]: sqlca: code: 0, state: 00000
53+
[NO_PID]: ecpg_execute on line 36: query: drop table cta_test1; with 0 parameter(s) on connection ecpg1_regression
54+
[NO_PID]: sqlca: code: 0, state: 00000
55+
[NO_PID]: ecpg_execute on line 36: using PQexec
56+
[NO_PID]: sqlca: code: 0, state: 00000
57+
[NO_PID]: ecpg_process_output on line 36: OK: DROP TABLE
58+
[NO_PID]: sqlca: code: 0, state: 00000
59+
[NO_PID]: ecpg_execute on line 37: query: drop table cta_test2; with 0 parameter(s) on connection ecpg1_regression
60+
[NO_PID]: sqlca: code: 0, state: 00000
61+
[NO_PID]: ecpg_execute on line 37: using PQexec
62+
[NO_PID]: sqlca: code: 0, state: 00000
63+
[NO_PID]: ecpg_process_output on line 37: OK: DROP TABLE
64+
[NO_PID]: sqlca: code: 0, state: 00000
65+
[NO_PID]: ecpg_finish: connection ecpg1_regression closed
66+
[NO_PID]: sqlca: code: 0, state: 00000
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ID = 100
2+
ID = 0

‎src/interfaces/ecpg/test/sql/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ TESTS = array array.c \
77
binary binary.c\
88
code100 code100.c\
99
copystdout copystdout.c\
10+
createtableas createtableas.c\
1011
define define.c\
1112
desc desc.c\
1213
sqlda sqlda.c\
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
#include <stdio.h>
5+
6+
exec sql include ../regression;
7+
8+
exec sql whenever sqlerror sqlprint;
9+
10+
int
11+
main(void)
12+
{
13+
EXEC SQL BEGIN DECLARE SECTION;
14+
int id;
15+
EXEC SQL END DECLARE SECTION;
16+
17+
ECPGdebug(1, stderr);
18+
EXEC SQL connect to REGRESSDB1;
19+
20+
EXEC SQL SET AUTOCOMMIT TO ON;
21+
EXEC SQL WHENEVER SQLWARNING SQLPRINT;
22+
EXEC SQL WHENEVER SQLERROR SQLPRINT;
23+
24+
EXEC SQL CREATE TABLE cta_test (id int);
25+
EXEC SQL INSERT INTO cta_test values (100);
26+
27+
EXEC SQL CREATE TABLE IF NOT EXISTS cta_test1 AS SELECT * FROM cta_test;
28+
EXEC SQL SELECT id INTO :id FROM cta_test1;
29+
printf("ID = %d\n", id);
30+
31+
EXEC SQL CREATE TABLE cta_test2 AS SELECT * FROM cta_test WITH NO DATA;
32+
EXEC SQL SELECT count(id) INTO :id FROM cta_test2;
33+
printf("ID = %d\n", id);
34+
35+
EXEC SQL DROP TABLE cta_test;
36+
EXEC SQL DROP TABLE cta_test1;
37+
EXEC SQL DROP TABLE cta_test2;
38+
EXEC SQL DISCONNECT all;
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp