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

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

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

Referenced by main().

#define PGDLLIMPORT

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

#define POSTGRES_SQLCA_H

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

#define sqlca   (*ECPGget_sqlca())

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

Referenced by main().

#define SQLERRMC_LEN   150

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

Function Documentation

struct sqlca_t* ECPGget_sqlca ( void  )

Definition at line 142 of file misc.c.

143 {
144 #ifdef ENABLE_THREAD_SAFETY
145  struct sqlca_t *sqlca;
146 
147  pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
148 
149  sqlca = pthread_getspecific(sqlca_key);
150  if (sqlca == NULL)
151  {
152  sqlca = malloc(sizeof(struct sqlca_t));
153  if (sqlca == NULL)
154  return NULL;
155  ecpg_init_sqlca(sqlca);
156  pthread_setspecific(sqlca_key, sqlca);
157  }
158  return (sqlca);
159 #else
160  return (&sqlca);
161 #endif
162 }
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
#define malloc(a)
Definition: header.h:50
Definition: sqlca.h:19
#define NULL
Definition: c.h:229
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
static struct sqlca_t sqlca
Definition: misc.c:63
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
int main ( void  )

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

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, NULL, sqlca, and sqlprint().

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 }
#define ECPGdebug(X, Y)
Definition: sql-dynalloc.c:7
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:759
void ECPGfree_auto_mem(void)
Definition: memory.c:138
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
#define sqlca
Definition: sql-dynalloc.c:71
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
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:245
void sqlprint(void)
Definition: error.c:336
#define NULL
Definition: c.h:229
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:712
int i