PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sql-oldexec.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-oldexec.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-oldexec.c.

Function Documentation

◆ main()

int main ( void  )

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

32{
33/* exec sql begin declare section */
34
35
36
37
38
39
40#line 14 "oldexec.pgc"
41 int amount [ 8 ] ;
42
43#line 15 "oldexec.pgc"
44 int increment = 100 ;
45
46#line 16 "oldexec.pgc"
47 char name [ 8 ] [ 8 ] ;
48
49#line 17 "oldexec.pgc"
50 char letter [ 8 ] [ 1 ] ;
51
52#line 18 "oldexec.pgc"
53 char command [ 128 ] ;
54/* exec sql end declare section */
55#line 19 "oldexec.pgc"
56
57 int i,j;
58
59 ECPGdebug(1, stderr);
60
61 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "main", 0);
62#line 24 "oldexec.pgc"
63
64if (sqlca.sqlcode < 0) sqlprint();}
65#line 24 "oldexec.pgc"
66
67
68 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
69#line 26 "oldexec.pgc"
70
71if (sqlca.sqlcode < 0) sqlprint();}
72#line 26 "oldexec.pgc"
73
74 { ECPGtrans(__LINE__, NULL, "commit");
75#line 27 "oldexec.pgc"
76
77if (sqlca.sqlcode < 0) sqlprint();}
78#line 27 "oldexec.pgc"
79
80
81 sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
82 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
83#line 30 "oldexec.pgc"
84
85if (sqlca.sqlcode < 0) sqlprint();}
86#line 30 "oldexec.pgc"
87
88
89 sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
90 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
91#line 33 "oldexec.pgc"
92
93if (sqlca.sqlcode < 0) sqlprint();}
94#line 33 "oldexec.pgc"
95
96
97 sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
98 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
99#line 36 "oldexec.pgc"
100
101if (sqlca.sqlcode < 0) sqlprint();}
102#line 36 "oldexec.pgc"
103
104
105 printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
106
107 sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
108 { ECPGprepare(__LINE__, NULL, 1, "i", command);
109#line 41 "oldexec.pgc"
110
111if (sqlca.sqlcode < 0) sqlprint();}
112#line 41 "oldexec.pgc"
113
114 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_execute, "i",
115 ECPGt_int,&(increment),(long)1,(long)1,sizeof(int),
116 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
117#line 42 "oldexec.pgc"
118
119if (sqlca.sqlcode < 0) sqlprint();}
120#line 42 "oldexec.pgc"
121
122
123 printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
124
125 { ECPGtrans(__LINE__, NULL, "commit");
126#line 46 "oldexec.pgc"
127
128if (sqlca.sqlcode < 0) sqlprint();}
129#line 46 "oldexec.pgc"
130
131
132 sprintf (command, "select * from test");
133
134 { ECPGprepare(__LINE__, NULL, 1, "f", command);
135#line 50 "oldexec.pgc"
136
137if (sqlca.sqlcode < 0) sqlprint();}
138#line 50 "oldexec.pgc"
139
140 /* declare CUR cursor for $1 */
141#line 51 "oldexec.pgc"
142
143
144 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR cursor for $1",
145 ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
146 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
147#line 53 "oldexec.pgc"
148
149if (sqlca.sqlcode < 0) sqlprint();}
150#line 53 "oldexec.pgc"
151
152 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT,
153 ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
154 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
155 ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
156 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
157 ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
158 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
159#line 54 "oldexec.pgc"
160
161if (sqlca.sqlcode < 0) sqlprint();}
162#line 54 "oldexec.pgc"
163
164
165 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
166 {
167 char n[8], l = letter[i][0];
168 int a = amount[i];
169
170 strncpy(n, name[i], 8);
171 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
172 }
173
174 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
175#line 65 "oldexec.pgc"
176
177if (sqlca.sqlcode < 0) sqlprint();}
178#line 65 "oldexec.pgc"
179
180
181 sprintf (command, "select * from test where ? = amount");
182
183 { ECPGprepare(__LINE__, NULL, 1, "f", command);
184#line 69 "oldexec.pgc"
185
186if (sqlca.sqlcode < 0) sqlprint();}
187#line 69 "oldexec.pgc"
188
189 /* declare CUR3 cursor for $1 */
190#line 70 "oldexec.pgc"
191
192
193 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR3 cursor for $1",
194 ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
195 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
196 ECPGt_const,"1",(long)1,(long)1,strlen("1"),
197 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
198#line 72 "oldexec.pgc"
199
200if (sqlca.sqlcode < 0) sqlprint();}
201#line 72 "oldexec.pgc"
202
203 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch in CUR3", ECPGt_EOIT,
204 ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
205 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
206 ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
207 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
208 ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
209 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
210#line 73 "oldexec.pgc"
211
212if (sqlca.sqlcode < 0) sqlprint();}
213#line 73 "oldexec.pgc"
214
215
216 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
217 {
218 char n[8], l = letter[i][0];
219 int a = amount[i];
220
221 strncpy(n, name[i], 8);
222 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
223 }
224
225 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR3", ECPGt_EOIT, ECPGt_EORT);
226#line 84 "oldexec.pgc"
227
228if (sqlca.sqlcode < 0) sqlprint();}
229#line 84 "oldexec.pgc"
230
231 { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
232#line 85 "oldexec.pgc"
233
234if (sqlca.sqlcode < 0) sqlprint();}
235#line 85 "oldexec.pgc"
236
237 { ECPGtrans(__LINE__, NULL, "commit");
238#line 86 "oldexec.pgc"
239
240if (sqlca.sqlcode < 0) sqlprint();}
241#line 86 "oldexec.pgc"
242
243 { ECPGdisconnect(__LINE__, "CURRENT");
244#line 87 "oldexec.pgc"
245
246if (sqlca.sqlcode < 0) sqlprint();}
247#line 87 "oldexec.pgc"
248
249
250 return 0;
251}
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
@ ECPGst_execute
Definition: ecpgtype.h:98
@ ECPGst_exec_immediate
Definition: ecpgtype.h:99
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_char_variable
Definition: ecpgtype.h:60
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_const
Definition: ecpgtype.h:61
@ ECPGt_char
Definition: ecpgtype.h:43
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
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition: prepare.c:368
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
int a
Definition: isn.c:70
int j
Definition: isn.c:75
int i
Definition: isn.c:74
#define sprintf
Definition: port.h:241
#define printf(...)
Definition: port.h:245
#define ECPGdebug(X, Y)
Definition: sql-oldexec.c:7
#define sqlca
Definition: sqlca.h:59
const char * name

References a, ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGprepare(), ECPGprepared_statement(), ECPGst_exec_immediate, ECPGst_execute, ECPGst_normal, ECPGt_char, ECPGt_char_variable, ECPGt_const, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), i, j, name, printf, sprintf, sqlca, and sqlprint().