PostgreSQL Source Code git master
Loading...
Searching...
No Matches
sql-sqlpgq.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for sql-sqlpgq.c:

Go to the source code of this file.

Macros

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

Functions

int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

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

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

Function Documentation

◆ main()

int main ( void  )

Definition at line 30 of file sql-sqlpgq.c.

31{
32/* exec sql begin declare section */
33
34
35
36
37
38#line 13 "sqlpgq.pgc"
39 char command [ 512 ] ;
40
41#line 14 "sqlpgq.pgc"
42 char search_address [ 10 ] ;
43
44#line 15 "sqlpgq.pgc"
45 char cname [ 100 ] ;
46
47#line 16 "sqlpgq.pgc"
48 int reg ;
49/* exec sql end declare section */
50#line 17 "sqlpgq.pgc"
51
52
53 ECPGdebug(1, stderr);
54
55 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "main", 0);
56#line 21 "sqlpgq.pgc"
57
58if (sqlca.sqlcode < 0) sqlprint();}
59#line 21 "sqlpgq.pgc"
60
61
62 /* Create schema and tables for property graph testing */
63 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create schema graph_ecpg_tests", ECPGt_EOIT, ECPGt_EORT);
64#line 24 "sqlpgq.pgc"
65
66if (sqlca.sqlcode < 0) sqlprint();}
67#line 24 "sqlpgq.pgc"
68
69 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path = graph_ecpg_tests", ECPGt_EOIT, ECPGt_EORT);
70#line 25 "sqlpgq.pgc"
71
72if (sqlca.sqlcode < 0) sqlprint();}
73#line 25 "sqlpgq.pgc"
74
75
76 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table customers ( customer_id integer primary key , name varchar , address varchar )", ECPGt_EOIT, ECPGt_EORT);
77#line 31 "sqlpgq.pgc"
78
79if (sqlca.sqlcode < 0) sqlprint();}
80#line 31 "sqlpgq.pgc"
81
82
83 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table orders ( order_id integer primary key , register integer )", ECPGt_EOIT, ECPGt_EORT);
84#line 36 "sqlpgq.pgc"
85
86if (sqlca.sqlcode < 0) sqlprint();}
87#line 36 "sqlpgq.pgc"
88
89
90 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table customer_orders ( customer_orders_id integer primary key , customer_id integer references customers ( customer_id ) , order_id integer references orders ( order_id ) )", ECPGt_EOIT, ECPGt_EORT);
91#line 42 "sqlpgq.pgc"
92
93if (sqlca.sqlcode < 0) sqlprint();}
94#line 42 "sqlpgq.pgc"
95
96
97 /* Insert test data */
98 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customers values ( 1 , 'customer1' , 'US' ) , ( 2 , 'customer2' , 'CA' ) , ( 3 , 'customer3' , 'GL' )", ECPGt_EOIT, ECPGt_EORT);
99#line 45 "sqlpgq.pgc"
100
101if (sqlca.sqlcode < 0) sqlprint();}
102#line 45 "sqlpgq.pgc"
103
104 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into orders values ( 1 , 100 ) , ( 2 , 200 ) , ( 3 , 500 )", ECPGt_EOIT, ECPGt_EORT);
105#line 46 "sqlpgq.pgc"
106
107if (sqlca.sqlcode < 0) sqlprint();}
108#line 46 "sqlpgq.pgc"
109
110 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into customer_orders ( customer_orders_id , customer_id , order_id ) values ( 1 , 1 , 1 ) , ( 2 , 2 , 2 ) , ( 3 , 3 , 3 )", ECPGt_EOIT, ECPGt_EORT);
111#line 47 "sqlpgq.pgc"
112
113if (sqlca.sqlcode < 0) sqlprint();}
114#line 47 "sqlpgq.pgc"
115
116
117 /* Create property graph */
118 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create property graph shopgraph vertex tables ( customers , orders ) edge tables ( customer_orders key ( customer_orders_id ) source key ( customer_id ) references customers ( customer_id ) destination key ( order_id ) references orders ( order_id ) )", ECPGt_EOIT, ECPGt_EORT);
119#line 59 "sqlpgq.pgc"
120
121if (sqlca.sqlcode < 0) sqlprint();}
122#line 59 "sqlpgq.pgc"
123
124
125 { ECPGtrans(__LINE__, NULL, "commit");
126#line 61 "sqlpgq.pgc"
127
128if (sqlca.sqlcode < 0) sqlprint();}
129#line 61 "sqlpgq.pgc"
130
131
132 /* direct sql - US customers */
133 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from graph_table ( shopgraph match ( c is customers where c . address = 'US' ) - [ is customer_orders ] -> ( o is orders ) columns ( c . name , o . register ) )", ECPGt_EOIT,
134 ECPGt_char,(cname),(long)100,(long)1,(100)*sizeof(char),
135 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
136 ECPGt_int,&(reg),(long)1,(long)1,sizeof(int),
138#line 64 "sqlpgq.pgc"
139
140if (sqlca.sqlcode < 0) sqlprint();}
141#line 64 "sqlpgq.pgc"
142
143 printf("found %ld results (%s, %d)\n", sqlca.sqlerrd[2], cname, reg);
144
145 /* direct sql with C variable - GL customers */
146 strcpy(search_address, "GL");
147 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from graph_table ( shopgraph match ( c is customers where c . address = $1 ) - [ is customer_orders ] -> ( o is orders ) columns ( c . name , o . register ) )",
148 ECPGt_char,(search_address),(long)10,(long)1,(10)*sizeof(char),
150 ECPGt_char,(cname),(long)100,(long)1,(100)*sizeof(char),
151 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
152 ECPGt_int,&(reg),(long)1,(long)1,sizeof(int),
154#line 69 "sqlpgq.pgc"
155
156if (sqlca.sqlcode < 0) sqlprint();}
157#line 69 "sqlpgq.pgc"
158
159 printf("found %ld results (%s, %d)\n", sqlca.sqlerrd[2], cname, reg);
160
161 /* prepared statement - CA customers */
162 sprintf(command, "select * from graph_table (shopgraph match (c is customers where c.address = $1)-[is customer_orders]->(o is orders) columns (c.name, o.register))");
163 { ECPGprepare(__LINE__, NULL, 0, "graph_stmt", command);
164#line 74 "sqlpgq.pgc"
165
166if (sqlca.sqlcode < 0) sqlprint();}
167#line 74 "sqlpgq.pgc"
168
169 strcpy(search_address, "CA");
170 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "graph_stmt",
171 ECPGt_char,(search_address),(long)10,(long)1,(10)*sizeof(char),
173 ECPGt_char,(cname),(long)100,(long)1,(100)*sizeof(char),
174 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
175 ECPGt_int,&(reg),(long)1,(long)1,sizeof(int),
177#line 76 "sqlpgq.pgc"
178
179if (sqlca.sqlcode < 0) sqlprint();}
180#line 76 "sqlpgq.pgc"
181
182 printf("found %ld results (%s, %d)\n", sqlca.sqlerrd[2], cname, reg);
183 { ECPGdeallocate(__LINE__, 0, NULL, "graph_stmt");
184#line 78 "sqlpgq.pgc"
185
186if (sqlca.sqlcode < 0) sqlprint();}
187#line 78 "sqlpgq.pgc"
188
189
190 /* cursor test - all customers with orders */
191 /* declare graph_cursor cursor for select * from graph_table ( shopgraph match ( c is customers ) - [ is customer_orders ] -> ( o is orders ) columns ( c . name , o . register ) ) order by name */
192#line 81 "sqlpgq.pgc"
193
194 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare graph_cursor cursor for select * from graph_table ( shopgraph match ( c is customers ) - [ is customer_orders ] -> ( o is orders ) columns ( c . name , o . register ) ) order by name", ECPGt_EOIT, ECPGt_EORT);
195#line 82 "sqlpgq.pgc"
196
197if (sqlca.sqlcode < 0) sqlprint();}
198#line 82 "sqlpgq.pgc"
199
200 /* exec sql whenever not found break ; */
201#line 83 "sqlpgq.pgc"
202
203 while (1) {
204 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch graph_cursor", ECPGt_EOIT,
205 ECPGt_char,(cname),(long)100,(long)1,(100)*sizeof(char),
206 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
207 ECPGt_int,&(reg),(long)1,(long)1,sizeof(int),
209#line 85 "sqlpgq.pgc"
210
211if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
212#line 85 "sqlpgq.pgc"
213
214if (sqlca.sqlcode < 0) sqlprint();}
215#line 85 "sqlpgq.pgc"
216
217 printf("cursor result: %s, %d\n", cname, reg);
218 }
219 /* exec sql whenever not found continue ; */
220#line 88 "sqlpgq.pgc"
221
222 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close graph_cursor", ECPGt_EOIT, ECPGt_EORT);
223#line 89 "sqlpgq.pgc"
224
225if (sqlca.sqlcode < 0) sqlprint();}
226#line 89 "sqlpgq.pgc"
227
228
229 /* label disjunction syntax test */
230 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from graph_table ( shopgraph match ( c is customers | customers where c . address = 'US' ) columns ( c . name ) )", ECPGt_EOIT,
231 ECPGt_char,(cname),(long)100,(long)1,(100)*sizeof(char),
233#line 92 "sqlpgq.pgc"
234
235if (sqlca.sqlcode < 0) sqlprint();}
236#line 92 "sqlpgq.pgc"
237
238 printf("found %ld results (%s)\n", sqlca.sqlerrd[2], cname);
239
240 /* Clean up */
241 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop property graph shopgraph", ECPGt_EOIT, ECPGt_EORT);
242#line 96 "sqlpgq.pgc"
243
244if (sqlca.sqlcode < 0) sqlprint();}
245#line 96 "sqlpgq.pgc"
246
247 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table customer_orders", ECPGt_EOIT, ECPGt_EORT);
248#line 97 "sqlpgq.pgc"
249
250if (sqlca.sqlcode < 0) sqlprint();}
251#line 97 "sqlpgq.pgc"
252
253 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table orders", ECPGt_EOIT, ECPGt_EORT);
254#line 98 "sqlpgq.pgc"
255
256if (sqlca.sqlcode < 0) sqlprint();}
257#line 98 "sqlpgq.pgc"
258
259 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table customers", ECPGt_EOIT, ECPGt_EORT);
260#line 99 "sqlpgq.pgc"
261
262if (sqlca.sqlcode < 0) sqlprint();}
263#line 99 "sqlpgq.pgc"
264
265 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop schema graph_ecpg_tests", ECPGt_EOIT, ECPGt_EORT);
266#line 100 "sqlpgq.pgc"
267
268if (sqlca.sqlcode < 0) sqlprint();}
269#line 100 "sqlpgq.pgc"
270
271 { ECPGtrans(__LINE__, NULL, "commit");
272#line 101 "sqlpgq.pgc"
273
274if (sqlca.sqlcode < 0) sqlprint();}
275#line 101 "sqlpgq.pgc"
276
277 { ECPGdisconnect(__LINE__, "CURRENT");
278#line 102 "sqlpgq.pgc"
279
280if (sqlca.sqlcode < 0) sqlprint();}
281#line 102 "sqlpgq.pgc"
282
283
284 return 0;
285}
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition connect.c:693
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition connect.c:260
#define ECPG_NOT_FOUND
Definition ecpgerrno.h:10
@ ECPGst_normal
Definition ecpgtype.h:97
@ ECPGst_execute
Definition ecpgtype.h:98
@ ECPGt_EOIT
Definition ecpgtype.h:62
@ ECPGt_int
Definition ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition ecpgtype.h:64
@ ECPGt_EORT
Definition ecpgtype.h:63
@ 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:2292
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition misc.c:160
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition prepare.c:249
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition prepare.c:347
#define sprintf
Definition port.h:262
#define printf(...)
Definition port.h:266
static int fb(int x)
#define ECPGdebug(X, Y)
Definition sql-sqlpgq.c:7
#define sqlca
Definition sqlca.h:59

References ECPG_NOT_FOUND, ECPGconnect(), ECPGdeallocate(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGprepare(), ECPGst_execute, ECPGst_normal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), fb(), printf, sprintf, sqlca, and sqlprint().