Header And Logo

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

sql-dynalloc2.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 "dynalloc2.pgc"
00010 #include <stdio.h>
00011 
00012 #line 1 "sqlca.h"
00013 #ifndef POSTGRES_SQLCA_H
00014 #define POSTGRES_SQLCA_H
00015 
00016 #ifndef PGDLLIMPORT
00017 #if  defined(WIN32) || defined(__CYGWIN__)
00018 #define PGDLLIMPORT __declspec (dllimport)
00019 #else
00020 #define PGDLLIMPORT
00021 #endif   /* __CYGWIN__ */
00022 #endif   /* PGDLLIMPORT */
00023 
00024 #define SQLERRMC_LEN    150
00025 
00026 #ifdef __cplusplus
00027 extern      "C"
00028 {
00029 #endif
00030 
00031 struct sqlca_t
00032 {
00033     char        sqlcaid[8];
00034     long        sqlabc;
00035     long        sqlcode;
00036     struct
00037     {
00038         int         sqlerrml;
00039         char        sqlerrmc[SQLERRMC_LEN];
00040     }           sqlerrm;
00041     char        sqlerrp[8];
00042     long        sqlerrd[6];
00043     /* Element 0: empty                     */
00044     /* 1: OID of processed tuple if applicable          */
00045     /* 2: number of rows processed              */
00046     /* after an INSERT, UPDATE or               */
00047     /* DELETE statement                 */
00048     /* 3: empty                     */
00049     /* 4: empty                     */
00050     /* 5: empty                     */
00051     char        sqlwarn[8];
00052     /* Element 0: set to 'W' if at least one other is 'W'   */
00053     /* 1: if 'W' at least one character string      */
00054     /* value was truncated when it was          */
00055     /* stored into a host variable.             */
00056 
00057     /*
00058      * 2: if 'W' a (hopefully) non-fatal notice occurred
00059      */ /* 3: empty */
00060     /* 4: empty                     */
00061     /* 5: empty                     */
00062     /* 6: empty                     */
00063     /* 7: empty                     */
00064 
00065     char        sqlstate[5];
00066 };
00067 
00068 struct sqlca_t *ECPGget_sqlca(void);
00069 
00070 #ifndef POSTGRES_ECPG_INTERNAL
00071 #define sqlca (*ECPGget_sqlca())
00072 #endif
00073 
00074 #ifdef __cplusplus
00075 }
00076 #endif
00077 
00078 #endif
00079 
00080 #line 2 "dynalloc2.pgc"
00081 
00082 #include <stdlib.h>
00083 
00084 #line 1 "regression.h"
00085 
00086 
00087 
00088 
00089 
00090 
00091 #line 4 "dynalloc2.pgc"
00092 
00093 
00094 int main(void)
00095 {
00096    /* exec sql begin declare section */
00097     
00098     
00099     
00100     
00101     
00102    
00103 #line 9 "dynalloc2.pgc"
00104  int * ip1 = 0 ;
00105  
00106 #line 10 "dynalloc2.pgc"
00107  char ** cp2 = 0 ;
00108  
00109 #line 11 "dynalloc2.pgc"
00110  int * ipointer1 = 0 ;
00111  
00112 #line 12 "dynalloc2.pgc"
00113  int * ipointer2 = 0 ;
00114  
00115 #line 13 "dynalloc2.pgc"
00116  int colnum ;
00117 /* exec sql end declare section */
00118 #line 14 "dynalloc2.pgc"
00119 
00120    int i;
00121 
00122    ECPGdebug(1, stderr);
00123 
00124    /* exec sql whenever sqlerror  do sqlprint ( ) ; */
00125 #line 19 "dynalloc2.pgc"
00126 
00127    { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
00128 #line 20 "dynalloc2.pgc"
00129 
00130 if (sqlca.sqlcode < 0) sqlprint ( );}
00131 #line 20 "dynalloc2.pgc"
00132 
00133 
00134    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to postgres", ECPGt_EOIT, ECPGt_EORT);
00135 #line 22 "dynalloc2.pgc"
00136 
00137 if (sqlca.sqlcode < 0) sqlprint ( );}
00138 #line 22 "dynalloc2.pgc"
00139 
00140 
00141    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);
00142 #line 24 "dynalloc2.pgc"
00143 
00144 if (sqlca.sqlcode < 0) sqlprint ( );}
00145 #line 24 "dynalloc2.pgc"
00146 
00147    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 1 , 'one' )", ECPGt_EOIT, ECPGt_EORT);
00148 #line 25 "dynalloc2.pgc"
00149 
00150 if (sqlca.sqlcode < 0) sqlprint ( );}
00151 #line 25 "dynalloc2.pgc"
00152 
00153    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 2 , 'two' )", ECPGt_EOIT, ECPGt_EORT);
00154 #line 26 "dynalloc2.pgc"
00155 
00156 if (sqlca.sqlcode < 0) sqlprint ( );}
00157 #line 26 "dynalloc2.pgc"
00158 
00159    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'three' )", ECPGt_EOIT, ECPGt_EORT);
00160 #line 27 "dynalloc2.pgc"
00161 
00162 if (sqlca.sqlcode < 0) sqlprint ( );}
00163 #line 27 "dynalloc2.pgc"
00164 
00165    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 4 , 'four' )", ECPGt_EOIT, ECPGt_EORT);
00166 #line 28 "dynalloc2.pgc"
00167 
00168 if (sqlca.sqlcode < 0) sqlprint ( );}
00169 #line 28 "dynalloc2.pgc"
00170 
00171    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 5 , null )", ECPGt_EOIT, ECPGt_EORT);
00172 #line 29 "dynalloc2.pgc"
00173 
00174 if (sqlca.sqlcode < 0) sqlprint ( );}
00175 #line 29 "dynalloc2.pgc"
00176 
00177    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , null )", ECPGt_EOIT, ECPGt_EORT);
00178 #line 30 "dynalloc2.pgc"
00179 
00180 if (sqlca.sqlcode < 0) sqlprint ( );}
00181 #line 30 "dynalloc2.pgc"
00182 
00183 
00184    ECPGallocate_desc(__LINE__, "mydesc");
00185 #line 32 "dynalloc2.pgc"
00186 
00187 if (sqlca.sqlcode < 0) sqlprint ( );
00188 #line 32 "dynalloc2.pgc"
00189 
00190    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from test", ECPGt_EOIT, 
00191     ECPGt_descriptor, "mydesc", 0L, 0L, 0L, 
00192     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00193 #line 33 "dynalloc2.pgc"
00194 
00195 if (sqlca.sqlcode < 0) sqlprint ( );}
00196 #line 33 "dynalloc2.pgc"
00197 
00198    { ECPGget_desc_header(__LINE__, "mydesc", &(colnum));
00199 
00200 #line 34 "dynalloc2.pgc"
00201 
00202 if (sqlca.sqlcode < 0) sqlprint ( );}
00203 #line 34 "dynalloc2.pgc"
00204 
00205    { ECPGget_desc(__LINE__, "mydesc", 1,ECPGd_indicator,
00206     ECPGt_int,&(ipointer1),(long)1,(long)0,sizeof(int), ECPGd_data,
00207     ECPGt_int,&(ip1),(long)1,(long)0,sizeof(int), ECPGd_EODT);
00208 
00209 #line 35 "dynalloc2.pgc"
00210 
00211 if (sqlca.sqlcode < 0) sqlprint ( );}
00212 #line 35 "dynalloc2.pgc"
00213 
00214    { ECPGget_desc(__LINE__, "mydesc", 2,ECPGd_indicator,
00215     ECPGt_int,&(ipointer2),(long)1,(long)0,sizeof(int), ECPGd_data,
00216     ECPGt_char,&(cp2),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
00217 
00218 #line 36 "dynalloc2.pgc"
00219 
00220 if (sqlca.sqlcode < 0) sqlprint ( );}
00221 #line 36 "dynalloc2.pgc"
00222 
00223 
00224    printf("Result (%d columns):\n", colnum);
00225    for (i=0;i < sqlca.sqlerrd[2];++i)
00226    {
00227       if (ipointer1[i]) printf("NULL, ");
00228       else printf("%d, ",ip1[i]);
00229 
00230       if (ipointer2[i]) printf("NULL, ");
00231       else printf("'%s', ",cp2[i]);
00232       printf("\n");
00233    }
00234    ECPGfree_auto_mem();
00235    printf("\n");
00236 
00237    ECPGdeallocate_desc(__LINE__, "mydesc");
00238 #line 51 "dynalloc2.pgc"
00239 
00240 if (sqlca.sqlcode < 0) sqlprint ( );
00241 #line 51 "dynalloc2.pgc"
00242 
00243    { ECPGtrans(__LINE__, NULL, "rollback");
00244 #line 52 "dynalloc2.pgc"
00245 
00246 if (sqlca.sqlcode < 0) sqlprint ( );}
00247 #line 52 "dynalloc2.pgc"
00248 
00249    { ECPGdisconnect(__LINE__, "CURRENT");
00250 #line 53 "dynalloc2.pgc"
00251 
00252 if (sqlca.sqlcode < 0) sqlprint ( );}
00253 #line 53 "dynalloc2.pgc"
00254 
00255    return 0;
00256 }