Header And Logo

PostgreSQL
| The world's most advanced open source database.

compat_informix-sqlda.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* Needed for informix compatibility */
00007 #include <ecpg_informix.h>
00008 /* End of automatic include section */
00009 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00010 
00011 #line 1 "sqlda.pgc"
00012 #include <stdlib.h>
00013 #include <string.h>
00014 #include <limits.h>
00015 
00016 
00017 #line 1 "regression.h"
00018 
00019 
00020 
00021 
00022 
00023 
00024 #line 5 "sqlda.pgc"
00025 
00026 
00027 
00028 #line 1 "sqlda.h"
00029 #ifndef ECPG_SQLDA_H
00030 #define ECPG_SQLDA_H
00031 
00032 #ifdef _ECPG_INFORMIX_H
00033 
00034 #include "sqlda-compat.h"
00035 typedef struct sqlvar_compat    sqlvar_t;
00036 typedef struct sqlda_compat sqlda_t;
00037 
00038 #else
00039 
00040 #include "sqlda-native.h"
00041 typedef struct sqlvar_struct    sqlvar_t;
00042 typedef struct sqlda_struct sqlda_t;
00043 
00044 #endif
00045 
00046 #endif /* ECPG_SQLDA_H */
00047 
00048 #line 7 "sqlda.pgc"
00049 
00050 
00051 #line 1 "sqltypes.h"
00052 #ifndef ECPG_SQLTYPES_H
00053 #define ECPG_SQLTYPES_H
00054 
00055 #include <limits.h>
00056 
00057 #define CCHARTYPE   ECPGt_char
00058 #define CSHORTTYPE  ECPGt_short
00059 #define CINTTYPE    ECPGt_int
00060 #define CLONGTYPE   ECPGt_long
00061 #define CFLOATTYPE  ECPGt_float
00062 #define CDOUBLETYPE ECPGt_double
00063 #define CDECIMALTYPE    ECPGt_decimal
00064 #define CFIXCHARTYPE    108
00065 #define CSTRINGTYPE ECPGt_char
00066 #define CDATETYPE   ECPGt_date
00067 #define CMONEYTYPE  111
00068 #define CDTIMETYPE  ECPGt_timestamp
00069 #define CLOCATORTYPE    113
00070 #define CVCHARTYPE  ECPGt_varchar
00071 #define CINVTYPE    115
00072 #define CFILETYPE   116
00073 #define CINT8TYPE   ECPGt_long_long
00074 #define CCOLLTYPE       118
00075 #define CLVCHARTYPE     119
00076 #define CFIXBINTYPE     120
00077 #define CVARBINTYPE     121
00078 #define CBOOLTYPE       ECPGt_bool
00079 #define CROWTYPE        123
00080 #define CLVCHARPTRTYPE  124
00081 #define CTYPEMAX    25
00082 
00083 /*
00084  * Values used in sqlda->sqlvar[i]->sqltype
00085  */
00086 #define SQLCHAR     ECPGt_char
00087 #define SQLSMINT    ECPGt_short
00088 #define SQLINT      ECPGt_int
00089 #define SQLFLOAT    ECPGt_double
00090 #define SQLSMFLOAT  ECPGt_float
00091 #define SQLDECIMAL  ECPGt_decimal
00092 #define SQLSERIAL   ECPGt_int
00093 #define SQLDATE     ECPGt_date
00094 #define SQLDTIME    ECPGt_timestamp
00095 #define SQLTEXT     ECPGt_char
00096 #define SQLVCHAR    ECPGt_char
00097 #define SQLINTERVAL     ECPGt_interval
00098 #define SQLNCHAR    ECPGt_char
00099 #define SQLNVCHAR   ECPGt_char
00100 #ifdef HAVE_LONG_LONG_INT_64
00101 #define SQLINT8     ECPGt_long_long
00102 #define SQLSERIAL8  ECPGt_long_long
00103 #else
00104 #define SQLINT8     ECPGt_long
00105 #define SQLSERIAL8  ECPGt_long
00106 #endif
00107 
00108 #endif   /* ndef ECPG_SQLTYPES_H */
00109 
00110 #line 8 "sqlda.pgc"
00111 
00112 
00113 /* exec sql whenever sqlerror  stop ; */
00114 #line 10 "sqlda.pgc"
00115 
00116 
00117 /* These shouldn't be under DECLARE SECTION */
00118 sqlda_t *inp_sqlda, *outp_sqlda;
00119 
00120 static void
00121 dump_sqlda(sqlda_t *sqlda)
00122 {
00123     int i;
00124 
00125     if (sqlda == NULL)
00126     {
00127         printf("dump_sqlda called with NULL sqlda\n");
00128         return;
00129     }
00130 
00131     for (i = 0; i < sqlda->sqld; i++)
00132     {
00133         if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
00134             printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname);
00135         else
00136         switch (sqlda->sqlvar[i].sqltype)
00137         {
00138         case SQLCHAR:
00139             printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname, sqlda->sqlvar[i].sqldata);
00140             break;
00141         case SQLINT:
00142             printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname, *(int *)sqlda->sqlvar[i].sqldata);
00143             break;
00144         case SQLFLOAT:
00145             printf("name sqlda descriptor: '%s' value %lf\n", sqlda->sqlvar[i].sqlname, *(double *)sqlda->sqlvar[i].sqldata);
00146             break;
00147         case SQLDECIMAL:
00148             {
00149                 char    val[64];
00150                 dectoasc((decimal *)sqlda->sqlvar[i].sqldata, val, 64, -1);
00151                 printf("name sqlda descriptor: '%s' value DECIMAL '%s'\n", sqlda->sqlvar[i].sqlname, val);
00152                 break;
00153             }
00154         }
00155     }
00156 }
00157 
00158 int
00159 main (void)
00160 {
00161 /* exec sql begin declare section */
00162           
00163           
00164         
00165         
00166 
00167 #line 57 "sqlda.pgc"
00168  char * stmt1 = "SELECT * FROM t1" ;
00169  
00170 #line 58 "sqlda.pgc"
00171  char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
00172  
00173 #line 59 "sqlda.pgc"
00174  int rec ;
00175  
00176 #line 60 "sqlda.pgc"
00177  int id ;
00178 /* exec sql end declare section */
00179 #line 61 "sqlda.pgc"
00180 
00181 
00182     char msg[128];
00183 
00184     ECPGdebug(1, stderr);
00185 
00186     strcpy(msg, "connect");
00187     { ECPGconnect(__LINE__, 1, "regress1" , NULL, NULL , "regress1", 0); 
00188 #line 68 "sqlda.pgc"
00189 
00190 if (sqlca.sqlcode < 0) exit (1);}
00191 #line 68 "sqlda.pgc"
00192 
00193 
00194     strcpy(msg, "set");
00195     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
00196 #line 71 "sqlda.pgc"
00197 
00198 if (sqlca.sqlcode < 0) exit (1);}
00199 #line 71 "sqlda.pgc"
00200 
00201 
00202     strcpy(msg, "create");
00203     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
00204 #line 79 "sqlda.pgc"
00205 
00206 if (sqlca.sqlcode < 0) exit (1);}
00207 #line 79 "sqlda.pgc"
00208 
00209 
00210     strcpy(msg, "insert");
00211     { ECPGdo(__LINE__, 1, 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);
00212 #line 85 "sqlda.pgc"
00213 
00214 if (sqlca.sqlcode < 0) exit (1);}
00215 #line 85 "sqlda.pgc"
00216 
00217 
00218     strcpy(msg, "commit");
00219     { ECPGtrans(__LINE__, NULL, "commit");
00220 #line 88 "sqlda.pgc"
00221 
00222 if (sqlca.sqlcode < 0) exit (1);}
00223 #line 88 "sqlda.pgc"
00224 
00225 
00226     /* SQLDA test for getting all records from a table */
00227 
00228     outp_sqlda = NULL;
00229 
00230     strcpy(msg, "prepare");
00231     { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
00232 #line 95 "sqlda.pgc"
00233 
00234 if (sqlca.sqlcode < 0) exit (1);}
00235 #line 95 "sqlda.pgc"
00236 
00237 
00238     strcpy(msg, "declare");
00239     ECPG_informix_reset_sqlca(); /* declare mycur1 cursor for $1 */
00240 #line 98 "sqlda.pgc"
00241 
00242 
00243     strcpy(msg, "open");
00244     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1", 
00245     ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00246     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00247 #line 101 "sqlda.pgc"
00248 
00249 if (sqlca.sqlcode < 0) exit (1);}
00250 #line 101 "sqlda.pgc"
00251 
00252 
00253     /* exec sql whenever not found  break ; */
00254 #line 103 "sqlda.pgc"
00255 
00256 
00257     rec = 0;
00258     while (1)
00259     {
00260         strcpy(msg, "fetch");
00261         { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
00262     ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
00263     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00264 #line 109 "sqlda.pgc"
00265 
00266 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
00267 #line 109 "sqlda.pgc"
00268 
00269 if (sqlca.sqlcode < 0) exit (1);}
00270 #line 109 "sqlda.pgc"
00271 
00272 
00273         printf("FETCH RECORD %d\n", ++rec);
00274         dump_sqlda(outp_sqlda);
00275     }
00276 
00277     /* exec sql whenever not found  continue ; */
00278 #line 115 "sqlda.pgc"
00279 
00280 
00281     strcpy(msg, "close");
00282     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
00283 #line 118 "sqlda.pgc"
00284 
00285 if (sqlca.sqlcode < 0) exit (1);}
00286 #line 118 "sqlda.pgc"
00287 
00288 
00289     strcpy(msg, "deallocate");
00290     { ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
00291 #line 121 "sqlda.pgc"
00292 
00293 if (sqlca.sqlcode < 0) exit (1);}
00294 #line 121 "sqlda.pgc"
00295 
00296 
00297     free(outp_sqlda);
00298 
00299     /* SQLDA test for getting all records from a table
00300        using the Informix-specific FETCH ... USING DESCRIPTOR
00301      */
00302 
00303     outp_sqlda = NULL;
00304 
00305     strcpy(msg, "prepare");
00306     { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
00307 #line 132 "sqlda.pgc"
00308 
00309 if (sqlca.sqlcode < 0) exit (1);}
00310 #line 132 "sqlda.pgc"
00311 
00312 
00313     strcpy(msg, "declare");
00314     ECPG_informix_reset_sqlca(); /* declare mycur2 cursor for $1 */
00315 #line 135 "sqlda.pgc"
00316 
00317 
00318     strcpy(msg, "open");
00319     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1", 
00320     ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
00321     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00322 #line 138 "sqlda.pgc"
00323 
00324 if (sqlca.sqlcode < 0) exit (1);}
00325 #line 138 "sqlda.pgc"
00326 
00327 
00328     /* exec sql whenever not found  break ; */
00329 #line 140 "sqlda.pgc"
00330 
00331 
00332     rec = 0;
00333     while (1)
00334     {
00335         strcpy(msg, "fetch");
00336         { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch from mycur2", ECPGt_EOIT, 
00337     ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
00338     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00339 #line 146 "sqlda.pgc"
00340 
00341 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
00342 #line 146 "sqlda.pgc"
00343 
00344 if (sqlca.sqlcode < 0) exit (1);}
00345 #line 146 "sqlda.pgc"
00346 
00347 
00348         printf("FETCH RECORD %d\n", ++rec);
00349         dump_sqlda(outp_sqlda);
00350     }
00351 
00352     /* exec sql whenever not found  continue ; */
00353 #line 152 "sqlda.pgc"
00354 
00355 
00356     strcpy(msg, "close");
00357     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
00358 #line 155 "sqlda.pgc"
00359 
00360 if (sqlca.sqlcode < 0) exit (1);}
00361 #line 155 "sqlda.pgc"
00362 
00363 
00364     strcpy(msg, "deallocate");
00365     { ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
00366 #line 158 "sqlda.pgc"
00367 
00368 if (sqlca.sqlcode < 0) exit (1);}
00369 #line 158 "sqlda.pgc"
00370 
00371 
00372     free(outp_sqlda);
00373 
00374     /* SQLDA test for getting one record using an input descriptor */
00375 
00376     /* Input sqlda has to be built manually */
00377     inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
00378     memset(inp_sqlda, 0, sizeof(sqlda_t));
00379     inp_sqlda->sqld = 1;
00380     inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
00381     memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
00382 
00383     inp_sqlda->sqlvar[0].sqltype = SQLINT;
00384     inp_sqlda->sqlvar[0].sqldata = (char *)&id;
00385 
00386     printf("EXECUTE RECORD 4\n");
00387 
00388     id = 4;
00389 
00390     outp_sqlda = NULL;
00391 
00392     strcpy(msg, "prepare");
00393     { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
00394 #line 181 "sqlda.pgc"
00395 
00396 if (sqlca.sqlcode < 0) exit (1);}
00397 #line 181 "sqlda.pgc"
00398 
00399 
00400     strcpy(msg, "execute");
00401     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_execute, "st_id3", 
00402     ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L, 
00403     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
00404     ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
00405     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00406 #line 184 "sqlda.pgc"
00407 
00408 if (sqlca.sqlcode < 0) exit (1);}
00409 #line 184 "sqlda.pgc"
00410 
00411 
00412     dump_sqlda(outp_sqlda);
00413 
00414     strcpy(msg, "deallocate");
00415     { ECPGdeallocate(__LINE__, 1, NULL, "st_id3");
00416 #line 189 "sqlda.pgc"
00417 
00418 if (sqlca.sqlcode < 0) exit (1);}
00419 #line 189 "sqlda.pgc"
00420 
00421 
00422     free(inp_sqlda->sqlvar);
00423     free(inp_sqlda);
00424     free(outp_sqlda);
00425 
00426     /* SQLDA test for getting one record using an input descriptor
00427      * on a named connection
00428      */
00429 
00430     { ECPGconnect(__LINE__, 1, "regress1" , NULL, NULL , "con2", 0); 
00431 #line 199 "sqlda.pgc"
00432 
00433 if (sqlca.sqlcode < 0) exit (1);}
00434 #line 199 "sqlda.pgc"
00435 
00436 
00437     /* Input sqlda has to be built manually */
00438     inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
00439     memset(inp_sqlda, 0, sizeof(sqlda_t));
00440     inp_sqlda->sqld = 1;
00441     inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
00442     memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
00443 
00444     inp_sqlda->sqlvar[0].sqltype = SQLINT;
00445     inp_sqlda->sqlvar[0].sqldata = (char *)&id;
00446 
00447     printf("EXECUTE RECORD 4\n");
00448 
00449     id = 4;
00450 
00451     outp_sqlda = NULL;
00452 
00453     strcpy(msg, "prepare");
00454     { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
00455 #line 218 "sqlda.pgc"
00456 
00457 if (sqlca.sqlcode < 0) exit (1);}
00458 #line 218 "sqlda.pgc"
00459 
00460 
00461     strcpy(msg, "execute");
00462     { ECPGdo(__LINE__, 1, 1, "con2", 0, ECPGst_execute, "st_id4", 
00463     ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L, 
00464     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
00465     ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
00466     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00467 #line 221 "sqlda.pgc"
00468 
00469 if (sqlca.sqlcode < 0) exit (1);}
00470 #line 221 "sqlda.pgc"
00471 
00472 
00473     dump_sqlda(outp_sqlda);
00474 
00475     strcpy(msg, "commit");
00476     { ECPGtrans(__LINE__, "con2", "commit");
00477 #line 226 "sqlda.pgc"
00478 
00479 if (sqlca.sqlcode < 0) exit (1);}
00480 #line 226 "sqlda.pgc"
00481 
00482 
00483     strcpy(msg, "deallocate");
00484     { ECPGdeallocate(__LINE__, 1, NULL, "st_id4");
00485 #line 229 "sqlda.pgc"
00486 
00487 if (sqlca.sqlcode < 0) exit (1);}
00488 #line 229 "sqlda.pgc"
00489 
00490 
00491     free(inp_sqlda->sqlvar);
00492     free(inp_sqlda);
00493     free(outp_sqlda);
00494 
00495     strcpy(msg, "disconnect");
00496     { ECPGdisconnect(__LINE__, "con2");
00497 #line 236 "sqlda.pgc"
00498 
00499 if (sqlca.sqlcode < 0) exit (1);}
00500 #line 236 "sqlda.pgc"
00501 
00502 
00503     /* End test */
00504 
00505     strcpy(msg, "drop");
00506     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
00507 #line 241 "sqlda.pgc"
00508 
00509 if (sqlca.sqlcode < 0) exit (1);}
00510 #line 241 "sqlda.pgc"
00511 
00512 
00513     strcpy(msg, "commit");
00514     { ECPGtrans(__LINE__, NULL, "commit");
00515 #line 244 "sqlda.pgc"
00516 
00517 if (sqlca.sqlcode < 0) exit (1);}
00518 #line 244 "sqlda.pgc"
00519 
00520 
00521     strcpy(msg, "disconnect");
00522     { ECPGdisconnect(__LINE__, "CURRENT");
00523 #line 247 "sqlda.pgc"
00524 
00525 if (sqlca.sqlcode < 0) exit (1);}
00526 #line 247 "sqlda.pgc"
00527 
00528 
00529     return (0);
00530 }