Header And Logo

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

compat_informix-describe.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 "describe.pgc"
00012 #include <stdlib.h>
00013 #include <string.h>
00014 
00015 
00016 #line 1 "regression.h"
00017 
00018 
00019 
00020 
00021 
00022 
00023 #line 4 "describe.pgc"
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 /* ECPG_SQLDA_H */
00045 
00046 #line 5 "describe.pgc"
00047 
00048 
00049 /* exec sql whenever sqlerror  stop ; */
00050 #line 7 "describe.pgc"
00051 
00052 
00053 sqlda_t *sqlda1, *sqlda2, *sqlda3;
00054 
00055 int
00056 main (void)
00057 {
00058 /* exec sql begin declare section */
00059           
00060           
00061           
00062           
00063           
00064 
00065 #line 15 "describe.pgc"
00066  char * stmt1 = "SELECT id, t FROM descr_t1" ;
00067  
00068 #line 16 "describe.pgc"
00069  char * stmt2 = "SELECT id, t FROM descr_t1 WHERE id = -1" ;
00070  
00071 #line 17 "describe.pgc"
00072  int i , count1 , count2 ;
00073  
00074 #line 18 "describe.pgc"
00075  char field_name1 [ 30 ] = "not set" ;
00076  
00077 #line 19 "describe.pgc"
00078  char field_name2 [ 30 ] = "not set" ;
00079 /* exec sql end declare section */
00080 #line 20 "describe.pgc"
00081 
00082 
00083     char msg[128];
00084 
00085     ECPGdebug(1, stderr);
00086 
00087     strcpy(msg, "connect");
00088     { ECPGconnect(__LINE__, 1, "regress1" , NULL, NULL , NULL, 0); 
00089 #line 27 "describe.pgc"
00090 
00091 if (sqlca.sqlcode < 0) exit (1);}
00092 #line 27 "describe.pgc"
00093 
00094 
00095     strcpy(msg, "set");
00096     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
00097 #line 30 "describe.pgc"
00098 
00099 if (sqlca.sqlcode < 0) exit (1);}
00100 #line 30 "describe.pgc"
00101 
00102 
00103     strcpy(msg, "create");
00104     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table descr_t1 ( id serial primary key , t text )", ECPGt_EOIT, ECPGt_EORT);
00105 #line 33 "describe.pgc"
00106 
00107 if (sqlca.sqlcode < 0) exit (1);}
00108 #line 33 "describe.pgc"
00109 
00110 
00111     strcpy(msg, "insert");
00112     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'a' )", ECPGt_EOIT, ECPGt_EORT);
00113 #line 36 "describe.pgc"
00114 
00115 if (sqlca.sqlcode < 0) exit (1);}
00116 #line 36 "describe.pgc"
00117 
00118     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'b' )", ECPGt_EOIT, ECPGt_EORT);
00119 #line 37 "describe.pgc"
00120 
00121 if (sqlca.sqlcode < 0) exit (1);}
00122 #line 37 "describe.pgc"
00123 
00124     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'c' )", ECPGt_EOIT, ECPGt_EORT);
00125 #line 38 "describe.pgc"
00126 
00127 if (sqlca.sqlcode < 0) exit (1);}
00128 #line 38 "describe.pgc"
00129 
00130     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'd' )", ECPGt_EOIT, ECPGt_EORT);
00131 #line 39 "describe.pgc"
00132 
00133 if (sqlca.sqlcode < 0) exit (1);}
00134 #line 39 "describe.pgc"
00135 
00136 
00137     strcpy(msg, "commit");
00138     { ECPGtrans(__LINE__, NULL, "commit");
00139 #line 42 "describe.pgc"
00140 
00141 if (sqlca.sqlcode < 0) exit (1);}
00142 #line 42 "describe.pgc"
00143 
00144 
00145     /*
00146      * Test DESCRIBE with a query producing tuples.
00147      * DESCRIPTOR and SQL DESCRIPTOR are NOT the same in
00148      * Informix-compat mode.
00149      */
00150 
00151     strcpy(msg, "allocate");
00152     ECPGallocate_desc(__LINE__, "desc1");
00153 #line 51 "describe.pgc"
00154 
00155 if (sqlca.sqlcode < 0) exit (1);
00156 #line 51 "describe.pgc"
00157 
00158     ECPGallocate_desc(__LINE__, "desc2");
00159 #line 52 "describe.pgc"
00160 
00161 if (sqlca.sqlcode < 0) exit (1);
00162 #line 52 "describe.pgc"
00163 
00164 
00165     strcpy(msg, "prepare");
00166     { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
00167 #line 55 "describe.pgc"
00168 
00169 if (sqlca.sqlcode < 0) exit (1);}
00170 #line 55 "describe.pgc"
00171 
00172 
00173     sqlda1 = sqlda2 = sqlda3 = NULL;
00174 
00175     strcpy(msg, "describe");
00176     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
00177     ECPGt_descriptor, "desc1", 0L, 0L, 0L, 
00178     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00179 #line 60 "describe.pgc"
00180 
00181     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
00182     ECPGt_descriptor, "desc2", 0L, 0L, 0L, 
00183     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00184 #line 61 "describe.pgc"
00185 
00186 
00187     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
00188     ECPGt_sqlda, &sqlda1, 0L, 0L, 0L, 
00189     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00190 #line 63 "describe.pgc"
00191 
00192     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
00193     ECPGt_sqlda, &sqlda2, 0L, 0L, 0L, 
00194     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00195 #line 64 "describe.pgc"
00196 
00197     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
00198     ECPGt_sqlda, &sqlda3, 0L, 0L, 0L, 
00199     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00200 #line 65 "describe.pgc"
00201 
00202 
00203     if (sqlda1 == NULL)
00204     {
00205         printf("sqlda1 NULL\n");
00206         exit(1);
00207     }
00208 
00209     if (sqlda2 == NULL)
00210     {
00211         printf("sqlda2 NULL\n");
00212         exit(1);
00213     }
00214 
00215     if (sqlda3 == NULL)
00216     {
00217         printf("sqlda3 NULL\n");
00218         exit(1);
00219     }
00220 
00221     strcpy(msg, "get descriptor");
00222     { ECPGget_desc_header(__LINE__, "desc1", &(count1));
00223 
00224 #line 86 "describe.pgc"
00225 
00226 if (sqlca.sqlcode < 0) exit (1);}
00227 #line 86 "describe.pgc"
00228 
00229     { ECPGget_desc_header(__LINE__, "desc1", &(count2));
00230 
00231 #line 87 "describe.pgc"
00232 
00233 if (sqlca.sqlcode < 0) exit (1);}
00234 #line 87 "describe.pgc"
00235 
00236 
00237     if (count1 != count2)
00238     {
00239         printf("count1 (%d) != count2 (%d)\n", count1, count2);
00240         exit(1);
00241     }
00242 
00243     if (count1 != sqlda1->sqld)
00244     {
00245         printf("count1 (%d) != sqlda1->sqld (%d)\n", count1, sqlda1->sqld);
00246         exit(1);
00247     }
00248 
00249     if (count1 != sqlda2->sqld)
00250     {
00251         printf("count1 (%d) != sqlda2->sqld (%d)\n", count1, sqlda2->sqld);
00252         exit(1);
00253     }
00254 
00255     if (count1 != sqlda3->sqld)
00256     {
00257         printf("count1 (%d) != sqlda3->sqld (%d)\n", count1, sqlda3->sqld);
00258         exit(1);
00259     }
00260 
00261     for (i = 1; i <= count1; i++)
00262     {
00263         { ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
00264     ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
00265 
00266 #line 115 "describe.pgc"
00267 
00268 if (sqlca.sqlcode < 0) exit (1);}
00269 #line 115 "describe.pgc"
00270 
00271         { ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
00272     ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
00273 
00274 #line 116 "describe.pgc"
00275 
00276 if (sqlca.sqlcode < 0) exit (1);}
00277 #line 116 "describe.pgc"
00278 
00279         printf("%d\n\tfield_name1 '%s'\n\tfield_name2 '%s'\n\t"
00280             "sqlda1 '%s'\n\tsqlda2 '%s'\n\tsqlda3 '%s'\n",
00281             i, field_name1, field_name2,
00282             sqlda1->sqlvar[i-1].sqlname,
00283             sqlda2->sqlvar[i-1].sqlname,
00284             sqlda3->sqlvar[i-1].sqlname);
00285     }
00286 
00287     strcpy(msg, "deallocate");
00288     ECPGdeallocate_desc(__LINE__, "desc1");
00289 #line 126 "describe.pgc"
00290 
00291 if (sqlca.sqlcode < 0) exit (1);
00292 #line 126 "describe.pgc"
00293 
00294     ECPGdeallocate_desc(__LINE__, "desc2");
00295 #line 127 "describe.pgc"
00296 
00297 if (sqlca.sqlcode < 0) exit (1);
00298 #line 127 "describe.pgc"
00299 
00300     free(sqlda1);
00301     free(sqlda2);
00302     free(sqlda3);
00303 
00304     { ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
00305 #line 132 "describe.pgc"
00306 
00307 if (sqlca.sqlcode < 0) exit (1);}
00308 #line 132 "describe.pgc"
00309 
00310 
00311     /* Test DESCRIBE with a query not producing tuples */
00312 
00313     strcpy(msg, "allocate");
00314     ECPGallocate_desc(__LINE__, "desc1");
00315 #line 137 "describe.pgc"
00316 
00317 if (sqlca.sqlcode < 0) exit (1);
00318 #line 137 "describe.pgc"
00319 
00320     ECPGallocate_desc(__LINE__, "desc2");
00321 #line 138 "describe.pgc"
00322 
00323 if (sqlca.sqlcode < 0) exit (1);
00324 #line 138 "describe.pgc"
00325 
00326 
00327     strcpy(msg, "prepare");
00328     { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt2);
00329 #line 141 "describe.pgc"
00330 
00331 if (sqlca.sqlcode < 0) exit (1);}
00332 #line 141 "describe.pgc"
00333 
00334 
00335     sqlda1 = sqlda2 = sqlda3 = NULL;
00336 
00337     strcpy(msg, "describe");
00338     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
00339     ECPGt_descriptor, "desc1", 0L, 0L, 0L, 
00340     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00341 #line 146 "describe.pgc"
00342 
00343     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
00344     ECPGt_descriptor, "desc2", 0L, 0L, 0L, 
00345     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00346 #line 147 "describe.pgc"
00347 
00348 
00349     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
00350     ECPGt_sqlda, &sqlda1, 0L, 0L, 0L, 
00351     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00352 #line 149 "describe.pgc"
00353 
00354     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
00355     ECPGt_sqlda, &sqlda2, 0L, 0L, 0L, 
00356     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00357 #line 150 "describe.pgc"
00358 
00359     { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
00360     ECPGt_sqlda, &sqlda3, 0L, 0L, 0L, 
00361     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00362 #line 151 "describe.pgc"
00363 
00364 
00365     if (sqlda1 == NULL || sqlda1 == NULL || sqlda2 == NULL)
00366         exit(1);
00367 
00368     strcpy(msg, "get descriptor");
00369     { ECPGget_desc_header(__LINE__, "desc1", &(count1));
00370 
00371 #line 157 "describe.pgc"
00372 
00373 if (sqlca.sqlcode < 0) exit (1);}
00374 #line 157 "describe.pgc"
00375 
00376     { ECPGget_desc_header(__LINE__, "desc1", &(count2));
00377 
00378 #line 158 "describe.pgc"
00379 
00380 if (sqlca.sqlcode < 0) exit (1);}
00381 #line 158 "describe.pgc"
00382 
00383 
00384     if (!(  count1 == count2 &&
00385         count1 == sqlda1->sqld &&
00386         count1 == sqlda2->sqld &&
00387         count1 == sqlda3->sqld))
00388         exit(1);
00389 
00390     for (i = 1; i <= count1; i++)
00391     {
00392         { ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
00393     ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
00394 
00395 #line 168 "describe.pgc"
00396 
00397 if (sqlca.sqlcode < 0) exit (1);}
00398 #line 168 "describe.pgc"
00399 
00400         { ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
00401     ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
00402 
00403 #line 169 "describe.pgc"
00404 
00405 if (sqlca.sqlcode < 0) exit (1);}
00406 #line 169 "describe.pgc"
00407 
00408         printf("%d\n\tfield_name1 '%s'\n\tfield_name2 '%s'\n\t"
00409             "sqlda1 '%s'\n\tsqlda2 '%s'\n\tsqlda3 '%s'\n",
00410             i, field_name1, field_name2,
00411             sqlda1->sqlvar[i-1].sqlname,
00412             sqlda2->sqlvar[i-1].sqlname,
00413             sqlda3->sqlvar[i-1].sqlname);
00414     }
00415 
00416     strcpy(msg, "deallocate");
00417     ECPGdeallocate_desc(__LINE__, "desc1");
00418 #line 179 "describe.pgc"
00419 
00420 if (sqlca.sqlcode < 0) exit (1);
00421 #line 179 "describe.pgc"
00422 
00423     ECPGdeallocate_desc(__LINE__, "desc2");
00424 #line 180 "describe.pgc"
00425 
00426 if (sqlca.sqlcode < 0) exit (1);
00427 #line 180 "describe.pgc"
00428 
00429     free(sqlda1);
00430     free(sqlda2);
00431     free(sqlda3);
00432 
00433     { ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
00434 #line 185 "describe.pgc"
00435 
00436 if (sqlca.sqlcode < 0) exit (1);}
00437 #line 185 "describe.pgc"
00438 
00439 
00440     /* End test */
00441 
00442     strcpy(msg, "drop");
00443     { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table descr_t1", ECPGt_EOIT, ECPGt_EORT);
00444 #line 190 "describe.pgc"
00445 
00446 if (sqlca.sqlcode < 0) exit (1);}
00447 #line 190 "describe.pgc"
00448 
00449 
00450     strcpy(msg, "commit");
00451     { ECPGtrans(__LINE__, NULL, "commit");
00452 #line 193 "describe.pgc"
00453 
00454 if (sqlca.sqlcode < 0) exit (1);}
00455 #line 193 "describe.pgc"
00456 
00457 
00458     strcpy(msg, "disconnect");
00459     { ECPGdisconnect(__LINE__, "CURRENT");
00460 #line 196 "describe.pgc"
00461 
00462 if (sqlca.sqlcode < 0) exit (1);}
00463 #line 196 "describe.pgc"
00464 
00465 
00466     return (0);
00467 }