PostgreSQL Source Code  git master
sql-createtableas.c
Go to the documentation of this file.
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 #define ECPGdebug(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  int id ;
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  return 0;
164 }
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:153
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:676
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
void sqlprint(void)
Definition: error.c:334
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2275
#define printf(...)
Definition: port.h:244
int main(void)
#define ECPGdebug(X, Y)
#define sqlca
Definition: sqlca.h:59