PostgreSQL Source Code  git master
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

◆ _ECPG_SQL3TYPES_H

#define _ECPG_SQL3TYPES_H

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

◆ ECPGdebug

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

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

◆ PGDLLIMPORT

#define PGDLLIMPORT

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

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

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

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

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

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

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

Enumeration Type Documentation

◆ anonymous enum

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.

26 {
27  SQL3_CHARACTER = 1,
32  SQL3_FLOAT,
33  SQL3_REAL,
36  SQL3_INTERVAL, /* 10 */
39  SQL3_BIT,
43  /* the rest is xLOB stuff */
44 };
@ SQL3_DATE_TIME_TIMESTAMP
Definition: sql-dyntest.c:35
@ SQL3_FLOAT
Definition: sql-dyntest.c:32
@ SQL3_INTEGER
Definition: sql-dyntest.c:30
@ SQL3_BIT_VARYING
Definition: sql-dyntest.c:40
@ SQL3_abstract
Definition: sql-dyntest.c:42
@ SQL3_BOOLEAN
Definition: sql-dyntest.c:41
@ SQL3_CHARACTER_VARYING
Definition: sql-dyntest.c:37
@ SQL3_BIT
Definition: sql-dyntest.c:39
@ SQL3_SMALLINT
Definition: sql-dyntest.c:31
@ SQL3_INTERVAL
Definition: sql-dyntest.c:36
@ SQL3_DOUBLE_PRECISION
Definition: sql-dyntest.c:34
@ SQL3_NUMERIC
Definition: sql-dyntest.c:28
@ SQL3_ENUMERATED
Definition: sql-dyntest.c:38
@ SQL3_DECIMAL
Definition: sql-dyntest.c:29
@ SQL3_CHARACTER
Definition: sql-dyntest.c:27
@ SQL3_REAL
Definition: sql-dyntest.c:33

◆ anonymous enum

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.

49 {
50  SQL3_DDT_DATE = 1,
55 
56  SQL3_DDT_ILLEGAL /* not a datetime data type (not part of
57  * standard) */
58 };
@ SQL3_DDT_TIME_WITH_TIME_ZONE
Definition: sql-dyntest.c:53
@ SQL3_DDT_DATE
Definition: sql-dyntest.c:50
@ SQL3_DDT_TIMESTAMP
Definition: sql-dyntest.c:52
@ SQL3_DDT_ILLEGAL
Definition: sql-dyntest.c:56
@ SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE
Definition: sql-dyntest.c:54
@ SQL3_DDT_TIME
Definition: sql-dyntest.c:51

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_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

◆ error()

◆ main()

int main ( void  )

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

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  }
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
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition: descriptor.c:84
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_char_variable
Definition: ecpgtype.h:60
@ 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_bool
Definition: ecpgtype.h:46
@ ECPGt_descriptor
Definition: ecpgtype.h:59
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGd_scale
Definition: ecpgtype.h:86
@ ECPGd_precision
Definition: ecpgtype.h:83
@ ECPGd_length
Definition: ecpgtype.h:79
@ ECPGd_type
Definition: ecpgtype.h:87
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_di_code
Definition: ecpgtype.h:75
@ ECPGd_name
Definition: ecpgtype.h:80
@ ECPGd_EODT
Definition: ecpgtype.h:88
@ ECPGd_octet
Definition: ecpgtype.h:82
@ ECPGd_ret_octet
Definition: ecpgtype.h:85
@ ECPGd_data
Definition: ecpgtype.h:74
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:2277
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition: prepare.c:368
#define COUNT
Definition: sha1.c:76
static void error(void)
Definition: sql-dyntest.c:147
#define ECPGdebug(X, Y)
Definition: sql-dyntest.c:7

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(), printf, 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.