PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sql-sqljson.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
Include dependency graph for sql-sqljson.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 ()
 

Macro Definition Documentation

◆ ECPGdebug

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

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

◆ PGDLLIMPORT

#define PGDLLIMPORT

Definition at line 21 of file sql-sqljson.c.

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

Definition at line 15 of file sql-sqljson.c.

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

Definition at line 72 of file sql-sqljson.c.

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 25 of file sql-sqljson.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 99 of file sql-sqljson.c.

100{
101/* exec sql begin declare section */
102
103
104
105#line 12 "sqljson.pgc"
106 char json [ 1024 ] ;
107
108#line 13 "sqljson.pgc"
109 bool is_json [ 8 ] ;
110/* exec sql end declare section */
111#line 14 "sqljson.pgc"
112
113
114 ECPGdebug (1, stderr);
115
116 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
117#line 18 "sqljson.pgc"
118
119if (sqlca.sqlcode < 0) sqlprint();}
120#line 18 "sqljson.pgc"
121
122 { ECPGsetcommit(__LINE__, "on", NULL);
123#line 19 "sqljson.pgc"
124
125if (sqlca.sqlcode < 0) sqlprint();}
126#line 19 "sqljson.pgc"
127
128
129 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( returning text )", ECPGt_EOIT,
130 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
131 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
132#line 21 "sqljson.pgc"
133
134if (sqlca.sqlcode < 0) sqlprint();}
135#line 21 "sqljson.pgc"
136
137 printf("Found json=%s\n", json);
138
139 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( returning text format json )", ECPGt_EOIT,
140 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
141 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
142#line 24 "sqljson.pgc"
143
144if (sqlca.sqlcode < 0) sqlprint();}
145#line 24 "sqljson.pgc"
146
147 printf("Found json=%s\n", json);
148
149 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_array ( returning jsonb )", ECPGt_EOIT,
150 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
151 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
152#line 27 "sqljson.pgc"
153
154if (sqlca.sqlcode < 0) sqlprint();}
155#line 27 "sqljson.pgc"
156
157 printf("Found json=%s\n", json);
158
159 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_array ( returning jsonb format json )", ECPGt_EOIT,
160 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
161 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
162#line 30 "sqljson.pgc"
163
164if (sqlca.sqlcode < 0) sqlprint();}
165#line 30 "sqljson.pgc"
166
167 printf("Found json=%s\n", json);
168
169 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( 1 : 1 , '1' : null with unique )", ECPGt_EOIT,
170 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
171 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
172#line 33 "sqljson.pgc"
173
174if (sqlca.sqlcode < 0) sqlprint();}
175#line 33 "sqljson.pgc"
176
177 // error
178
179 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( 1 : 1 , '2' : null , 1 : '2' absent on null without unique keys )", ECPGt_EOIT,
180 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
181 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
182#line 36 "sqljson.pgc"
183
184if (sqlca.sqlcode < 0) sqlprint();}
185#line 36 "sqljson.pgc"
186
187 printf("Found json=%s\n", json);
188
189 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( 1 : 1 , '2' : null absent on null without unique returning jsonb )", ECPGt_EOIT,
190 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
191 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
192#line 39 "sqljson.pgc"
193
194if (sqlca.sqlcode < 0) sqlprint();}
195#line 39 "sqljson.pgc"
196
197 printf("Found json=%s\n", json);
198
199 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( null )", ECPGt_EOIT,
200 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
201 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
202#line 42 "sqljson.pgc"
203
204if (sqlca.sqlcode < 0) sqlprint();}
205#line 42 "sqljson.pgc"
206
207 printf("Found json=%s\n", json);
208
209 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( '{ \"a\" : 1 } ' format json )", ECPGt_EOIT,
210 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
211 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
212#line 45 "sqljson.pgc"
213
214if (sqlca.sqlcode < 0) sqlprint();}
215#line 45 "sqljson.pgc"
216
217 printf("Found json=%s\n", json);
218
219 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( '{ \"a\" : 1 } ' format json encoding UTF8 )", ECPGt_EOIT,
220 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
221 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
222#line 48 "sqljson.pgc"
223
224if (sqlca.sqlcode < 0) sqlprint();}
225#line 48 "sqljson.pgc"
226
227 // error
228
229 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( ' 1 ' :: jsonb )", ECPGt_EOIT,
230 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
231 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
232#line 51 "sqljson.pgc"
233
234if (sqlca.sqlcode < 0) sqlprint();}
235#line 51 "sqljson.pgc"
236
237 printf("Found json=%s\n", json);
238
239 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( ' 1 ' :: json with unique keys ) into json", ECPGt_EOIT, ECPGt_EORT);
240#line 54 "sqljson.pgc"
241
242if (sqlca.sqlcode < 0) sqlprint();}
243#line 54 "sqljson.pgc"
244
245 // error
246
247 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( '{\"a\": 1, \"a\": 2}' )", ECPGt_EOIT,
248 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
249 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
250#line 57 "sqljson.pgc"
251
252if (sqlca.sqlcode < 0) sqlprint();}
253#line 57 "sqljson.pgc"
254
255 printf("Found json=%s\n", json);
256
257 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( '{\"a\": 1, \"a\": 2}' with unique keys )", ECPGt_EOIT,
258 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
259 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
260#line 60 "sqljson.pgc"
261
262if (sqlca.sqlcode < 0) sqlprint();}
263#line 60 "sqljson.pgc"
264
265 // error
266
267 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( null )", ECPGt_EOIT,
268 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
269 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
270#line 63 "sqljson.pgc"
271
272if (sqlca.sqlcode < 0) sqlprint();}
273#line 63 "sqljson.pgc"
274
275 printf("Found json=%s\n", json);
276
277 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( null :: int )", ECPGt_EOIT,
278 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
279 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
280#line 66 "sqljson.pgc"
281
282if (sqlca.sqlcode < 0) sqlprint();}
283#line 66 "sqljson.pgc"
284
285 printf("Found json=%s\n", json);
286
287 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( 123.45 )", ECPGt_EOIT,
288 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
289 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
290#line 69 "sqljson.pgc"
291
292if (sqlca.sqlcode < 0) sqlprint();}
293#line 69 "sqljson.pgc"
294
295 printf("Found json=%s\n", json);
296
297 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( true )", ECPGt_EOIT,
298 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
299 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
300#line 72 "sqljson.pgc"
301
302if (sqlca.sqlcode < 0) sqlprint();}
303#line 72 "sqljson.pgc"
304
305 printf("Found json=%s\n", json);
306
307 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( ' 123.45' )", ECPGt_EOIT,
308 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
309 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
310#line 75 "sqljson.pgc"
311
312if (sqlca.sqlcode < 0) sqlprint();}
313#line 75 "sqljson.pgc"
314
315 printf("Found json=%s\n", json);
316
317 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( '2020-06-07 01:02:03' :: timestamp )", ECPGt_EOIT,
318 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
319 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
320#line 78 "sqljson.pgc"
321
322if (sqlca.sqlcode < 0) sqlprint();}
323#line 78 "sqljson.pgc"
324
325 printf("Found json=%s\n", json);
326
327 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_scalar ( '{}' :: jsonb )", ECPGt_EOIT,
328 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
329 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
330#line 81 "sqljson.pgc"
331
332if (sqlca.sqlcode < 0) sqlprint();}
333#line 81 "sqljson.pgc"
334
335 printf("Found json=%s\n", json);
336
337 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_serialize ( null )", ECPGt_EOIT,
338 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
339 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
340#line 84 "sqljson.pgc"
341
342if (sqlca.sqlcode < 0) sqlprint();}
343#line 84 "sqljson.pgc"
344
345 printf("Found json=%s\n", json);
346
347 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_serialize ( json ( '{ \"a\" : 1 } ' ) )", ECPGt_EOIT,
348 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
349 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
350#line 87 "sqljson.pgc"
351
352if (sqlca.sqlcode < 0) sqlprint();}
353#line 87 "sqljson.pgc"
354
355 printf("Found json=%s\n", json);
356
357 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_serialize ( '{ \"a\" : 1 } ' )", ECPGt_EOIT,
358 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
359 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
360#line 90 "sqljson.pgc"
361
362if (sqlca.sqlcode < 0) sqlprint();}
363#line 90 "sqljson.pgc"
364
365 printf("Found json=%s\n", json);
366
367 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_serialize ( '1' format json )", ECPGt_EOIT,
368 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
369 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
370#line 93 "sqljson.pgc"
371
372if (sqlca.sqlcode < 0) sqlprint();}
373#line 93 "sqljson.pgc"
374
375 printf("Found json=%s\n", json);
376
377 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_serialize ( '{ \"a\" : 1 } ' returning varchar )", ECPGt_EOIT,
378 ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
379 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
380#line 96 "sqljson.pgc"
381
382if (sqlca.sqlcode < 0) sqlprint();}
383#line 96 "sqljson.pgc"
384
385 printf("Found json=%s\n", json);
386
387 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_serialize ( '{ \"a\" : 1 } ' returning jsonb )", ECPGt_EOIT, ECPGt_EORT);
388#line 99 "sqljson.pgc"
389
390if (sqlca.sqlcode < 0) sqlprint();}
391#line 99 "sqljson.pgc"
392
393 // error
394
395 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "with val ( js ) as ( values ( '{ \"a\": 1, \"b\": [{ \"a\": 1, \"b\": 0, \"a\": 2 }] }' ) ) select js is json \"IS JSON\" , js is not json \"IS NOT JSON\" , js is json value \"IS VALUE\" , js is json object \"IS OBJECT\" , js is json array \"IS ARRAY\" , js is json scalar \"IS SCALAR\" , js is json without unique keys \"WITHOUT UNIQUE\" , js is json with unique keys \"WITH UNIQUE\" from val", ECPGt_EOIT,
396 ECPGt_bool,&(is_json[0]),(long)1,(long)1,sizeof(bool),
397 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
398 ECPGt_bool,&(is_json[1]),(long)1,(long)1,sizeof(bool),
399 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
400 ECPGt_bool,&(is_json[2]),(long)1,(long)1,sizeof(bool),
401 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
402 ECPGt_bool,&(is_json[3]),(long)1,(long)1,sizeof(bool),
403 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
404 ECPGt_bool,&(is_json[4]),(long)1,(long)1,sizeof(bool),
405 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
406 ECPGt_bool,&(is_json[5]),(long)1,(long)1,sizeof(bool),
407 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
408 ECPGt_bool,&(is_json[6]),(long)1,(long)1,sizeof(bool),
409 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
410 ECPGt_bool,&(is_json[7]),(long)1,(long)1,sizeof(bool),
411 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
412#line 114 "sqljson.pgc"
413
414if (sqlca.sqlcode < 0) sqlprint();}
415#line 114 "sqljson.pgc"
416
417 for (int i = 0; i < sizeof(is_json); i++)
418 printf("Found is_json[%d]: %s\n", i, is_json[i] ? "true" : "false");
419
420 { ECPGdisconnect(__LINE__, "CURRENT");
421#line 118 "sqljson.pgc"
422
423if (sqlca.sqlcode < 0) sqlprint();}
424#line 118 "sqljson.pgc"
425
426
427 return 0;
428}
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_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_bool
Definition: ecpgtype.h:46
@ 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
int i
Definition: isn.c:72
#define printf(...)
Definition: port.h:244
#define sqlca
Definition: sql-sqljson.c:72
#define ECPGdebug(X, Y)
Definition: sql-sqljson.c:7

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_bool, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_NO_INDICATOR, i, printf, sqlca, and sqlprint().