PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sql-dynalloc.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 "dynalloc.pgc"
10 #include <stdio.h>
11 
12 #line 1 "sqlca.h"
13 #ifndef POSTGRES_SQLCA_H
14 #define POSTGRES_SQLCA_H
15 
16 #ifndef PGDLLIMPORT
17 #if defined(WIN32) || defined(__CYGWIN__)
18 #define PGDLLIMPORT __declspec (dllimport)
19 #else
20 #define PGDLLIMPORT
21 #endif /* __CYGWIN__ */
22 #endif /* PGDLLIMPORT */
23 
24 #define SQLERRMC_LEN 150
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 struct sqlca_t
32 {
33  char sqlcaid[8];
34  long sqlabc;
35  long sqlcode;
36  struct
37  {
38  int sqlerrml;
39  char sqlerrmc[SQLERRMC_LEN];
41  char sqlerrp[8];
42  long sqlerrd[6];
43  /* Element 0: empty */
44  /* 1: OID of processed tuple if applicable */
45  /* 2: number of rows processed */
46  /* after an INSERT, UPDATE or */
47  /* DELETE statement */
48  /* 3: empty */
49  /* 4: empty */
50  /* 5: empty */
51  char sqlwarn[8];
52  /* Element 0: set to 'W' if at least one other is 'W' */
53  /* 1: if 'W' at least one character string */
54  /* value was truncated when it was */
55  /* stored into a host variable. */
56 
57  /*
58  * 2: if 'W' a (hopefully) non-fatal notice occurred
59  */ /* 3: empty */
60  /* 4: empty */
61  /* 5: empty */
62  /* 6: empty */
63  /* 7: empty */
64 
65  char sqlstate[5];
66 };
67 
68 struct sqlca_t *ECPGget_sqlca(void);
69 
70 #ifndef POSTGRES_ECPG_INTERNAL
71 #define sqlca (*ECPGget_sqlca())
72 #endif
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
79 
80 #line 2 "dynalloc.pgc"
81 
82 #include <stdlib.h>
83 
84 #line 1 "regression.h"
85 
86 
87 
88 
89 
90 
91 #line 4 "dynalloc.pgc"
92 
93 
94 int main(void)
95 {
96  /* exec sql begin declare section */
97 
98 
99 
100 
101 
102 
103 
104 /* char **d8=0; */
105 
106 
107 
108 
109 
110 
111 
112 
113 /* int *i8=0; */
114 
115 
116 #line 9 "dynalloc.pgc"
117  int * d1 = 0 ;
118 
119 #line 10 "dynalloc.pgc"
120  double * d2 = 0 ;
121 
122 #line 11 "dynalloc.pgc"
123  char ** d3 = 0 ;
124 
125 #line 12 "dynalloc.pgc"
126  char ** d4 = 0 ;
127 
128 #line 13 "dynalloc.pgc"
129  char ** d5 = 0 ;
130 
131 #line 14 "dynalloc.pgc"
132  char ** d6 = 0 ;
133 
134 #line 15 "dynalloc.pgc"
135  char ** d7 = 0 ;
136 
137 #line 17 "dynalloc.pgc"
138  char ** d9 = 0 ;
139 
140 #line 18 "dynalloc.pgc"
141  int * i1 = 0 ;
142 
143 #line 19 "dynalloc.pgc"
144  int * i2 = 0 ;
145 
146 #line 20 "dynalloc.pgc"
147  int * i3 = 0 ;
148 
149 #line 21 "dynalloc.pgc"
150  int * i4 = 0 ;
151 
152 #line 22 "dynalloc.pgc"
153  int * i5 = 0 ;
154 
155 #line 23 "dynalloc.pgc"
156  int * i6 = 0 ;
157 
158 #line 24 "dynalloc.pgc"
159  int * i7 = 0 ;
160 
161 #line 26 "dynalloc.pgc"
162  int * i9 = 0 ;
163 /* exec sql end declare section */
164 #line 27 "dynalloc.pgc"
165 
166  int i;
167 
168  ECPGdebug(1, stderr);
169 
170  /* exec sql whenever sqlerror do sqlprint ( ) ; */
171 #line 32 "dynalloc.pgc"
172 
173  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
174 #line 33 "dynalloc.pgc"
175 
176 if (sqlca.sqlcode < 0) sqlprint ( );}
177 #line 33 "dynalloc.pgc"
178 
179 
180  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to mdy", ECPGt_EOIT, ECPGt_EORT);
181 #line 35 "dynalloc.pgc"
182 
183 if (sqlca.sqlcode < 0) sqlprint ( );}
184 #line 35 "dynalloc.pgc"
185 
186 
187  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( a serial , b numeric ( 12 , 3 ) , c varchar , d varchar ( 3 ) , e char ( 4 ) , f timestamptz , g boolean , h box , i inet )", ECPGt_EOIT, ECPGt_EORT);
188 #line 37 "dynalloc.pgc"
189 
190 if (sqlca.sqlcode < 0) sqlprint ( );}
191 #line 37 "dynalloc.pgc"
192 
193  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( b , c , d , e , f , g , h , i ) values ( 23.456 , 'varchar' , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , true , '(1,2,3,4)' , '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128' )", ECPGt_EOIT, ECPGt_EORT);
194 #line 38 "dynalloc.pgc"
195 
196 if (sqlca.sqlcode < 0) sqlprint ( );}
197 #line 38 "dynalloc.pgc"
198 
199  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( b , c , d , e , f , g , h , i ) values ( 2.446456 , null , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , false , null , null )", ECPGt_EOIT, ECPGt_EORT);
200 #line 39 "dynalloc.pgc"
201 
202 if (sqlca.sqlcode < 0) sqlprint ( );}
203 #line 39 "dynalloc.pgc"
204 
205 
206  ECPGallocate_desc(__LINE__, "mydesc");
207 #line 41 "dynalloc.pgc"
208 
209 if (sqlca.sqlcode < 0) sqlprint ( );
210 #line 41 "dynalloc.pgc"
211 
212  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , b , c , d , e , f , g , h , i from test order by a", ECPGt_EOIT,
213  ECPGt_descriptor, "mydesc", 1L, 1L, 1L,
214  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
215 #line 42 "dynalloc.pgc"
216 
217 if (sqlca.sqlcode < 0) sqlprint ( );}
218 #line 42 "dynalloc.pgc"
219 
220  { ECPGget_desc(__LINE__, "mydesc", 1,ECPGd_indicator,
221  ECPGt_int,&(i1),(long)1,(long)0,sizeof(int), ECPGd_data,
222  ECPGt_int,&(d1),(long)1,(long)0,sizeof(int), ECPGd_EODT);
223 
224 #line 43 "dynalloc.pgc"
225 
226 if (sqlca.sqlcode < 0) sqlprint ( );}
227 #line 43 "dynalloc.pgc"
228 
229  { ECPGget_desc(__LINE__, "mydesc", 2,ECPGd_indicator,
230  ECPGt_int,&(i2),(long)1,(long)0,sizeof(int), ECPGd_data,
231  ECPGt_double,&(d2),(long)1,(long)0,sizeof(double), ECPGd_EODT);
232 
233 #line 44 "dynalloc.pgc"
234 
235 if (sqlca.sqlcode < 0) sqlprint ( );}
236 #line 44 "dynalloc.pgc"
237 
238  { ECPGget_desc(__LINE__, "mydesc", 3,ECPGd_indicator,
239  ECPGt_int,&(i3),(long)1,(long)0,sizeof(int), ECPGd_data,
240  ECPGt_char,&(d3),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
241 
242 #line 45 "dynalloc.pgc"
243 
244 if (sqlca.sqlcode < 0) sqlprint ( );}
245 #line 45 "dynalloc.pgc"
246 
247  { ECPGget_desc(__LINE__, "mydesc", 4,ECPGd_indicator,
248  ECPGt_int,&(i4),(long)1,(long)0,sizeof(int), ECPGd_data,
249  ECPGt_char,&(d4),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
250 
251 #line 46 "dynalloc.pgc"
252 
253 if (sqlca.sqlcode < 0) sqlprint ( );}
254 #line 46 "dynalloc.pgc"
255 
256  { ECPGget_desc(__LINE__, "mydesc", 5,ECPGd_indicator,
257  ECPGt_int,&(i5),(long)1,(long)0,sizeof(int), ECPGd_data,
258  ECPGt_char,&(d5),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
259 
260 #line 47 "dynalloc.pgc"
261 
262 if (sqlca.sqlcode < 0) sqlprint ( );}
263 #line 47 "dynalloc.pgc"
264 
265  { ECPGget_desc(__LINE__, "mydesc", 6,ECPGd_indicator,
266  ECPGt_int,&(i6),(long)1,(long)0,sizeof(int), ECPGd_data,
267  ECPGt_char,&(d6),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
268 
269 #line 48 "dynalloc.pgc"
270 
271 if (sqlca.sqlcode < 0) sqlprint ( );}
272 #line 48 "dynalloc.pgc"
273 
274  { ECPGget_desc(__LINE__, "mydesc", 7,ECPGd_indicator,
275  ECPGt_int,&(i7),(long)1,(long)0,sizeof(int), ECPGd_data,
276  ECPGt_char,&(d7),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
277 
278 #line 49 "dynalloc.pgc"
279 
280 if (sqlca.sqlcode < 0) sqlprint ( );}
281 #line 49 "dynalloc.pgc"
282 
283  /* skip box for now */
284  /* exec sql get descriptor mydesc value 8 :d8=DATA, :i8=INDICATOR; */
285  { ECPGget_desc(__LINE__, "mydesc", 9,ECPGd_indicator,
286  ECPGt_int,&(i9),(long)1,(long)0,sizeof(int), ECPGd_data,
287  ECPGt_char,&(d9),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
288 
289 #line 52 "dynalloc.pgc"
290 
291 if (sqlca.sqlcode < 0) sqlprint ( );}
292 #line 52 "dynalloc.pgc"
293 
294 
295  printf("Result:\n");
296  for (i=0;i<sqlca.sqlerrd[2];++i)
297  {
298  if (i1[i]) printf("NULL, ");
299  else printf("%d, ",d1[i]);
300 
301  if (i2[i]) printf("NULL, ");
302  else printf("%f, ",d2[i]);
303 
304  if (i3[i]) printf("NULL, ");
305  else printf("'%s', ",d3[i]);
306 
307  if (i4[i]) printf("NULL, ");
308  else printf("'%s', ",d4[i]);
309 
310  if (i5[i]) printf("NULL, ");
311  else printf("'%s', ",d5[i]);
312 
313  if (i6[i]) printf("NULL, ");
314  else printf("'%s', ",d6[i]);
315 
316  if (i7[i]) printf("NULL, ");
317  else printf("'%s', ",d7[i]);
318 
319  if (i9[i]) printf("NULL, ");
320  else printf("'%s', ",d9[i]);
321 
322  printf("\n");
323  }
325  printf("\n");
326 
327  ECPGdeallocate_desc(__LINE__, "mydesc");
328 #line 86 "dynalloc.pgc"
329 
330 if (sqlca.sqlcode < 0) sqlprint ( );
331 #line 86 "dynalloc.pgc"
332 
333  { ECPGdisconnect(__LINE__, "CURRENT");
334 #line 87 "dynalloc.pgc"
335 
336 if (sqlca.sqlcode < 0) sqlprint ( );}
337 #line 87 "dynalloc.pgc"
338 
339  return 0;
340 }
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
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:748
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:234
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:792
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_double
Definition: ecpgtype.h:47
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_descriptor
Definition: ecpgtype.h:59
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_EODT
Definition: ecpgtype.h:88
@ ECPGd_data
Definition: ecpgtype.h:74
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
int i
Definition: isn.c:72
void ECPGfree_auto_mem(void)
Definition: memory.c:131
#define printf(...)
Definition: port.h:244
int main(void)
Definition: sql-dynalloc.c:94
#define SQLERRMC_LEN
Definition: sql-dynalloc.c:24
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:108
#define sqlca
Definition: sql-dynalloc.c:71
#define ECPGdebug(X, Y)
Definition: sql-dynalloc.c:7
Definition: sqlca.h:20
char sqlerrp[8]
Definition: sqlca.h:29
long sqlerrd[6]
Definition: sqlca.h:30
char sqlstate[5]
Definition: sqlca.h:53
char sqlwarn[8]
Definition: sqlca.h:39
long sqlabc
Definition: sqlca.h:22
char sqlcaid[8]
Definition: sqlca.h:21
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
long sqlcode
Definition: sqlca.h:23
int sqlerrml
Definition: sqlca.h:26
struct sqlca_t::@163 sqlerrm