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);
dosqlprint(void)28 static void dosqlprint(void) {
29 printf("doSQLprint: Error: %s\n", sqlca.sqlerrm.sqlerrmc);
30 }
31
main(void)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 ECPG_informix_reset_sqlca(); /* declare c cursor for select * from test where i <= $1 */
152 #line 49 "test_informix.pgc"
153
154 printf ("%ld\n", sqlca.sqlcode);
155 openit();
156
157 deccvint(0, &j);
158
159 for (loopcount = 0; loopcount < 100; loopcount++)
160 {
161 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT,
162 ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
163 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
164 ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal),
165 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
166 ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char),
167 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
168 #line 57 "test_informix.pgc"
169
170 if (sqlca.sqlcode < 0) dosqlprint ( );}
171 #line 57 "test_informix.pgc"
172
173 if (sqlca.sqlcode == 100) break;
174 else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
175
176 if (risnull(CDECIMALTYPE, (char *)&j))
177 printf("%d NULL\n", i);
178 else
179 {
180 int a;
181
182 dectoint(&j, &a);
183 printf("%d %d \"%s\"\n", i, a, c);
184 }
185 }
186
187 deccvint(7, &j);
188 deccvint(14, &m);
189 decadd(&j, &m, &n);
190 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "delete from test where i = $1 :: decimal",
191 ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal),
192 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
193 #line 75 "test_informix.pgc"
194
195 if (sqlca.sqlcode < 0) dosqlprint ( );}
196 #line 75 "test_informix.pgc"
197
198 printf("DELETE: %ld\n", sqlca.sqlcode);
199
200 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 14", ECPGt_EOIT, ECPGt_EORT);
201 #line 78 "test_informix.pgc"
202
203 if (sqlca.sqlcode < 0) dosqlprint ( );}
204 #line 78 "test_informix.pgc"
205
206 printf("Exists: %ld\n", sqlca.sqlcode);
207
208 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT);
209 #line 81 "test_informix.pgc"
210
211 if (sqlca.sqlcode < 0) dosqlprint ( );}
212 #line 81 "test_informix.pgc"
213
214 printf("Does not exist: %ld\n", sqlca.sqlcode);
215
216 { ECPGtrans(__LINE__, NULL, "commit");
217 #line 84 "test_informix.pgc"
218
219 if (sqlca.sqlcode < 0) dosqlprint ( );}
220 #line 84 "test_informix.pgc"
221
222 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
223 #line 85 "test_informix.pgc"
224
225 if (sqlca.sqlcode < 0) dosqlprint ( );}
226 #line 85 "test_informix.pgc"
227
228 { ECPGtrans(__LINE__, NULL, "commit");
229 #line 86 "test_informix.pgc"
230
231 if (sqlca.sqlcode < 0) dosqlprint ( );}
232 #line 86 "test_informix.pgc"
233
234
235 { ECPGdisconnect(__LINE__, "CURRENT");
236 #line 88 "test_informix.pgc"
237
238 if (sqlca.sqlcode < 0) dosqlprint ( );}
239 #line 88 "test_informix.pgc"
240
241
242 return 0;
243 }
244
openit(void)245 static void openit(void)
246 {
247 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare c cursor for select * from test where i <= $1 ",
248 ECPGt_int,&(*( int *)(ECPGget_var( 0))),(long)1,(long)1,sizeof(int),
249 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
250 #line 95 "test_informix.pgc"
251
252 if (sqlca.sqlcode < 0) dosqlprint ( );}
253 #line 95 "test_informix.pgc"
254
255 }
256