Header And Logo

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

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