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

Go to the source code of this file.

Data Structures

struct  sqlca_t
 

Macros

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

Enumerations

enum  {
  SQL3_CHARACTER = 1, SQL3_NUMERIC, SQL3_DECIMAL, SQL3_INTEGER,
  SQL3_SMALLINT, SQL3_FLOAT, SQL3_REAL, SQL3_DOUBLE_PRECISION,
  SQL3_DATE_TIME_TIMESTAMP, SQL3_INTERVAL, SQL3_CHARACTER_VARYING = 12, SQL3_ENUMERATED,
  SQL3_BIT, SQL3_BIT_VARYING, SQL3_BOOLEAN, SQL3_abstract
}
 
enum  {
  SQL3_DDT_DATE = 1, SQL3_DDT_TIME, SQL3_DDT_TIMESTAMP, SQL3_DDT_TIME_WITH_TIME_ZONE,
  SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE, SQL3_DDT_ILLEGAL
}
 

Functions

struct sqlca_tECPGget_sqlca (void)
 
static void error (void)
 
int main ()
 

Macro Definition Documentation

#define _ECPG_SQL3TYPES_H

Definition at line 19 of file sql-dyntest.c.

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

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

Referenced by main().

#define PGDLLIMPORT

Definition at line 73 of file sql-dyntest.c.

#define POSTGRES_SQLCA_H

Definition at line 67 of file sql-dyntest.c.

#define sqlca   (*ECPGget_sqlca())

Definition at line 124 of file sql-dyntest.c.

Referenced by error(), and main().

#define SQLERRMC_LEN   150

Definition at line 77 of file sql-dyntest.c.

Enumeration Type Documentation

anonymous enum
Enumerator
SQL3_CHARACTER 
SQL3_NUMERIC 
SQL3_DECIMAL 
SQL3_INTEGER 
SQL3_SMALLINT 
SQL3_FLOAT 
SQL3_REAL 
SQL3_DOUBLE_PRECISION 
SQL3_DATE_TIME_TIMESTAMP 
SQL3_INTERVAL 
SQL3_CHARACTER_VARYING 
SQL3_ENUMERATED 
SQL3_BIT 
SQL3_BIT_VARYING 
SQL3_BOOLEAN 
SQL3_abstract 

Definition at line 25 of file sql-dyntest.c.

anonymous enum
Enumerator
SQL3_DDT_DATE 
SQL3_DDT_TIME 
SQL3_DDT_TIMESTAMP 
SQL3_DDT_TIME_WITH_TIME_ZONE 
SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE 
SQL3_DDT_ILLEGAL 

Definition at line 48 of file sql-dyntest.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
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 154 of file sql-dyntest.c.

References COUNT, ECPGallocate_desc(), ECPGconnect(), ECPGd_data, ECPGd_di_code, ECPGd_EODT, ECPGd_indicator, ECPGd_length, ECPGd_name, ECPGd_octet, ECPGd_precision, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGdeallocate_desc(), ECPGdebug, ECPGdo(), ECPGget_desc(), ECPGget_desc_header(), ECPGprepare(), ECPGprepared_statement(), ECPGst_normal, ECPGt_bool, ECPGt_char, ECPGt_char_variable, ECPGt_descriptor, ECPGt_double, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, error(), SQL3_BOOLEAN, SQL3_CHARACTER, SQL3_CHARACTER_VARYING, SQL3_DATE_TIME_TIMESTAMP, SQL3_DDT_DATE, SQL3_DDT_TIME, SQL3_DDT_TIME_WITH_TIME_ZONE, SQL3_DDT_TIMESTAMP, SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE, SQL3_DECIMAL, SQL3_DOUBLE_PRECISION, SQL3_FLOAT, SQL3_INTEGER, SQL3_INTERVAL, SQL3_NUMERIC, SQL3_REAL, SQL3_SMALLINT, and sqlca.

