PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sql-array.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <locale.h>
#include <string.h>
#include <stdlib.h>
#include <pgtypes_date.h>
#include <pgtypes_interval.h>
#include <pgtypes_numeric.h>
#include <pgtypes_timestamp.h>
Include dependency graph for sql-array.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-array.c.

Referenced by main().

#define PGDLLIMPORT

Definition at line 32 of file sql-array.c.

#define POSTGRES_SQLCA_H

Definition at line 26 of file sql-array.c.

#define sqlca   (*ECPGget_sqlca())

Definition at line 83 of file sql-array.c.

Referenced by main().

#define SQLERRMC_LEN   150

Definition at line 36 of file sql-array.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:45
Definition: sqlca.h:19
#define NULL
Definition: c.h:226
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:30
static struct sqlca_t sqlca
Definition: misc.c:63
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:25
int main ( void  )

Definition at line 106 of file sql-array.c.

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_char, ECPGt_date, ECPGt_double, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_interval, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_timestamp, ECPGtrans(), free, i, malloc, NULL, PGTYPESdate_from_asc(), PGTYPESdate_to_asc(), PGTYPESinterval_from_asc(), PGTYPESinterval_new(), PGTYPESinterval_to_asc(), PGTYPESnumeric_from_int(), PGTYPESnumeric_new(), PGTYPESnumeric_to_asc(), PGTYPEStimestamp_from_asc(), PGTYPEStimestamp_to_asc(), sqlca, sqlprint(), and value.

