]> granicus.if.org Git - postgresql/blob - src/interfaces/ecpg/test/expected/sql-array.c
pgindent run for 9.4
[postgresql] / src / interfaces / ecpg / test / expected / sql-array.c
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 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8
9 #line 1 "array.pgc"
10 #include <locale.h>
11 #include <string.h>
12 #include <stdlib.h>
13
14 /* exec sql whenever sqlerror  sqlprint ; */
15 #line 5 "array.pgc"
16
17
18
19 #line 1 "sqlca.h"
20 #ifndef POSTGRES_SQLCA_H
21 #define POSTGRES_SQLCA_H
22
23 #ifndef PGDLLIMPORT
24 #if  defined(WIN32) || defined(__CYGWIN__)
25 #define PGDLLIMPORT __declspec (dllimport)
26 #else
27 #define PGDLLIMPORT
28 #endif   /* __CYGWIN__ */
29 #endif   /* PGDLLIMPORT */
30
31 #define SQLERRMC_LEN    150
32
33 #ifdef __cplusplus
34 extern          "C"
35 {
36 #endif
37
38 struct sqlca_t
39 {
40         char            sqlcaid[8];
41         long            sqlabc;
42         long            sqlcode;
43         struct
44         {
45                 int                     sqlerrml;
46                 char            sqlerrmc[SQLERRMC_LEN];
47         }                       sqlerrm;
48         char            sqlerrp[8];
49         long            sqlerrd[6];
50         /* Element 0: empty                                             */
51         /* 1: OID of processed tuple if applicable                      */
52         /* 2: number of rows processed                          */
53         /* after an INSERT, UPDATE or                           */
54         /* DELETE statement                                     */
55         /* 3: empty                                             */
56         /* 4: empty                                             */
57         /* 5: empty                                             */
58         char            sqlwarn[8];
59         /* Element 0: set to 'W' if at least one other is 'W'   */
60         /* 1: if 'W' at least one character string              */
61         /* value was truncated when it was                      */
62         /* stored into a host variable.             */
63
64         /*
65          * 2: if 'W' a (hopefully) non-fatal notice occurred
66          */     /* 3: empty */
67         /* 4: empty                                             */
68         /* 5: empty                                             */
69         /* 6: empty                                             */
70         /* 7: empty                                             */
71
72         char            sqlstate[5];
73 };
74
75 struct sqlca_t *ECPGget_sqlca(void);
76
77 #ifndef POSTGRES_ECPG_INTERNAL
78 #define sqlca (*ECPGget_sqlca())
79 #endif
80
81 #ifdef __cplusplus
82 }
83 #endif
84
85 #endif
86
87 #line 7 "array.pgc"
88
89
90 #line 1 "regression.h"
91
92
93
94
95
96
97 #line 8 "array.pgc"
98
99
100 int
101 main (void)
102 {
103 /* exec sql begin declare section */
104            
105            
106            
107            
108             
109          
110
111 #line 14 "array.pgc"
112  int i = 1 ;
113  
114 #line 15 "array.pgc"
115  int * did = & i ;
116  
117 #line 16 "array.pgc"
118  int a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
119  
120 #line 17 "array.pgc"
121  char text [ 25 ] = "klmnopqrst" ;
122  
123 #line 18 "array.pgc"
124  char * t = ( char * ) malloc ( 11 ) ;
125  
126 #line 19 "array.pgc"
127  double f ;
128 /* exec sql end declare section */
129 #line 20 "array.pgc"
130
131
132         strcpy(t, "0123456789");
133         setlocale(LC_ALL, "C");
134
135         ECPGdebug(1, stderr);
136
137         { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
138 #line 27 "array.pgc"
139
140 if (sqlca.sqlcode < 0) sqlprint();}
141 #line 27 "array.pgc"
142
143
144         { ECPGsetcommit(__LINE__, "on", NULL);
145 #line 29 "array.pgc"
146
147 if (sqlca.sqlcode < 0) sqlprint();}
148 #line 29 "array.pgc"
149
150
151         { ECPGtrans(__LINE__, NULL, "begin work");
152 #line 31 "array.pgc"
153
154 if (sqlca.sqlcode < 0) sqlprint();}
155 #line 31 "array.pgc"
156
157
158         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
159 #line 33 "array.pgc"
160
161 if (sqlca.sqlcode < 0) sqlprint();}
162 #line 33 "array.pgc"
163
164
165         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' )", ECPGt_EOIT, ECPGt_EORT);
166 #line 35 "array.pgc"
167
168 if (sqlca.sqlcode < 0) sqlprint();}
169 #line 35 "array.pgc"
170
171
172         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 140787.0 , 2 , $1  , $2  )", 
173         ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
174         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
175         ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
176         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
177 #line 37 "array.pgc"
178
179 if (sqlca.sqlcode < 0) sqlprint();}
180 #line 37 "array.pgc"
181
182
183         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 14.07 , $1  , $2  , $3  )", 
184         ECPGt_int,&(did),(long)1,(long)0,sizeof(int), 
185         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
186         ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
187         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
188         ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), 
189         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
190 #line 39 "array.pgc"
191
192 if (sqlca.sqlcode < 0) sqlprint();}
193 #line 39 "array.pgc"
194
195
196         { ECPGtrans(__LINE__, NULL, "commit");
197 #line 41 "array.pgc"
198
199 if (sqlca.sqlcode < 0) sqlprint();}
200 #line 41 "array.pgc"
201
202
203         { ECPGtrans(__LINE__, NULL, "begin work");
204 #line 43 "array.pgc"
205
206 if (sqlca.sqlcode < 0) sqlprint();}
207 #line 43 "array.pgc"
208
209
210         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT, 
211         ECPGt_double,&(f),(long)1,(long)1,sizeof(double), 
212         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
213         ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
214         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
215 #line 48 "array.pgc"
216
217 if (sqlca.sqlcode < 0) sqlprint();}
218 #line 48 "array.pgc"
219
220
221         printf("Found f=%f text=%10.10s\n", f, text);
222
223         f=140787;
224         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text from test where f = $1 ", 
225         ECPGt_double,&(f),(long)1,(long)1,sizeof(double), 
226         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
227         ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
228         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
229         ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), 
230         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
231 #line 56 "array.pgc"
232
233 if (sqlca.sqlcode < 0) sqlprint();}
234 #line 56 "array.pgc"
235
236
237         for (i = 0; i < 10; i++)
238                 printf("Found a[%d] = %d\n", i, a[i]);
239
240         printf("Found text=%10.10s\n", t);
241
242         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a from test where f = $1 ", 
243         ECPGt_double,&(f),(long)1,(long)1,sizeof(double), 
244         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
245         ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
246         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
247 #line 66 "array.pgc"
248
249 if (sqlca.sqlcode < 0) sqlprint();}
250 #line 66 "array.pgc"
251
252
253         printf("Found text=%s\n", text);
254
255         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
256 #line 70 "array.pgc"
257
258 if (sqlca.sqlcode < 0) sqlprint();}
259 #line 70 "array.pgc"
260
261
262         { ECPGtrans(__LINE__, NULL, "commit");
263 #line 72 "array.pgc"
264
265 if (sqlca.sqlcode < 0) sqlprint();}
266 #line 72 "array.pgc"
267
268
269         { ECPGdisconnect(__LINE__, "CURRENT");
270 #line 74 "array.pgc"
271
272 if (sqlca.sqlcode < 0) sqlprint();}
273 #line 74 "array.pgc"
274
275
276         free(t);
277
278         return (0);
279 }