PostgreSQL Source Code  git master
sql-createtableas.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for sql-createtableas.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file sql-createtableas.c.

Referenced by main().

Function Documentation

◆ main()

int main ( void  )

Definition at line 31 of file sql-createtableas.c.

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, printf, sqlca, and sqlprint().

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 ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:684
#define sqlca
Definition: sqlca.h:59
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:2279
#define printf(...)
Definition: port.h:198
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
void sqlprint(void)
Definition: error.c:336
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:165
#define ECPGdebug(X, Y)