PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sql-fetch.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 "fetch.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 
15 #line 1 "regression.h"
16 
17 
18 
19 
20 
21 
22 #line 5 "fetch.pgc"
23 
24 
25 int main() {
26  /* exec sql begin declare section */
27 
28 
29 
30 #line 9 "fetch.pgc"
31  char str [ 25 ] ;
32 
33 #line 10 "fetch.pgc"
34  int i , count = 1 ;
35 /* exec sql end declare section */
36 #line 11 "fetch.pgc"
37 
38 
39  ECPGdebug(1, stderr);
40  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
41 #line 14 "fetch.pgc"
42 
43 
44  /* exec sql whenever sql_warning sqlprint ; */
45 #line 16 "fetch.pgc"
46 
47  /* exec sql whenever sqlerror sqlprint ; */
48 #line 17 "fetch.pgc"
49 
50 
51  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table My_Table ( Item1 int , Item2 text )", ECPGt_EOIT, ECPGt_EORT);
52 #line 19 "fetch.pgc"
53 
54 if (sqlca.sqlwarn[0] == 'W') sqlprint();
55 #line 19 "fetch.pgc"
56 
57 if (sqlca.sqlcode < 0) sqlprint();}
58 #line 19 "fetch.pgc"
59 
60 
61  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 1 , 'text1' )", ECPGt_EOIT, ECPGt_EORT);
62 #line 21 "fetch.pgc"
63 
64 if (sqlca.sqlwarn[0] == 'W') sqlprint();
65 #line 21 "fetch.pgc"
66 
67 if (sqlca.sqlcode < 0) sqlprint();}
68 #line 21 "fetch.pgc"
69 
70  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 2 , 'text2' )", ECPGt_EOIT, ECPGt_EORT);
71 #line 22 "fetch.pgc"
72 
73 if (sqlca.sqlwarn[0] == 'W') sqlprint();
74 #line 22 "fetch.pgc"
75 
76 if (sqlca.sqlcode < 0) sqlprint();}
77 #line 22 "fetch.pgc"
78 
79  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 3 , 'text3' )", ECPGt_EOIT, ECPGt_EORT);
80 #line 23 "fetch.pgc"
81 
82 if (sqlca.sqlwarn[0] == 'W') sqlprint();
83 #line 23 "fetch.pgc"
84 
85 if (sqlca.sqlcode < 0) sqlprint();}
86 #line 23 "fetch.pgc"
87 
88  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 4 , 'text4' )", ECPGt_EOIT, ECPGt_EORT);
89 #line 24 "fetch.pgc"
90 
91 if (sqlca.sqlwarn[0] == 'W') sqlprint();
92 #line 24 "fetch.pgc"
93 
94 if (sqlca.sqlcode < 0) sqlprint();}
95 #line 24 "fetch.pgc"
96 
97 
98  /* declare C cursor for select * from My_Table */
99 #line 26 "fetch.pgc"
100 
101 
102  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select * from My_Table", ECPGt_EOIT, ECPGt_EORT);
103 #line 28 "fetch.pgc"
104 
105 if (sqlca.sqlwarn[0] == 'W') sqlprint();
106 #line 28 "fetch.pgc"
107 
108 if (sqlca.sqlcode < 0) sqlprint();}
109 #line 28 "fetch.pgc"
110 
111 
112  /* exec sql whenever not found break ; */
113 #line 30 "fetch.pgc"
114 
115  while (1) {
116  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT,
117  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
118  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
119  ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char),
120  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
121 #line 32 "fetch.pgc"
122 
123 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
124 #line 32 "fetch.pgc"
125 
126 if (sqlca.sqlwarn[0] == 'W') sqlprint();
127 #line 32 "fetch.pgc"
128 
129 if (sqlca.sqlcode < 0) sqlprint();}
130 #line 32 "fetch.pgc"
131 
132  printf("%d: %s\n", i, str);
133  }
134 
135  /* exec sql whenever not found continue ; */
136 #line 36 "fetch.pgc"
137 
138  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
139 #line 37 "fetch.pgc"
140 
141 if (sqlca.sqlwarn[0] == 'W') sqlprint();
142 #line 37 "fetch.pgc"
143 
144 if (sqlca.sqlcode < 0) sqlprint();}
145 #line 37 "fetch.pgc"
146 
147 
148  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0 in C",
149  ECPGt_int,&(count),(long)1,(long)1,sizeof(int),
150  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
151  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
152  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
153  ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char),
154  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
155 #line 39 "fetch.pgc"
156 
157 if (sqlca.sqlwarn[0] == 'W') sqlprint();
158 #line 39 "fetch.pgc"
159 
160 if (sqlca.sqlcode < 0) sqlprint();}
161 #line 39 "fetch.pgc"
162 
163  printf("%d: %s\n", i, str);
164 
165  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
166 #line 42 "fetch.pgc"
167 
168 if (sqlca.sqlwarn[0] == 'W') sqlprint();
169 #line 42 "fetch.pgc"
170 
171 if (sqlca.sqlcode < 0) sqlprint();}
172 #line 42 "fetch.pgc"
173 
174 
175  /* declare D cursor for select * from My_Table where Item1 = $1 */
176 #line 44 "fetch.pgc"
177 
178 
179  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare D cursor for select * from My_Table where Item1 = $1",
180  ECPGt_const,"1",(long)1,(long)1,strlen("1"),
181  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
182 #line 46 "fetch.pgc"
183 
184 if (sqlca.sqlwarn[0] == 'W') sqlprint();
185 #line 46 "fetch.pgc"
186 
187 if (sqlca.sqlcode < 0) sqlprint();}
188 #line 46 "fetch.pgc"
189 
190 
191  /* exec sql whenever not found break ; */
192 #line 48 "fetch.pgc"
193 
194  while (1) {
195  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in D", ECPGt_EOIT,
196  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
197  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
198  ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char),
199  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
200 #line 50 "fetch.pgc"
201 
202 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
203 #line 50 "fetch.pgc"
204 
205 if (sqlca.sqlwarn[0] == 'W') sqlprint();
206 #line 50 "fetch.pgc"
207 
208 if (sqlca.sqlcode < 0) sqlprint();}
209 #line 50 "fetch.pgc"
210 
211  printf("%d: %s\n", i, str);
212  }
213  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close D", ECPGt_EOIT, ECPGt_EORT);
214 #line 53 "fetch.pgc"
215 
216 if (sqlca.sqlwarn[0] == 'W') sqlprint();
217 #line 53 "fetch.pgc"
218 
219 if (sqlca.sqlcode < 0) sqlprint();}
220 #line 53 "fetch.pgc"
221 
222 
223  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table My_Table", ECPGt_EOIT, ECPGt_EORT);
224 #line 55 "fetch.pgc"
225 
226 if (sqlca.sqlwarn[0] == 'W') sqlprint();
227 #line 55 "fetch.pgc"
228 
229 if (sqlca.sqlcode < 0) sqlprint();}
230 #line 55 "fetch.pgc"
231 
232 
233  { ECPGdisconnect(__LINE__, "ALL");
234 #line 57 "fetch.pgc"
235 
236 if (sqlca.sqlwarn[0] == 'W') sqlprint();
237 #line 57 "fetch.pgc"
238 
239 if (sqlca.sqlcode < 0) sqlprint();}
240 #line 57 "fetch.pgc"
241 
242 
243  return 0;
244 }
#define ECPGdebug(X, Y)
Definition: sql-fetch.c:7
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
#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:2030
int main()
Definition: sql-fetch.c:25
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
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
void sqlprint(void)
Definition: error.c:336
#define NULL
Definition: c.h:229
int i