PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
compat_informix-test_informix.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <ecpg_informix.h>
#include "sqltypes.h"
#include <stdlib.h>
Include dependency graph for compat_informix-test_informix.c:

Go to the source code of this file.

Macros

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

Functions

static void openit (void)
 
static void dosqlprint (void)
 
int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

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

Definition at line 9 of file compat_informix-test_informix.c.

Function Documentation

◆ dosqlprint()

static void dosqlprint ( void  )
static

Definition at line 28 of file compat_informix-test_informix.c.

28 {
29 printf("doSQLprint: Error: %s\n", sqlca.sqlerrm.sqlerrmc);
30}
#define printf(...)
Definition: port.h:244
#define sqlca
Definition: sqlca.h:59

References printf, and sqlca.

Referenced by main(), and openit().

◆ main()

int main ( void  )

Definition at line 32 of file compat_informix-test_informix.c.

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
61if (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
69if (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
80if (sqlca.sqlcode < 0) dosqlprint ( );}
81#line 28 "test_informix.pgc"
82
83 { ECPGtrans(__LINE__, NULL, "commit");
84#line 29 "test_informix.pgc"
85
86if (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
94if (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
101if (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
110if (sqlca.sqlcode < 0) dosqlprint ( );}
111#line 36 "test_informix.pgc"
112
113 { ECPGtrans(__LINE__, NULL, "commit");
114#line 37 "test_informix.pgc"
115
116if (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
124if (sqlca.sqlcode < 0) dosqlprint ( );}
125#line 40 "test_informix.pgc"
126
127 { ECPGtrans(__LINE__, NULL, "rollback");
128#line 41 "test_informix.pgc"
129
130if (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
138if (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
145if (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
154if (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
175if (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
199if (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
207if (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
215if (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
223if (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
229if (sqlca.sqlcode < 0) dosqlprint ( );}
230#line 84 "test_informix.pgc"
231
232 { ECPGtrans(__LINE__, NULL, "commit");
233#line 85 "test_informix.pgc"
234
235if (sqlca.sqlcode < 0) dosqlprint ( );}
236#line 85 "test_informix.pgc"
237
238
239 { ECPGdisconnect(__LINE__, "CURRENT");
240#line 87 "test_informix.pgc"
241
242if (sqlca.sqlcode < 0) dosqlprint ( );}
243#line 87 "test_informix.pgc"
244
245
246 return 0;
247}
static void dosqlprint(void)
static void openit(void)
#define ECPGdebug(X, Y)
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_decimal
Definition: ecpgtype.h:51
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_string
Definition: ecpgtype.h:65
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 decadd(decimal *arg1, decimal *arg2, decimal *sum)
Definition: informix.c:151
int deccvint(int in, decimal *np)
Definition: informix.c:268
int dectoint(decimal *np, int *ip)
Definition: informix.c:453
int risnull(int t, const char *ptr)
Definition: informix.c:1049
int rsetnull(int t, char *ptr)
Definition: informix.c:1042
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:538
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
exit(1)
char * c
#define CDECIMALTYPE
Definition: sqltypes.h:12

References a, CDECIMALTYPE, decadd(), deccvint(), dectoint(), dosqlprint(), ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGset_var(), ECPGst_normal, ECPGt_decimal, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGt_string, ECPGtrans(), exit(), i, j, openit(), printf, risnull(), rsetnull(), and sqlca.

◆ openit()

static void openit ( void  )
static

Definition at line 249 of file compat_informix-test_informix.c.

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
256if (sqlca.sqlcode < 0) dosqlprint ( );}
257#line 94 "test_informix.pgc"
258
259}
void * ECPGget_var(int number)
Definition: misc.c:593

References dosqlprint(), ECPGdo(), ECPGget_var(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, and sqlca.

Referenced by main().