00001
00002
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008
00009 #line 1 "sqlda.pgc"
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <limits.h>
00013
00014
00015 #line 1 "regression.h"
00016
00017
00018
00019
00020
00021
00022 #line 5 "sqlda.pgc"
00023
00024
00025
00026 #line 1 "sqlda.h"
00027 #ifndef ECPG_SQLDA_H
00028 #define ECPG_SQLDA_H
00029
00030 #ifdef _ECPG_INFORMIX_H
00031
00032 #include "sqlda-compat.h"
00033 typedef struct sqlvar_compat sqlvar_t;
00034 typedef struct sqlda_compat sqlda_t;
00035
00036 #else
00037
00038 #include "sqlda-native.h"
00039 typedef struct sqlvar_struct sqlvar_t;
00040 typedef struct sqlda_struct sqlda_t;
00041
00042 #endif
00043
00044 #endif
00045
00046 #line 7 "sqlda.pgc"
00047
00048
00049 #line 1 "pgtypes_numeric.h"
00050 #ifndef PGTYPES_NUMERIC
00051 #define PGTYPES_NUMERIC
00052
00053 #define NUMERIC_POS 0x0000
00054 #define NUMERIC_NEG 0x4000
00055 #define NUMERIC_NAN 0xC000
00056 #define NUMERIC_NULL 0xF000
00057 #define NUMERIC_MAX_PRECISION 1000
00058 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
00059 #define NUMERIC_MIN_DISPLAY_SCALE 0
00060 #define NUMERIC_MIN_SIG_DIGITS 16
00061
00062 #define DECSIZE 30
00063
00064 typedef unsigned char NumericDigit;
00065 typedef struct
00066 {
00067 int ndigits;
00068 int weight;
00069 int rscale;
00070 int dscale;
00071 int sign;
00072 NumericDigit *buf;
00073 NumericDigit *digits;
00074 } numeric;
00075
00076 typedef struct
00077 {
00078 int ndigits;
00079 int weight;
00080 int rscale;
00081 int dscale;
00082 int sign;
00083 NumericDigit digits[DECSIZE];
00084 } decimal;
00085
00086 #ifdef __cplusplus
00087 extern "C"
00088 {
00089 #endif
00090
00091 numeric *PGTYPESnumeric_new(void);
00092 decimal *PGTYPESdecimal_new(void);
00093 void PGTYPESnumeric_free(numeric *);
00094 void PGTYPESdecimal_free(decimal *);
00095 numeric *PGTYPESnumeric_from_asc(char *, char **);
00096 char *PGTYPESnumeric_to_asc(numeric *, int);
00097 int PGTYPESnumeric_add(numeric *, numeric *, numeric *);
00098 int PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
00099 int PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
00100 int PGTYPESnumeric_div(numeric *, numeric *, numeric *);
00101 int PGTYPESnumeric_cmp(numeric *, numeric *);
00102 int PGTYPESnumeric_from_int(signed int, numeric *);
00103 int PGTYPESnumeric_from_long(signed long int, numeric *);
00104 int PGTYPESnumeric_copy(numeric *, numeric *);
00105 int PGTYPESnumeric_from_double(double, numeric *);
00106 int PGTYPESnumeric_to_double(numeric *, double *);
00107 int PGTYPESnumeric_to_int(numeric *, int *);
00108 int PGTYPESnumeric_to_long(numeric *, long *);
00109 int PGTYPESnumeric_to_decimal(numeric *, decimal *);
00110 int PGTYPESnumeric_from_decimal(decimal *, numeric *);
00111
00112 #ifdef __cplusplus
00113 }
00114 #endif
00115
00116 #endif
00117
00118 #line 8 "sqlda.pgc"
00119
00120
00121
00122 #line 10 "sqlda.pgc"
00123
00124
00125
00126 sqlda_t *inp_sqlda, *outp_sqlda, *outp_sqlda1;
00127
00128 static void
00129 dump_sqlda(sqlda_t *sqlda)
00130 {
00131 int i;
00132
00133 if (sqlda == NULL)
00134 {
00135 printf("dump_sqlda called with NULL sqlda\n");
00136 return;
00137 }
00138
00139 for (i = 0; i < sqlda->sqld; i++)
00140 {
00141 if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
00142 printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname.data);
00143 else
00144 switch (sqlda->sqlvar[i].sqltype)
00145 {
00146 case ECPGt_char:
00147 printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname.data, sqlda->sqlvar[i].sqldata);
00148 break;
00149 case ECPGt_int:
00150 printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname.data, *(int *)sqlda->sqlvar[i].sqldata);
00151 break;
00152 case ECPGt_double:
00153 printf("name sqlda descriptor: '%s' value %lf\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
00154 break;
00155 case ECPGt_numeric:
00156 {
00157 char *val;
00158
00159 val = PGTYPESnumeric_to_asc((numeric*)sqlda->sqlvar[i].sqldata, -1);
00160 printf("name sqlda descriptor: '%s' value NUMERIC '%s'\n", sqlda->sqlvar[i].sqlname.data, val);
00161 free(val);
00162 break;
00163 }
00164 }
00165 }
00166 }
00167
00168 int
00169 main (void)
00170 {
00171
00172
00173
00174
00175
00176
00177 #line 59 "sqlda.pgc"
00178 char * stmt1 = "SELECT * FROM t1" ;
00179
00180 #line 60 "sqlda.pgc"
00181 char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
00182
00183 #line 61 "sqlda.pgc"
00184 int rec ;
00185
00186 #line 62 "sqlda.pgc"
00187 int id ;
00188
00189 #line 63 "sqlda.pgc"
00190
00191
00192 char msg[128];
00193
00194 ECPGdebug(1, stderr);
00195
00196 strcpy(msg, "connect");
00197 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , "regress1", 0);
00198 #line 70 "sqlda.pgc"
00199
00200 if (sqlca.sqlcode < 0) exit (1);}
00201 #line 70 "sqlda.pgc"
00202
00203
00204 strcpy(msg, "set");
00205 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
00206 #line 73 "sqlda.pgc"
00207
00208 if (sqlca.sqlcode < 0) exit (1);}
00209 #line 73 "sqlda.pgc"
00210
00211
00212 strcpy(msg, "create");
00213 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
00214 #line 81 "sqlda.pgc"
00215
00216 if (sqlca.sqlcode < 0) exit (1);}
00217 #line 81 "sqlda.pgc"
00218
00219
00220 strcpy(msg, "insert");
00221 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' ) , ( 2 , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' )", ECPGt_EOIT, ECPGt_EORT);
00222 #line 87 "sqlda.pgc"
00223
00224 if (sqlca.sqlcode < 0) exit (1);}
00225 #line 87 "sqlda.pgc"
00226
00227
00228 strcpy(msg, "commit");
00229 { ECPGtrans(__LINE__, NULL, "commit");
00230 #line 90 "sqlda.pgc"
00231
00232 if (sqlca.sqlcode < 0) exit (1);}
00233 #line 90 "sqlda.pgc"
00234
00235
00236
00237
00238 outp_sqlda = NULL;
00239
00240 strcpy(msg, "prepare");
00241 { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
00242 #line 97 "sqlda.pgc"
00243
00244 if (sqlca.sqlcode < 0) exit (1);}
00245 #line 97 "sqlda.pgc"
00246
00247
00248 strcpy(msg, "declare");
00249
00250 #line 100 "sqlda.pgc"
00251
00252
00253 strcpy(msg, "open");
00254 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
00255 ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
00256 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00257 #line 103 "sqlda.pgc"
00258
00259 if (sqlca.sqlcode < 0) exit (1);}
00260 #line 103 "sqlda.pgc"
00261
00262
00263
00264 #line 105 "sqlda.pgc"
00265
00266
00267 rec = 0;
00268 while (1)
00269 {
00270 strcpy(msg, "fetch");
00271 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
00272 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
00273 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00274 #line 111 "sqlda.pgc"
00275
00276 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
00277 #line 111 "sqlda.pgc"
00278
00279 if (sqlca.sqlcode < 0) exit (1);}
00280 #line 111 "sqlda.pgc"
00281
00282
00283 printf("FETCH RECORD %d\n", ++rec);
00284 dump_sqlda(outp_sqlda);
00285 }
00286
00287
00288 #line 117 "sqlda.pgc"
00289
00290
00291 strcpy(msg, "close");
00292 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
00293 #line 120 "sqlda.pgc"
00294
00295 if (sqlca.sqlcode < 0) exit (1);}
00296 #line 120 "sqlda.pgc"
00297
00298
00299 strcpy(msg, "deallocate");
00300 { ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
00301 #line 123 "sqlda.pgc"
00302
00303 if (sqlca.sqlcode < 0) exit (1);}
00304 #line 123 "sqlda.pgc"
00305
00306
00307 free(outp_sqlda);
00308
00309
00310
00311 outp_sqlda = NULL;
00312
00313 strcpy(msg, "prepare");
00314 { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
00315 #line 132 "sqlda.pgc"
00316
00317 if (sqlca.sqlcode < 0) exit (1);}
00318 #line 132 "sqlda.pgc"
00319
00320
00321 strcpy(msg, "declare");
00322
00323 #line 135 "sqlda.pgc"
00324
00325
00326 strcpy(msg, "open");
00327 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
00328 ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
00329 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00330 #line 138 "sqlda.pgc"
00331
00332 if (sqlca.sqlcode < 0) exit (1);}
00333 #line 138 "sqlda.pgc"
00334
00335
00336 strcpy(msg, "fetch");
00337 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT,
00338 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
00339 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00340 #line 141 "sqlda.pgc"
00341
00342 if (sqlca.sqlcode < 0) exit (1);}
00343 #line 141 "sqlda.pgc"
00344
00345
00346 outp_sqlda1 = outp_sqlda;
00347 rec = 0;
00348 while (outp_sqlda1)
00349 {
00350 sqlda_t *ptr;
00351 printf("FETCH RECORD %d\n", ++rec);
00352 dump_sqlda(outp_sqlda1);
00353
00354 ptr = outp_sqlda1;
00355 outp_sqlda1 = outp_sqlda1->desc_next;
00356 free(ptr);
00357 }
00358
00359 strcpy(msg, "close");
00360 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
00361 #line 157 "sqlda.pgc"
00362
00363 if (sqlca.sqlcode < 0) exit (1);}
00364 #line 157 "sqlda.pgc"
00365
00366
00367 strcpy(msg, "deallocate");
00368 { ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
00369 #line 160 "sqlda.pgc"
00370
00371 if (sqlca.sqlcode < 0) exit (1);}
00372 #line 160 "sqlda.pgc"
00373
00374
00375
00376
00377
00378
00379
00380
00381 inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
00382 memset(inp_sqlda, 0, sizeof(sqlda_t));
00383 inp_sqlda->sqln = 1;
00384
00385 inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
00386 inp_sqlda->sqlvar[0].sqldata = (char *)&id;
00387
00388 printf("EXECUTE RECORD 4\n");
00389
00390 id = 4;
00391
00392 outp_sqlda = NULL;
00393
00394 strcpy(msg, "prepare");
00395 { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
00396 #line 182 "sqlda.pgc"
00397
00398 if (sqlca.sqlcode < 0) exit (1);}
00399 #line 182 "sqlda.pgc"
00400
00401
00402 strcpy(msg, "execute");
00403 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "st_id3",
00404 ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
00405 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
00406 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
00407 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00408 #line 185 "sqlda.pgc"
00409
00410 if (sqlca.sqlcode < 0) exit (1);}
00411 #line 185 "sqlda.pgc"
00412
00413
00414 dump_sqlda(outp_sqlda);
00415
00416 strcpy(msg, "deallocate");
00417 { ECPGdeallocate(__LINE__, 0, NULL, "st_id3");
00418 #line 190 "sqlda.pgc"
00419
00420 if (sqlca.sqlcode < 0) exit (1);}
00421 #line 190 "sqlda.pgc"
00422
00423
00424 free(inp_sqlda);
00425 free(outp_sqlda);
00426
00427
00428
00429
00430
00431 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , "con2", 0);
00432 #line 199 "sqlda.pgc"
00433
00434 if (sqlca.sqlcode < 0) exit (1);}
00435 #line 199 "sqlda.pgc"
00436
00437
00438
00439
00440
00441
00442 inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
00443 memset(inp_sqlda, 0, sizeof(sqlda_t));
00444 inp_sqlda->sqln = 1;
00445
00446 inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
00447 inp_sqlda->sqlvar[0].sqldata = (char *)&id;
00448
00449 printf("EXECUTE RECORD 4\n");
00450
00451 id = 4;
00452
00453 outp_sqlda = NULL;
00454
00455 strcpy(msg, "prepare");
00456 { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
00457 #line 219 "sqlda.pgc"
00458
00459 if (sqlca.sqlcode < 0) exit (1);}
00460 #line 219 "sqlda.pgc"
00461
00462
00463 strcpy(msg, "execute");
00464 { ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_execute, "st_id4",
00465 ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
00466 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
00467 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
00468 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00469 #line 222 "sqlda.pgc"
00470
00471 if (sqlca.sqlcode < 0) exit (1);}
00472 #line 222 "sqlda.pgc"
00473
00474
00475 dump_sqlda(outp_sqlda);
00476
00477 strcpy(msg, "commit");
00478 { ECPGtrans(__LINE__, "con2", "commit");
00479 #line 227 "sqlda.pgc"
00480
00481 if (sqlca.sqlcode < 0) exit (1);}
00482 #line 227 "sqlda.pgc"
00483
00484
00485 strcpy(msg, "deallocate");
00486 { ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
00487 #line 230 "sqlda.pgc"
00488
00489 if (sqlca.sqlcode < 0) exit (1);}
00490 #line 230 "sqlda.pgc"
00491
00492
00493 free(inp_sqlda);
00494 free(outp_sqlda);
00495
00496 strcpy(msg, "disconnect");
00497 { ECPGdisconnect(__LINE__, "con2");
00498 #line 236 "sqlda.pgc"
00499
00500 if (sqlca.sqlcode < 0) exit (1);}
00501 #line 236 "sqlda.pgc"
00502
00503
00504
00505
00506 strcpy(msg, "drop");
00507 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
00508 #line 241 "sqlda.pgc"
00509
00510 if (sqlca.sqlcode < 0) exit (1);}
00511 #line 241 "sqlda.pgc"
00512
00513
00514 strcpy(msg, "commit");
00515 { ECPGtrans(__LINE__, NULL, "commit");
00516 #line 244 "sqlda.pgc"
00517
00518 if (sqlca.sqlcode < 0) exit (1);}
00519 #line 244 "sqlda.pgc"
00520
00521
00522 strcpy(msg, "disconnect");
00523 { ECPGdisconnect(__LINE__, "CURRENT");
00524 #line 247 "sqlda.pgc"
00525
00526 if (sqlca.sqlcode < 0) exit (1);}
00527 #line 247 "sqlda.pgc"
00528
00529
00530 return (0);
00531 }