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

◆ ECPGdebug

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

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

◆ PGDLLIMPORT

#define PGDLLIMPORT

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

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

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

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

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

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 36 of file sql-array.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 106 of file sql-array.c.

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[28];
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;
172 n[j] = *value;
173 }
174
175 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
176#line 53 "array.pgc"
177
178if (sqlca.sqlcode < 0) sqlprint();}
179#line 53 "array.pgc"
180
181
182 { ECPGsetcommit(__LINE__, "on", NULL);
183#line 55 "array.pgc"
184
185if (sqlca.sqlcode < 0) sqlprint();}
186#line 55 "array.pgc"
187
188
189 { ECPGtrans(__LINE__, NULL, "begin work");
190#line 57 "array.pgc"
191
192if (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
199if (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
214if (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
233if (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
254if (sqlca.sqlcode < 0) sqlprint();}
255#line 65 "array.pgc"
256
257
258 { ECPGtrans(__LINE__, NULL, "commit");
259#line 67 "array.pgc"
260
261if (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
274if (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
285if (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
309if (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
325if (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
334if (sqlca.sqlcode < 0) sqlprint();}
335#line 102 "array.pgc"
336
337
338 { ECPGtrans(__LINE__, NULL, "commit");
339#line 104 "array.pgc"
340
341if (sqlca.sqlcode < 0) sqlprint();}
342#line 104 "array.pgc"
343
344
345 { ECPGdisconnect(__LINE__, "CURRENT");
346#line 106 "array.pgc"
347
348if (sqlca.sqlcode < 0) sqlprint();}
349#line 106 "array.pgc"
350
351
352 free(t);
353
354 return 0;
355}
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:153
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
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ ECPGt_timestamp
Definition: ecpgtype.h:54
@ 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_date
Definition: ecpgtype.h:53
@ ECPGt_interval
Definition: ecpgtype.h:55
@ ECPGt_char
Definition: ecpgtype.h:43
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
const char * str
#define free(a)
Definition: header.h:65
static struct @162 value
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
int a
Definition: isn.c:68
int j
Definition: isn.c:73
int i
Definition: isn.c:72
char * PGTYPESdate_to_asc(date dDate)
Definition: datetime.c:101
long date
Definition: pgtypes_date.h:9
date PGTYPESdate_from_asc(char *str, char **endptr)
Definition: datetime.c:47
interval * PGTYPESinterval_new(void)
Definition: interval.c:987
interval * PGTYPESinterval_from_asc(char *str, char **endptr)
Definition: interval.c:1003
char * PGTYPESinterval_to_asc(interval *span)
Definition: interval.c:1062
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:42
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
Definition: numeric.c:343
int PGTYPESnumeric_from_int(signed int int_val, numeric *var)
Definition: numeric.c:1309
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
Definition: timestamp.c:202
int64 timestamp
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
Definition: timestamp.c:268
#define sprintf
Definition: port.h:241
#define printf(...)
Definition: port.h:245
#define sqlca
Definition: sql-array.c:83
#define ECPGdebug(X, Y)
Definition: sql-array.c:7
Definition: c.h:644
#define setlocale(a, b)
Definition: win32_port.h:475

References a, 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, j, malloc, 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(), printf, setlocale, sprintf, sqlca, sqlprint(), str, and value.