PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sql-dynalloc.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for sql-dynalloc.c:

Go to the source code of this file.

Data Structures

struct  sqlca_t
 

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 
#define POSTGRES_SQLCA_H
 
#define PGDLLIMPORT
 
#define SQLERRMC_LEN   150
 
#define sqlca   (*ECPGget_sqlca())
 

Functions

struct sqlca_tECPGget_sqlca (void)
 
int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

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

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

◆ PGDLLIMPORT

#define PGDLLIMPORT

Definition at line 20 of file sql-dynalloc.c.

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

Definition at line 14 of file sql-dynalloc.c.

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

Definition at line 71 of file sql-dynalloc.c.

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 24 of file sql-dynalloc.c.

Function Documentation

◆ ECPGget_sqlca()

struct sqlca_t * ECPGget_sqlca ( void  )

Definition at line 108 of file misc.c.

109{
110 struct sqlca_t *sqlca;
111
112 pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
113
115 if (sqlca == NULL)
116 {
117 sqlca = malloc(sizeof(struct sqlca_t));
118 if (sqlca == NULL)
119 return NULL;
122 }
123 return sqlca;
124}
#define malloc(a)
Definition: header.h:50
static pthread_key_t sqlca_key
Definition: misc.c:58
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
static void ecpg_sqlca_key_init(void)
Definition: misc.c:102
static pthread_once_t sqlca_key_once
Definition: misc.c:59
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

◆ main()

int main ( void  )

Definition at line 94 of file sql-dynalloc.c.

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
176if (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
183if (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
190if (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
196if (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
202if (sqlca.sqlcode < 0) sqlprint ( );}
203#line 39 "dynalloc.pgc"
204
205
206 ECPGallocate_desc(__LINE__, "mydesc");
207#line 41 "dynalloc.pgc"
208
209if (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
217if (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
226if (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
235if (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
244if (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
253if (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
262if (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
271if (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
280if (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
291if (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
330if (sqlca.sqlcode < 0) sqlprint ( );
331#line 86 "dynalloc.pgc"
332
333 { ECPGdisconnect(__LINE__, "CURRENT");
334#line 87 "dynalloc.pgc"
335
336if (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
#define sqlca
Definition: sql-dynalloc.c:71
#define ECPGdebug(X, Y)
Definition: sql-dynalloc.c:7

References ECPGallocate_desc(), ECPGconnect(), ECPGd_data, ECPGd_EODT, ECPGd_indicator, ECPGdeallocate_desc(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGfree_auto_mem(), ECPGget_desc(), ECPGst_normal, ECPGt_char, ECPGt_descriptor, ECPGt_double, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, i, printf, sqlca, and sqlprint().