107 {
108 /* exec sql begin declare section */
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 #line 19 "array.pgc"
121  int i = 1 , j ;
122 
123 #line 20 "array.pgc"
124  int * did = & i ;
125 
126 #line 21 "array.pgc"
127  short a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
128 
129 #line 22 "array.pgc"
130  timestamp ts [ 10 ] ;
131 
132 #line 23 "array.pgc"
133  date d [ 10 ] ;
134 
135 #line 24 "array.pgc"
136  interval in [ 10 ] ;
137 
138 #line 25 "array.pgc"
139  numeric n [ 10 ] ;
140 
141 #line 26 "array.pgc"
142  char text [ 25 ] = "klmnopqrst" ;
143 
144 #line 27 "array.pgc"
145  char * t = ( char * ) malloc ( 11 ) ;
146 
147 #line 28 "array.pgc"
148  double f ;
149 /* exec sql end declare section */
150 #line 29 "array.pgc"
151 
152 
153  strcpy(t, "0123456789");
154  setlocale(LC_ALL, "C");
155 
156  ECPGdebug(1, stderr);
157 
158  for (j = 0; j < 10; j++) {
159  char str[20];
160  numeric *value;
161  interval *inter;
162 
163  sprintf(str, "2000-1-1 0%d:00:00", j);
164  ts[j] = PGTYPEStimestamp_from_asc(str, NULL);
165  sprintf(str, "2000-1-1%d\n", j);
166  d[j] = PGTYPESdate_from_asc(str, NULL);
167  sprintf(str, "%d hours", j+10);
168  inter = PGTYPESinterval_from_asc(str, NULL);
169  in[j] = *inter;
170  value = PGTYPESnumeric_new();
171  PGTYPESnumeric_from_int(j, value);
172  n[j] = *value;
173  }
174 
175  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
176 #line 53 "array.pgc"
177 
178 if (sqlca.sqlcode < 0) sqlprint();}
179 #line 53 "array.pgc"
180 
181 
182  { ECPGsetcommit(__LINE__, "on", NULL);
183 #line 55 "array.pgc"
184 
185 if (sqlca.sqlcode < 0) sqlprint();}
186 #line 55 "array.pgc"
187 
188 
189  { ECPGtrans(__LINE__, NULL, "begin work");
190 #line 57 "array.pgc"
191 
192 if (sqlca.sqlcode < 0) sqlprint();}
193 #line 57 "array.pgc"
194 
195 
196  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) , ts timestamp [ 10 ] , n numeric [ 10 ] , d date [ 10 ] , inter interval [ 10 ] )", ECPGt_EOIT, ECPGt_EORT);
197 #line 59 "array.pgc"
198 
199 if (sqlca.sqlcode < 0) sqlprint();}
200 #line 59 "array.pgc"
201 
202 
203  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , $1 , $2 , $3 , $4 )",
204  ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
205  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
206  ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
207  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
208  ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
209  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
210  ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
211  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
212 #line 61 "array.pgc"
213 
214 if (sqlca.sqlcode < 0) sqlprint();}
215 #line 61 "array.pgc"
216 
217 
218  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 140787.0 , 2 , $1 , $2 , $3 , $4 , $5 , $6 )",
219  ECPGt_short,(a),(long)1,(long)10,sizeof(short),
220  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
221  ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
222  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
223  ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
224  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
225  ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
226  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
227  ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
228  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
229  ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
230  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
231 #line 63 "array.pgc"
232 
233 if (sqlca.sqlcode < 0) sqlprint();}
234 #line 63 "array.pgc"
235 
236 
237  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 14.07 , $1 , $2 , $3 , $4 , $5 , $6 , $7 )",
238  ECPGt_int,&(did),(long)1,(long)0,sizeof(int),
239  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
240  ECPGt_short,(a),(long)1,(long)10,sizeof(short),
241  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
242  ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char),
243  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
244  ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
245  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
246  ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
247  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
248  ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
249  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
250  ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
251  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
252 #line 65 "array.pgc"
253 
254 if (sqlca.sqlcode < 0) sqlprint();}
255 #line 65 "array.pgc"
256 
257 
258  { ECPGtrans(__LINE__, NULL, "commit");
259 #line 67 "array.pgc"
260 
261 if (sqlca.sqlcode < 0) sqlprint();}
262 #line 67 "array.pgc"
263 
264 
265  for (j = 0; j < 10; j++) {
266  ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL);
267  d[j] = PGTYPESdate_from_asc("1900-01-01", NULL);
268  in[j] = *PGTYPESinterval_new();
269  n[j] = *PGTYPESnumeric_new();
270  }
271  { ECPGtrans(__LINE__, NULL, "begin work");
272 #line 75 "array.pgc"
273 
274 if (sqlca.sqlcode < 0) sqlprint();}
275 #line 75 "array.pgc"
276 
277 
278  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT,
279  ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
280  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
281  ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
282  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
283 #line 80 "array.pgc"
284 
285 if (sqlca.sqlcode < 0) sqlprint();}
286 #line 80 "array.pgc"
287 
288 
289  printf("Found f=%f text=%10.10s\n", f, text);
290 
291  f=140787;
292  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text , ts , n , d , inter from test where f = $1 ",
293  ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
294  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
295  ECPGt_short,(a),(long)1,(long)10,sizeof(short),
296  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
297  ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char),
298  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
299  ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp),
300  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
301  ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric),
302  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
303  ECPGt_date,&(d),(long)1,(long)10,sizeof(date),
304  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
305  ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval),
306  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
307 #line 88 "array.pgc"
308 
309 if (sqlca.sqlcode < 0) sqlprint();}
310 #line 88 "array.pgc"
311 
312 
313  for (i = 0; i < 10; i++)
314  printf("Found a[%d] = %d ts[%d] = %s n[%d] = %s d[%d] = %s in[%d] = %s\n", i, a[i], i, PGTYPEStimestamp_to_asc(ts[i]), i, PGTYPESnumeric_to_asc(&(n[i]), -1), i, PGTYPESdate_to_asc(d[i]), i, PGTYPESinterval_to_asc(&(in[i])));
315 
316  printf("Found text=%10.10s\n", t);
317 
318  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a from test where f = $1 ",
319  ECPGt_double,&(f),(long)1,(long)1,sizeof(double),
320  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
321  ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
322  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
323 #line 98 "array.pgc"
324 
325 if (sqlca.sqlcode < 0) sqlprint();}
326 #line 98 "array.pgc"
327 
328 
329  printf("Found text=%s\n", text);
330 
331  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
332 #line 102 "array.pgc"
333 
334 if (sqlca.sqlcode < 0) sqlprint();}
335 #line 102 "array.pgc"
336 
337 
338  { ECPGtrans(__LINE__, NULL, "commit");
339 #line 104 "array.pgc"
340 
341 if (sqlca.sqlcode < 0) sqlprint();}
342 #line 104 "array.pgc"
343 
344 
345  { ECPGdisconnect(__LINE__, "CURRENT");
346 #line 106 "array.pgc"
347 
348 if (sqlca.sqlcode < 0) sqlprint();}
349 #line 106 "array.pgc"
350 
351 
352  free(t);
353 
354  return (0);
355 }
date PGTYPESdate_from_asc(char *, char **)
Definition: datetime.c:53
static struct @76 value
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
#define sqlca
Definition: sql-array.c:83
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:2031
long date
Definition: pgtypes_date.h:8
char * PGTYPESdate_to_asc(date)
Definition: datetime.c:107
#define malloc(a)
Definition: header.h:45
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:127
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
interval * PGTYPESinterval_from_asc(char *, char **)
Definition: interval.c:1075
#define ECPGdebug(X, Y)
Definition: sql-array.c:7
int PGTYPESnumeric_from_int(signed int, numeric *)
Definition: numeric.c:1396
char * PGTYPESnumeric_to_asc(numeric *, int)
Definition: numeric.c:428
void sqlprint(void)
Definition: error.c:336
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
char * PGTYPEStimestamp_to_asc(timestamp)
Definition: timestamp.c:356
double timestamp
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
char * PGTYPESinterval_to_asc(interval *)
Definition: interval.c:1134
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:165
int i
Definition: c.h:434
interval * PGTYPESinterval_new(void)
Definition: interval.c:1059
timestamp PGTYPEStimestamp_from_asc(char *, char **)
Definition: timestamp.c:281