Header And Logo

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

sql-indicators.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 "indicators.pgc"
00010 #include <stdio.h>
00011 
00012 
00013 #line 1 "sqlca.h"
00014 #ifndef POSTGRES_SQLCA_H
00015 #define POSTGRES_SQLCA_H
00016 
00017 #ifndef PGDLLIMPORT
00018 #if  defined(WIN32) || defined(__CYGWIN__)
00019 #define PGDLLIMPORT __declspec (dllimport)
00020 #else
00021 #define PGDLLIMPORT
00022 #endif   /* __CYGWIN__ */
00023 #endif   /* PGDLLIMPORT */
00024 
00025 #define SQLERRMC_LEN    150
00026 
00027 #ifdef __cplusplus
00028 extern      "C"
00029 {
00030 #endif
00031 
00032 struct sqlca_t
00033 {
00034     char        sqlcaid[8];
00035     long        sqlabc;
00036     long        sqlcode;
00037     struct
00038     {
00039         int         sqlerrml;
00040         char        sqlerrmc[SQLERRMC_LEN];
00041     }           sqlerrm;
00042     char        sqlerrp[8];
00043     long        sqlerrd[6];
00044     /* Element 0: empty                     */
00045     /* 1: OID of processed tuple if applicable          */
00046     /* 2: number of rows processed              */
00047     /* after an INSERT, UPDATE or               */
00048     /* DELETE statement                 */
00049     /* 3: empty                     */
00050     /* 4: empty                     */
00051     /* 5: empty                     */
00052     char        sqlwarn[8];
00053     /* Element 0: set to 'W' if at least one other is 'W'   */
00054     /* 1: if 'W' at least one character string      */
00055     /* value was truncated when it was          */
00056     /* stored into a host variable.             */
00057 
00058     /*
00059      * 2: if 'W' a (hopefully) non-fatal notice occurred
00060      */ /* 3: empty */
00061     /* 4: empty                     */
00062     /* 5: empty                     */
00063     /* 6: empty                     */
00064     /* 7: empty                     */
00065 
00066     char        sqlstate[5];
00067 };
00068 
00069 struct sqlca_t *ECPGget_sqlca(void);
00070 
00071 #ifndef POSTGRES_ECPG_INTERNAL
00072 #define sqlca (*ECPGget_sqlca())
00073 #endif
00074 
00075 #ifdef __cplusplus
00076 }
00077 #endif
00078 
00079 #endif
00080 
00081 #line 3 "indicators.pgc"
00082 
00083 
00084 #line 1 "regression.h"
00085 
00086 
00087 
00088 
00089 
00090 
00091 #line 4 "indicators.pgc"
00092 
00093 
00094 int main()
00095 {
00096     /* exec sql begin declare section */
00097            
00098            
00099     
00100 #line 9 "indicators.pgc"
00101  int intvar = 5 ;
00102  
00103 #line 10 "indicators.pgc"
00104  int nullind = - 1 ;
00105 /* exec sql end declare section */
00106 #line 11 "indicators.pgc"
00107 
00108 
00109     ECPGdebug(1,stderr);
00110 
00111     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
00112 #line 15 "indicators.pgc"
00113 
00114     { ECPGsetcommit(__LINE__, "off", NULL);}
00115 #line 16 "indicators.pgc"
00116 
00117 
00118     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table indicator_test ( \"id\" int primary key , \"str\" text not null , val int null )", ECPGt_EOIT, ECPGt_EORT);}
00119 #line 21 "indicators.pgc"
00120 
00121     { ECPGtrans(__LINE__, NULL, "commit work");}
00122 #line 22 "indicators.pgc"
00123 
00124 
00125     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 1 , 'Hello' , 0 )", ECPGt_EOIT, ECPGt_EORT);}
00126 #line 24 "indicators.pgc"
00127 
00128 
00129     /* use indicator in insert */
00130     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 2 , 'Hi there' , $1  )", 
00131     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00132     ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
00133 #line 27 "indicators.pgc"
00134 
00135     nullind = 0;
00136     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 3 , 'Good evening' , $1  )", 
00137     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00138     ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
00139 #line 29 "indicators.pgc"
00140 
00141     { ECPGtrans(__LINE__, NULL, "commit work");}
00142 #line 30 "indicators.pgc"
00143 
00144 
00145     /* use indicators to get information about selects */
00146     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 1", ECPGt_EOIT, 
00147     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00148     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00149 #line 33 "indicators.pgc"
00150 
00151     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 2", ECPGt_EOIT, 
00152     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00153     ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
00154 #line 34 "indicators.pgc"
00155 
00156     printf("intvar: %d, nullind: %d\n", intvar, nullind);
00157     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 3", ECPGt_EOIT, 
00158     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00159     ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
00160 #line 36 "indicators.pgc"
00161 
00162     printf("intvar: %d, nullind: %d\n", intvar, nullind);
00163 
00164     /* use indicators for update */
00165     intvar = 5; nullind = -1;
00166     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update indicator_test set val = $1  where id = 1", 
00167     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00168     ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
00169 #line 41 "indicators.pgc"
00170 
00171     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 1", ECPGt_EOIT, 
00172     ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
00173     ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
00174 #line 42 "indicators.pgc"
00175 
00176     printf("intvar: %d, nullind: %d\n", intvar, nullind);
00177 
00178     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table indicator_test", ECPGt_EOIT, ECPGt_EORT);}
00179 #line 45 "indicators.pgc"
00180 
00181     { ECPGtrans(__LINE__, NULL, "commit work");}
00182 #line 46 "indicators.pgc"
00183 
00184 
00185     { ECPGdisconnect(__LINE__, "CURRENT");}
00186 #line 48 "indicators.pgc"
00187 
00188     return 0;
00189 }