Header And Logo

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

sql-binary.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 "binary.pgc"
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 
00013 
00014 #line 1 "regression.h"
00015 
00016 
00017 
00018 
00019 
00020 
00021 #line 4 "binary.pgc"
00022 
00023 
00024 /* exec sql begin declare section */
00025  
00026 
00027    
00028    
00029    
00030    
00031 
00032 struct TBempl { 
00033 #line 9 "binary.pgc"
00034  long idnum ;
00035  
00036 #line 10 "binary.pgc"
00037  char name [ 21 ] ;
00038  
00039 #line 11 "binary.pgc"
00040  short accs ;
00041  
00042 #line 12 "binary.pgc"
00043  char byte [ 20 ] ;
00044  } ;/* exec sql end declare section */
00045 #line 14 "binary.pgc"
00046 
00047 
00048 int
00049 main (void)
00050 {
00051   /* exec sql begin declare section */
00052     
00053      
00054      
00055   
00056 #line 20 "binary.pgc"
00057  struct TBempl empl ;
00058  
00059 #line 21 "binary.pgc"
00060  char * pointer = NULL ;
00061  
00062 #line 22 "binary.pgc"
00063  char * data = "\\001\\155\\000\\212" ;
00064 /* exec sql end declare section */
00065 #line 23 "binary.pgc"
00066 
00067   int i;
00068 
00069   ECPGdebug (1, stderr);
00070 
00071   empl.idnum = 1;
00072   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
00073 #line 29 "binary.pgc"
00074 
00075   if (sqlca.sqlcode)
00076     {
00077       printf ("connect error = %ld\n", sqlca.sqlcode);
00078       exit (sqlca.sqlcode);
00079     }
00080 
00081   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set bytea_output = escape", ECPGt_EOIT, ECPGt_EORT);}
00082 #line 36 "binary.pgc"
00083 
00084   if (sqlca.sqlcode)
00085     {
00086       printf ("set bytea_output error = %ld\n", sqlca.sqlcode);
00087       exit (sqlca.sqlcode);
00088     }
00089 
00090   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea )", ECPGt_EOIT, ECPGt_EORT);}
00091 #line 44 "binary.pgc"
00092 
00093   if (sqlca.sqlcode)
00094     {
00095       printf ("create error = %ld\n", sqlca.sqlcode);
00096       exit (sqlca.sqlcode);
00097     }
00098 
00099   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into empl values ( 1 , 'first user' , 320 , $1  )", 
00100     ECPGt_char,&(data),(long)0,(long)1,(1)*sizeof(char), 
00101     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
00102 #line 51 "binary.pgc"
00103 
00104   if (sqlca.sqlcode)
00105     {
00106       printf ("insert error = %ld\n", sqlca.sqlcode);
00107       exit (sqlca.sqlcode);
00108     }
00109 
00110   ECPGset_var( 0, &( empl.idnum ), __LINE__);\
00111  /* declare C cursor for select name , accs , byte from empl where idnum = $1  */
00112 #line 58 "binary.pgc"
00113 
00114   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select name , accs , byte from empl where idnum = $1 ", 
00115     ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
00116     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
00117 #line 59 "binary.pgc"
00118 
00119   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, 
00120     ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), 
00121     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00122     ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), 
00123     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00124     ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), 
00125     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00126 #line 60 "binary.pgc"
00127 
00128   if (sqlca.sqlcode)
00129     {
00130       printf ("fetch error = %ld\n", sqlca.sqlcode);
00131       exit (sqlca.sqlcode);
00132     }
00133 
00134   printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
00135 
00136   memset(empl.name, 0, 21L);
00137   ECPGset_var( 1, &( empl.idnum ), __LINE__);\
00138  /* declare B binary cursor for select name , accs , byte from empl where idnum = $1  */
00139 #line 70 "binary.pgc"
00140 
00141   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ", 
00142     ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
00143     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
00144 #line 71 "binary.pgc"
00145 
00146   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch B", ECPGt_EOIT, 
00147     ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), 
00148     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00149     ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), 
00150     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
00151     ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), 
00152     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00153 #line 72 "binary.pgc"
00154 
00155   if (sqlca.sqlcode)
00156     {
00157       printf ("fetch error = %ld\n", sqlca.sqlcode);
00158       exit (sqlca.sqlcode);
00159     }
00160 
00161   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);}
00162 #line 79 "binary.pgc"
00163 
00164 
00165   /* do not print a.accs because big/little endian will have different outputs here */
00166   printf ("name=%s, byte=", empl.name);
00167   for (i=0; i<4; i++)
00168     printf("(%o)", (unsigned char)empl.byte[i]);
00169   printf("\n");
00170 
00171   ECPGset_var( 2, &( empl.idnum ), __LINE__);\
00172  /* declare A binary cursor for select byte from empl where idnum = $1  */
00173 #line 87 "binary.pgc"
00174 
00175   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ", 
00176     ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
00177     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
00178 #line 88 "binary.pgc"
00179 
00180   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch A", ECPGt_EOIT, 
00181     ECPGt_char,&(pointer),(long)0,(long)1,(1)*sizeof(char), 
00182     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
00183 #line 89 "binary.pgc"
00184 
00185   if (sqlca.sqlcode)
00186     {
00187       printf ("fetch error = %ld\n", sqlca.sqlcode);
00188       exit (sqlca.sqlcode);
00189     }
00190 
00191   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);}
00192 #line 96 "binary.pgc"
00193 
00194 
00195   printf ("pointer=");
00196   for (i=0; i<4; i++)
00197     printf("(%o)", (unsigned char)pointer[i]);
00198   printf("\n");
00199   free(pointer);
00200 
00201   { ECPGdisconnect(__LINE__, "CURRENT");}
00202 #line 104 "binary.pgc"
00203 
00204   exit (0);
00205 }