Debian Codegraph @

src/interfaces/ecpg/test/expected/compat_informix-test_informix.c

raw
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* Needed for informix compatibility */
7 #include <ecpg_informix.h>
8 /* End of automatic include section */
9 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
10
11 #line 1 "test_informix.pgc"
12 #include "sqltypes.h"
13 #include <stdlib.h>
14
15
16 #line 1 "regression.h"
17
18
19
20
21
22
23 #line 4 "test_informix.pgc"
24
25
26
27 static void openit(void);
28 static void dosqlprint(void) {
29 printf("doSQLprint: Error: %s\n", sqlca.sqlerrm.sqlerrmc);
30 }
31
32 int main(void)
33 {
34
35 #line 14 "test_informix.pgc"
36 int i = 14 , loopcount ;
37
38 #line 14 "test_informix.pgc"
39
40
41 #line 15 "test_informix.pgc"
42 decimal j , m , n ;
43
44 #line 15 "test_informix.pgc"
45
46
47 #line 16 "test_informix.pgc"
48 char c [ 10 ] ;
49
50 #line 16 "test_informix.pgc"
51
52
53 ECPGdebug(1, stderr);
54 /* exec sql whenever sqlerror do dosqlprint ( ) ; */
55 #line 19 "test_informix.pgc"
56
57
58 { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , NULL, 0);
59 #line 21 "test_informix.pgc"
60
61 if (sqlca.sqlcode < 0) dosqlprint ( );}
62 #line 21 "test_informix.pgc"
63
64 if (sqlca.sqlcode != 0) exit(1);
65
66 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table test ( i int primary key , j int , c text )", ECPGt_EOIT, ECPGt_EORT);
67 #line 24 "test_informix.pgc"
68
69 if (sqlca.sqlcode < 0) dosqlprint ( );}
70 #line 24 "test_informix.pgc"
71
72
73 /* this INSERT works */
74 rsetnull(CDECIMALTYPE, (char *)&j);
75 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , $1 , 'test ' )",
76 ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal),
77 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
78 #line 28 "test_informix.pgc"
79
80 if (sqlca.sqlcode < 0) dosqlprint ( );}
81 #line 28 "test_informix.pgc"
82
83 { ECPGtrans(__LINE__, NULL, "commit");
84 #line 29 "test_informix.pgc"
85
86 if (sqlca.sqlcode < 0) dosqlprint ( );}
87 #line 29 "test_informix.pgc"
88
89
90 /* this INSERT should fail because i is a unique column */
91 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , 12 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
92 #line 32 "test_informix.pgc"
93
94 if (sqlca.sqlcode < 0) dosqlprint ( );}
95 #line 32 "test_informix.pgc"
96
97 printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
98 if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
99 #line 34 "test_informix.pgc"
100
101 if (sqlca.sqlcode < 0) dosqlprint ( );}
102 #line 34 "test_informix.pgc"
103
104
105 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( $1 , 1 , 'a ' )",
106 ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
107 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
108 #line 36 "test_informix.pgc"
109
110 if (sqlca.sqlcode < 0) dosqlprint ( );}
111 #line 36 "test_informix.pgc"
112
113 { ECPGtrans(__LINE__, NULL, "commit");
114 #line 37 "test_informix.pgc"
115
116 if (sqlca.sqlcode < 0) dosqlprint ( );}
117 #line 37 "test_informix.pgc"
118
119
120 /* this will fail (more than one row in subquery) */
121 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test )", ECPGt_EOIT, ECPGt_EORT);
122 #line 40 "test_informix.pgc"
123
124 if (sqlca.sqlcode < 0) dosqlprint ( );}
125 #line 40 "test_informix.pgc"
126
127 { ECPGtrans(__LINE__, NULL, "rollback");
128 #line 41 "test_informix.pgc"
129
130 if (sqlca.sqlcode < 0) dosqlprint ( );}
131 #line 41 "test_informix.pgc"
132
133
134 /* this however should be ok */
135 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test order by i limit 1 )", ECPGt_EOIT, ECPGt_EORT);
136 #line 44 "test_informix.pgc"
137
138 if (sqlca.sqlcode < 0) dosqlprint ( );}
139 #line 44 "test_informix.pgc"
140
141 printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
142 if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
143 #line 46 "test_informix.pgc"
144
145 if (sqlca.sqlcode < 0) dosqlprint ( );}
146 #line 46 "test_informix.pgc"
147
148
149 sqlca.sqlcode = 100;
150 ECPGset_var( 0, &( i ), __LINE__);\
151 /* declare c cursor for select * from test where i <= $1 */
152 #line 49 "test_informix.pgc"
153
154 if (sqlca.sqlcode < 0) dosqlprint ( );
155 #line 49 "test_informix.pgc"
156
157 #line 49 "test_informix.pgc"
158
159 printf ("%ld\n", sqlca.sqlcode);
160 openit();
161
162 deccvint(0, &j);
163
164 for (loopcount = 0; loopcount < 100; loopcount++)
165 {
166 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT,
167 ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
168 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
169 ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal),
170 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
171 ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char),
172 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
173 #line 57 "test_informix.pgc"
174
175 if (sqlca.sqlcode < 0) dosqlprint ( );}
176 #line 57 "test_informix.pgc"
177
178 if (sqlca.sqlcode == 100) break;
179
180 if (risnull(CDECIMALTYPE, (char *)&j))
181 printf("%d NULL\n", i);
182 else
183 {
184 int a;
185
186 dectoint(&j, &a);
187 printf("%d %d \"%s\"\n", i, a, c);
188 }
189 }
190
191 deccvint(7, &j);
192 deccvint(14, &m);
193 decadd(&j, &m, &n);
194 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "delete from test where i = $1 :: decimal",
195 ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal),
196 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
197 #line 74 "test_informix.pgc"
198
199 if (sqlca.sqlcode < 0) dosqlprint ( );}
200 #line 74 "test_informix.pgc"
201
202 printf("DELETE: %ld\n", sqlca.sqlcode);
203
204 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 14", ECPGt_EOIT, ECPGt_EORT);
205 #line 77 "test_informix.pgc"
206
207 if (sqlca.sqlcode < 0) dosqlprint ( );}
208 #line 77 "test_informix.pgc"
209
210 printf("Exists: %ld\n", sqlca.sqlcode);
211
212 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT);
213 #line 80 "test_informix.pgc"
214
215 if (sqlca.sqlcode < 0) dosqlprint ( );}
216 #line 80 "test_informix.pgc"
217
218 printf("Does not exist: %ld\n", sqlca.sqlcode);
219
220 { ECPGtrans(__LINE__, NULL, "commit");
221 #line 83 "test_informix.pgc"
222
223 if (sqlca.sqlcode < 0) dosqlprint ( );}
224 #line 83 "test_informix.pgc"
225
226 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
227 #line 84 "test_informix.pgc"
228
229 if (sqlca.sqlcode < 0) dosqlprint ( );}
230 #line 84 "test_informix.pgc"
231
232 { ECPGtrans(__LINE__, NULL, "commit");
233 #line 85 "test_informix.pgc"
234
235 if (sqlca.sqlcode < 0) dosqlprint ( );}
236 #line 85 "test_informix.pgc"
237
238
239 { ECPGdisconnect(__LINE__, "CURRENT");
240 #line 87 "test_informix.pgc"
241
242 if (sqlca.sqlcode < 0) dosqlprint ( );}
243 #line 87 "test_informix.pgc"
244
245
246 return 0;
247 }
248
249 static void openit(void)
250 {
251 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare c cursor for select * from test where i <= $1 ",
252 ECPGt_int,&(*( int *)(ECPGget_var( 0))),(long)1,(long)1,sizeof(int),
253 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
254 #line 94 "test_informix.pgc"
255
256 if (sqlca.sqlcode < 0) dosqlprint ( );}
257 #line 94 "test_informix.pgc"
258
259 }