PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
compat_informix-test_informix.c
Go to the documentation of this file.
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 ;
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),
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  while (1)
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 
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 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
void * ECPGget_var(int number)
Definition: misc.c:568
#define sqlca
Definition: sqlca.h:59
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:2030
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:524
int risnull(int t, char *ptr)
Definition: informix.c:1050
int main(void)
#define ECPGdebug(X, Y)
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
static void dosqlprint(void)
char * c
#define CDECIMALTYPE
Definition: sqltypes.h:12
static void openit(void)
int deccvint(int in, decimal *np)
Definition: informix.c:268
int dectoint(decimal *np, int *ip)
Definition: informix.c:453
void ECPG_informix_reset_sqlca(void)
Definition: informix.c:1032
#define NULL
Definition: c.h:229
int rsetnull(int t, char *ptr)
Definition: informix.c:1043
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
int i
int decadd(decimal *arg1, decimal *arg2, decimal *sum)
Definition: informix.c:151