PostgreSQL Source Code  git master
compat_oracle-char_array.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pgtypes_numeric.h>
#include "sqlda-native.h"
Include dependency graph for compat_oracle-char_array.c:

Go to the source code of this file.

Macros

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

Typedefs

typedef struct sqlvar_struct sqlvar_t
 
typedef struct sqlda_struct sqlda_t
 

Functions

static void warn (void)
 
int main ()
 

Macro Definition Documentation

◆ ECPG_SQLDA_H

#define ECPG_SQLDA_H

Definition at line 19 of file compat_oracle-char_array.c.

◆ ECPGdebug

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

Definition at line 7 of file compat_oracle-char_array.c.

Typedef Documentation

◆ sqlda_t

typedef struct sqlda_struct sqlda_t

Definition at line 1 of file compat_oracle-char_array.c.

◆ sqlvar_t

typedef struct sqlvar_struct sqlvar_t

Definition at line 1 of file compat_oracle-char_array.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 60 of file compat_oracle-char_array.c.

60  {
61 
62  /* exec sql whenever sql_warning do warn ( ) ; */
63 #line 22 "char_array.pgc"
64 
65  /* exec sql whenever sqlerror stop ; */
66 #line 23 "char_array.pgc"
67 
68 
69  const char *ppppp = "XXXXX";
70  int loopcount;
71  sqlda_t *sqlda = NULL;
72 
73  /* exec sql begin declare section */
74 
75 
76 
77 
78 
79 #line 30 "char_array.pgc"
80  char shortstr [ 5 ] ;
81 
82 #line 31 "char_array.pgc"
83  char bigstr [ 11 ] ;
84 
85 #line 32 "char_array.pgc"
86  short shstr_ind = 0 ;
87 
88 #line 33 "char_array.pgc"
89  short bigstr_ind = 0 ;
90 /* exec sql end declare section */
91 #line 34 "char_array.pgc"
92 
93 
94  ECPGdebug(1, stderr);
95  { ECPGconnect(__LINE__, 3, "ecpg1_regression" , NULL, NULL , NULL, 0);
96 #line 37 "char_array.pgc"
97 
98 if (sqlca.sqlwarn[0] == 'W') warn ( );
99 #line 37 "char_array.pgc"
100 
101 if (sqlca.sqlcode < 0) exit (1);}
102 #line 37 "char_array.pgc"
103 
104 
105  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "create table strdbase ( strval varchar ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
106 #line 39 "char_array.pgc"
107 
108 if (sqlca.sqlwarn[0] == 'W') warn ( );
109 #line 39 "char_array.pgc"
110 
111 if (sqlca.sqlcode < 0) exit (1);}
112 #line 39 "char_array.pgc"
113 
114  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( '' )", ECPGt_EOIT, ECPGt_EORT);
115 #line 40 "char_array.pgc"
116 
117 if (sqlca.sqlwarn[0] == 'W') warn ( );
118 #line 40 "char_array.pgc"
119 
120 if (sqlca.sqlcode < 0) exit (1);}
121 #line 40 "char_array.pgc"
122 
123  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'AB' )", ECPGt_EOIT, ECPGt_EORT);
124 #line 41 "char_array.pgc"
125 
126 if (sqlca.sqlwarn[0] == 'W') warn ( );
127 #line 41 "char_array.pgc"
128 
129 if (sqlca.sqlcode < 0) exit (1);}
130 #line 41 "char_array.pgc"
131 
132  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCD' )", ECPGt_EOIT, ECPGt_EORT);
133 #line 42 "char_array.pgc"
134 
135 if (sqlca.sqlwarn[0] == 'W') warn ( );
136 #line 42 "char_array.pgc"
137 
138 if (sqlca.sqlcode < 0) exit (1);}
139 #line 42 "char_array.pgc"
140 
141  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDE' )", ECPGt_EOIT, ECPGt_EORT);
142 #line 43 "char_array.pgc"
143 
144 if (sqlca.sqlwarn[0] == 'W') warn ( );
145 #line 43 "char_array.pgc"
146 
147 if (sqlca.sqlcode < 0) exit (1);}
148 #line 43 "char_array.pgc"
149 
150  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEF' )", ECPGt_EOIT, ECPGt_EORT);
151 #line 44 "char_array.pgc"
152 
153 if (sqlca.sqlwarn[0] == 'W') warn ( );
154 #line 44 "char_array.pgc"
155 
156 if (sqlca.sqlcode < 0) exit (1);}
157 #line 44 "char_array.pgc"
158 
159  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEFGHIJ' )", ECPGt_EOIT, ECPGt_EORT);
160 #line 45 "char_array.pgc"
161 
162 if (sqlca.sqlwarn[0] == 'W') warn ( );
163 #line 45 "char_array.pgc"
164 
165 if (sqlca.sqlcode < 0) exit (1);}
166 #line 45 "char_array.pgc"
167 
168 
169  /* declare C cursor for select strval , strval from strdbase */
170 #line 47 "char_array.pgc"
171 
172  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare C cursor for select strval , strval from strdbase", ECPGt_EOIT, ECPGt_EORT);
173 #line 48 "char_array.pgc"
174 
175 if (sqlca.sqlwarn[0] == 'W') warn ( );
176 #line 48 "char_array.pgc"
177 
178 if (sqlca.sqlcode < 0) exit (1);}
179 #line 48 "char_array.pgc"
180 
181 
182  /* exec sql whenever not found break ; */
183 #line 50 "char_array.pgc"
184 
185 
186  printf("Full Str. : Short Ind.\n");
187  for (loopcount = 0; loopcount < 100; loopcount++) {
188  strncpy(shortstr, ppppp, sizeof shortstr);
189  memset(bigstr, 0, sizeof bigstr);
190  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
191  ECPGt_char,(bigstr),(long)11,(long)1,(11)*sizeof(char),
192  ECPGt_short,&(bigstr_ind),(long)1,(long)1,sizeof(short),
193  ECPGt_char,(shortstr),(long)5,(long)1,(5)*sizeof(char),
194  ECPGt_short,&(shstr_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
195 #line 56 "char_array.pgc"
196 
197 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
198 #line 56 "char_array.pgc"
199 
200 if (sqlca.sqlwarn[0] == 'W') warn ( );
201 #line 56 "char_array.pgc"
202 
203 if (sqlca.sqlcode < 0) exit (1);}
204 #line 56 "char_array.pgc"
205 
206  printf("\"%s\": \"%s\" %d\n", bigstr, shortstr, shstr_ind);
207  }
208 
209  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
210 #line 60 "char_array.pgc"
211 
212 if (sqlca.sqlwarn[0] == 'W') warn ( );
213 #line 60 "char_array.pgc"
214 
215 if (sqlca.sqlcode < 0) exit (1);}
216 #line 60 "char_array.pgc"
217 
218  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "drop table strdbase", ECPGt_EOIT, ECPGt_EORT);
219 #line 61 "char_array.pgc"
220 
221 if (sqlca.sqlwarn[0] == 'W') warn ( );
222 #line 61 "char_array.pgc"
223 
224 if (sqlca.sqlcode < 0) exit (1);}
225 #line 61 "char_array.pgc"
226 
227  { ECPGtrans(__LINE__, NULL, "commit work");
228 #line 62 "char_array.pgc"
229 
230 if (sqlca.sqlwarn[0] == 'W') warn ( );
231 #line 62 "char_array.pgc"
232 
233 if (sqlca.sqlcode < 0) exit (1);}
234 #line 62 "char_array.pgc"
235 
236 
237  /* SQLDA handling */
238  /* exec sql whenever sql_warning sqlprint ; */
239 #line 65 "char_array.pgc"
240 
241  /* exec sql whenever not found stop ; */
242 #line 66 "char_array.pgc"
243 
244  { ECPGprepare(__LINE__, NULL, 0, "stmt1", "SELECT 123::numeric(3,0), 't'::varchar(2)");
245 #line 67 "char_array.pgc"
246 
247 if (sqlca.sqlwarn[0] == 'W') sqlprint();
248 #line 67 "char_array.pgc"
249 
250 if (sqlca.sqlcode < 0) exit (1);}
251 #line 67 "char_array.pgc"
252 
253  /* declare cur1 cursor for $1 */
254 #line 68 "char_array.pgc"
255 
256  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for $1",
257  ECPGt_char_variable,(ECPGprepared_statement(NULL, "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
258  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
259 #line 69 "char_array.pgc"
260 
261 if (sqlca.sqlwarn[0] == 'W') sqlprint();
262 #line 69 "char_array.pgc"
263 
264 if (sqlca.sqlcode < 0) exit (1);}
265 #line 69 "char_array.pgc"
266 
267  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch next from cur1", ECPGt_EOIT,
268  ECPGt_sqlda, &sqlda, 0L, 0L, 0L,
269  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
270 #line 70 "char_array.pgc"
271 
272 if (sqlca.sqlcode == ECPG_NOT_FOUND) exit (1);
273 #line 70 "char_array.pgc"
274 
275 if (sqlca.sqlwarn[0] == 'W') sqlprint();
276 #line 70 "char_array.pgc"
277 
278 if (sqlca.sqlcode < 0) exit (1);}
279 #line 70 "char_array.pgc"
280 
281 
282  printf("\n-----------------\ntype : data\n");
283  for (int i = 0 ; i < sqlda->sqld ; i++)
284  {
285  sqlvar_t v = sqlda->sqlvar[i];
286  char *sqldata = v.sqldata;
287 
288  if (v.sqltype == ECPGt_numeric)
289  sqldata =
290  PGTYPESnumeric_to_asc((numeric*) sqlda->sqlvar[i].sqldata, -1);
291 
292  printf("%-8s: \"%s\"\n", v.sqlname.data, sqldata);
293  }
294 
295  { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
296 #line 85 "char_array.pgc"
297 
298 if (sqlca.sqlwarn[0] == 'W') sqlprint();
299 #line 85 "char_array.pgc"
300 
301 if (sqlca.sqlcode < 0) exit (1);}
302 #line 85 "char_array.pgc"
303 
304  { ECPGtrans(__LINE__, NULL, "commit work");
305 #line 86 "char_array.pgc"
306 
307 if (sqlca.sqlwarn[0] == 'W') sqlprint();
308 #line 86 "char_array.pgc"
309 
310 if (sqlca.sqlcode < 0) exit (1);}
311 #line 86 "char_array.pgc"
312 
313 
314  printf("\nGOOD-BYE!!\n\n");
315 
316  { ECPGdisconnect(__LINE__, "ALL");
317 #line 90 "char_array.pgc"
318 
319 if (sqlca.sqlwarn[0] == 'W') sqlprint();
320 #line 90 "char_array.pgc"
321 
322 if (sqlca.sqlcode < 0) exit (1);}
323 #line 90 "char_array.pgc"
324 
325 
326  return 0;
327 }
static void warn(void)
#define ECPGdebug(X, Y)
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:673
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
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_sqlda
Definition: ecpgtype.h:66
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_char_variable
Definition: ecpgtype.h:60
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_char
Definition: ecpgtype.h:43
void sqlprint(void)
Definition: error.c:334
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:2277
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition: prepare.c:368
int i
Definition: isn.c:73
exit(1)
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
Definition: numeric.c:343
#define printf(...)
Definition: port.h:244
#define sqlca
Definition: sqlca.h:59
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
struct sqlname sqlname
Definition: sqlda-native.h:30
char * sqldata
Definition: sqlda-native.h:28

References sqlname::data, ECPG_NOT_FOUND, ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGprepare(), ECPGprepared_statement(), ECPGst_normal, ECPGt_char, ECPGt_char_variable, ECPGt_EOIT, ECPGt_EORT, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_sqlda, ECPGtrans(), exit(), i, PGTYPESnumeric_to_asc(), printf, sqlca, sqlda_struct::sqld, sqlvar_struct::sqldata, sqlvar_struct::sqlname, sqlprint(), sqlvar_struct::sqltype, sqlda_struct::sqlvar, and warn().

◆ warn()

static void warn ( void  )
static

Definition at line 51 of file compat_oracle-char_array.c.

52 {
53  fprintf(stderr, "Warning: At least one column was truncated\n");
54 }
#define fprintf
Definition: port.h:242

References fprintf.

Referenced by main().