155 {
156  /* exec sql begin declare section */
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 #line 22 "dyntest.pgc"
169  int COUNT ;
170 
171 #line 23 "dyntest.pgc"
172  int INTVAR ;
173 
174 #line 24 "dyntest.pgc"
175  int INDEX ;
176 
177 #line 25 "dyntest.pgc"
178  int INDICATOR ;
179 
180 #line 26 "dyntest.pgc"
181  int TYPE , LENGTH , OCTET_LENGTH , PRECISION , SCALE , RETURNED_OCTET_LENGTH ;
182 
183 #line 27 "dyntest.pgc"
184  int DATETIME_INTERVAL_CODE ;
185 
186 #line 28 "dyntest.pgc"
187  char NAME [ 120 ] , BOOLVAR ;
188 
189 #line 29 "dyntest.pgc"
190  char STRINGVAR [ 1024 ] ;
191 
192 #line 30 "dyntest.pgc"
193  double DOUBLEVAR ;
194 
195 #line 31 "dyntest.pgc"
196  char * QUERY ;
197 /* exec sql end declare section */
198 #line 32 "dyntest.pgc"
199 
200  int done = 0;
201 
202  /* exec sql var BOOLVAR is bool */
203 #line 35 "dyntest.pgc"
204 
205 
206  ECPGdebug (1, stderr);
207 
208  QUERY = "select * from dyntest";
209 
210  /* exec sql whenever sqlerror do error ( ) ; */
211 #line 43 "dyntest.pgc"
212 
213 
214  ECPGallocate_desc(__LINE__, "MYDESC");
215 #line 45 "dyntest.pgc"
216 
217 if (sqlca.sqlcode < 0) error ( );
218 #line 45 "dyntest.pgc"
219 
220 
221  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
222 #line 47 "dyntest.pgc"
223 
224 if (sqlca.sqlcode < 0) error ( );}
225 #line 47 "dyntest.pgc"
226 
227 
228  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to german", ECPGt_EOIT, ECPGt_EORT);
229 #line 49 "dyntest.pgc"
230 
231 if (sqlca.sqlcode < 0) error ( );}
232 #line 49 "dyntest.pgc"
233 
234 
235  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table dyntest ( name char ( 14 ) , d float8 , i int , bignumber int8 , b boolean , comment text , day date )", ECPGt_EOIT, ECPGt_EORT);
236 #line 53 "dyntest.pgc"
237 
238 if (sqlca.sqlcode < 0) error ( );}
239 #line 53 "dyntest.pgc"
240 
241  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true , 'The world''s most advanced open source database.' , '1987-07-14' )", ECPGt_EOIT, ECPGt_EORT);
242 #line 54 "dyntest.pgc"
243 
244 if (sqlca.sqlcode < 0) error ( );}
245 #line 54 "dyntest.pgc"
246 
247  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210 , false , 'The elephant never forgets.' , '1999-11-5' )", ECPGt_EOIT, ECPGt_EORT);
248 #line 55 "dyntest.pgc"
249 
250 if (sqlca.sqlcode < 0) error ( );}
251 #line 55 "dyntest.pgc"
252 
253 
254  { ECPGprepare(__LINE__, NULL, 0, "myquery", QUERY);
255 #line 57 "dyntest.pgc"
256 
257 if (sqlca.sqlcode < 0) error ( );}
258 #line 57 "dyntest.pgc"
259 
260  /* declare MYCURS cursor for $1 */
261 #line 58 "dyntest.pgc"
262 
263 
264  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare MYCURS cursor for $1",
265  ECPGt_char_variable,(ECPGprepared_statement(NULL, "myquery", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
266  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
267 #line 60 "dyntest.pgc"
268 
269 if (sqlca.sqlcode < 0) error ( );}
270 #line 60 "dyntest.pgc"
271 
272 
273  while (1)
274  {
275  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in MYCURS", ECPGt_EOIT,
276  ECPGt_descriptor, "MYDESC", 1L, 1L, 1L,
277  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
278 #line 64 "dyntest.pgc"
279 
280 if (sqlca.sqlcode < 0) error ( );}
281 #line 64 "dyntest.pgc"
282 
283 
284  if (sqlca.sqlcode)
285  break;
286 
287  { ECPGget_desc_header(__LINE__, "MYDESC", &(COUNT));
288 
289 #line 69 "dyntest.pgc"
290 
291 if (sqlca.sqlcode < 0) error ( );}
292 #line 69 "dyntest.pgc"
293 
294  if (!done)
295  {
296  printf ("Found %d columns\n", COUNT);
297  done = 1;
298  }
299 
300  for (INDEX = 1; INDEX <= COUNT; ++INDEX)
301  {
302  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_indicator,
303  ECPGt_int,&(INDICATOR),(long)1,(long)1,sizeof(int), ECPGd_name,
304  ECPGt_char,(NAME),(long)120,(long)1,(120)*sizeof(char), ECPGd_scale,
305  ECPGt_int,&(SCALE),(long)1,(long)1,sizeof(int), ECPGd_precision,
306  ECPGt_int,&(PRECISION),(long)1,(long)1,sizeof(int), ECPGd_ret_octet,
307  ECPGt_int,&(RETURNED_OCTET_LENGTH),(long)1,(long)1,sizeof(int), ECPGd_octet,
308  ECPGt_int,&(OCTET_LENGTH),(long)1,(long)1,sizeof(int), ECPGd_length,
309  ECPGt_int,&(LENGTH),(long)1,(long)1,sizeof(int), ECPGd_type,
310  ECPGt_int,&(TYPE),(long)1,(long)1,sizeof(int), ECPGd_EODT);
311 
312 #line 86 "dyntest.pgc"
313 
314 if (sqlca.sqlcode < 0) error ( );}
315 #line 86 "dyntest.pgc"
316 
317  printf ("%2d\t%s (type: %d length: %d precision: %d scale: %d = " , INDEX, NAME, TYPE, LENGTH, PRECISION, SCALE);
318  switch (TYPE)
319  {
320  case SQL3_BOOLEAN:
321  printf ("bool");
322  break;
323  case SQL3_NUMERIC:
324  printf ("numeric(%d,%d)", PRECISION, SCALE);
325  break;
326  case SQL3_DECIMAL:
327  printf ("decimal(%d,%d)", PRECISION, SCALE);
328  break;
329  case SQL3_INTEGER:
330  printf ("integer");
331  break;
332  case SQL3_SMALLINT:
333  printf ("smallint");
334  break;
335  case SQL3_FLOAT:
336  printf ("float(%d,%d)", PRECISION, SCALE);
337  break;
338  case SQL3_REAL:
339  printf ("real");
340  break;
342  printf ("double precision");
343  break;
345  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_di_code,
346  ECPGt_int,&(DATETIME_INTERVAL_CODE),(long)1,(long)1,sizeof(int), ECPGd_EODT);
347 
348 #line 116 "dyntest.pgc"
349 
350 if (sqlca.sqlcode < 0) error ( );}
351 #line 116 "dyntest.pgc"
352 
353  switch (DATETIME_INTERVAL_CODE)
354  {
355  case SQL3_DDT_DATE:
356  printf ("date");
357  break;
358  case SQL3_DDT_TIME:
359  printf ("time");
360  break;
361  case SQL3_DDT_TIMESTAMP:
362  printf ("timestamp");
363  break;
365  printf ("time with time zone");
366  break;
368  printf ("timestamp with time zone");
369  break;
370  }
371  break;
372  case SQL3_INTERVAL:
373  printf ("interval");
374  break;
375  case SQL3_CHARACTER:
376  if (LENGTH > 0)
377  printf ("char(%d)", LENGTH);
378  else
379  printf ("text");
380  break;
382  if (LENGTH > 0)
383  printf ("varchar(%d)", LENGTH);
384  else
385  printf ("varchar()");
386  break;
387  default:
388  printf ("<SQL3 %d>", TYPE);
389  break;
390  }
391  printf (")\n\toctet_length: %d returned_octet_length: %d)\n\t= ",
392  OCTET_LENGTH, RETURNED_OCTET_LENGTH);
393  if (INDICATOR == -1)
394  printf ("NULL\n");
395  else
396  switch (TYPE)
397  {
398  case SQL3_BOOLEAN:
399  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
400  ECPGt_bool,&(BOOLVAR),(long)1,(long)1,sizeof(bool), ECPGd_EODT);
401 
402 #line 163 "dyntest.pgc"
403 
404 if (sqlca.sqlcode < 0) error ( );}
405 #line 163 "dyntest.pgc"
406 
407  printf ("%s\n", BOOLVAR ? "true" : "false");
408  break;
409  case SQL3_INTEGER:
410  case SQL3_SMALLINT:
411  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
412  ECPGt_int,&(INTVAR),(long)1,(long)1,sizeof(int), ECPGd_EODT);
413 
414 #line 168 "dyntest.pgc"
415 
416 if (sqlca.sqlcode < 0) error ( );}
417 #line 168 "dyntest.pgc"
418 
419  printf ("%d\n", INTVAR);
420  break;
422  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
423  ECPGt_double,&(DOUBLEVAR),(long)1,(long)1,sizeof(double), ECPGd_EODT);
424 
425 #line 172 "dyntest.pgc"
426 
427 if (sqlca.sqlcode < 0) error ( );}
428 #line 172 "dyntest.pgc"
429 
430  printf ("%.*f\n", PRECISION, DOUBLEVAR);
431  break;
433  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
434  ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_di_code,
435  ECPGt_int,&(DATETIME_INTERVAL_CODE),(long)1,(long)1,sizeof(int), ECPGd_EODT);
436 
437 #line 178 "dyntest.pgc"
438 
439 if (sqlca.sqlcode < 0) error ( );}
440 #line 178 "dyntest.pgc"
441 
442  printf ("%d \"%s\"\n", DATETIME_INTERVAL_CODE, STRINGVAR);
443  break;
444  case SQL3_CHARACTER:
446  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
447  ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
448 
449 #line 183 "dyntest.pgc"
450 
451 if (sqlca.sqlcode < 0) error ( );}
452 #line 183 "dyntest.pgc"
453 
454  printf ("\"%s\"\n", STRINGVAR);
455  break;
456  default:
457  { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
458  ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
459 
460 #line 187 "dyntest.pgc"
461 
462 if (sqlca.sqlcode < 0) error ( );}
463 #line 187 "dyntest.pgc"
464 
465  printf ("<\"%s\">\n", STRINGVAR);
466  break;
467  }
468  }
469  }
470 
471  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
472 #line 194 "dyntest.pgc"
473 
474 if (sqlca.sqlcode < 0) error ( );}
475 #line 194 "dyntest.pgc"
476 
477 
478  ECPGdeallocate_desc(__LINE__, "MYDESC");
479 #line 196 "dyntest.pgc"
480 
481 if (sqlca.sqlcode < 0) error ( );
482 #line 196 "dyntest.pgc"
483 
484 
485  return 0;
486  }
#define COUNT
Definition: sha1.c:58
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:759
static void error(void)
Definition: sql-dyntest.c:147
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
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:161
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
#define sqlca
Definition: sql-dyntest.c:124
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition: descriptor.c:91
#define ECPGdebug(X, Y)
Definition: sql-dyntest.c:7
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:712
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition: prepare.c:306