1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "binary.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 
13 
14 #line 1 "regression.h"
15 
16 
17 
18 
19 
20 
21 #line 4 "binary.pgc"
22 
23 
24 /* exec sql begin declare section */
25 
26 
27 
28 
29 
30 
31 
32 struct TBempl {
33 #line 9 "binary.pgc"
34  long idnum ;
35 
36 #line 10 "binary.pgc"
37  char name [ 21 ] ;
38 
39 #line 11 "binary.pgc"
40  short accs ;
41 
42 #line 12 "binary.pgc"
43  char byte [ 20 ] ;
44  } ;/* exec sql end declare section */
45 #line 14 "binary.pgc"
46 
47 
48 int
main(void)49 main (void)
50 {
51   /* exec sql begin declare section */
52 
53 
54 
55 
56 #line 20 "binary.pgc"
57  struct TBempl empl ;
58 
59 #line 21 "binary.pgc"
60  char * pointer = NULL ;
61 
62 #line 22 "binary.pgc"
63  char * data = "\\001\\155\\000\\212" ;
64 /* exec sql end declare section */
65 #line 23 "binary.pgc"
66 
67   int i;
68 
69   ECPGdebug (1, stderr);
70 
71   empl.idnum = 1;
72   { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
73 #line 29 "binary.pgc"
74 
75   if (sqlca.sqlcode)
76     {
77       printf ("connect error = %ld\n", sqlca.sqlcode);
78       exit (sqlca.sqlcode);
79     }
80 
81   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set bytea_output = escape", ECPGt_EOIT, ECPGt_EORT);}
82 #line 36 "binary.pgc"
83 
84   if (sqlca.sqlcode)
85     {
86       printf ("set bytea_output error = %ld\n", sqlca.sqlcode);
87       exit (sqlca.sqlcode);
88     }
89 
90   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea )", ECPGt_EOIT, ECPGt_EORT);}
91 #line 44 "binary.pgc"
92 
93   if (sqlca.sqlcode)
94     {
95       printf ("create error = %ld\n", sqlca.sqlcode);
96       exit (sqlca.sqlcode);
97     }
98 
99   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into empl values ( 1 , 'first user' , 320 , $1  )",
100 	ECPGt_char,&(data),(long)0,(long)1,(1)*sizeof(char),
101 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
102 #line 51 "binary.pgc"
103 
104   if (sqlca.sqlcode)
105     {
106       printf ("insert error = %ld\n", sqlca.sqlcode);
107       exit (sqlca.sqlcode);
108     }
109 
110   ECPGset_var( 0, &( empl.idnum ), __LINE__);\
111  /* declare C cursor for select name , accs , byte from empl where idnum = $1  */
112 #line 58 "binary.pgc"
113 
114   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select name , accs , byte from empl where idnum = $1 ",
115 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long),
116 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
117 #line 59 "binary.pgc"
118 
119   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
120 	ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char),
121 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
122 	ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short),
123 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
124 	ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char),
125 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
126 #line 60 "binary.pgc"
127 
128   if (sqlca.sqlcode)
129     {
130       printf ("fetch error = %ld\n", sqlca.sqlcode);
131       exit (sqlca.sqlcode);
132     }
133 
134   printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
135 
136   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);}
137 #line 69 "binary.pgc"
138 
139 
140   memset(empl.name, 0, 21L);
141   ECPGset_var( 1, &( empl.idnum ), __LINE__);\
142  /* declare B binary cursor for select name , accs , byte from empl where idnum = $1  */
143 #line 72 "binary.pgc"
144 
145   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ",
146 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long),
147 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
148 #line 73 "binary.pgc"
149 
150   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch B", ECPGt_EOIT,
151 	ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char),
152 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
153 	ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short),
154 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
155 	ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char),
156 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
157 #line 74 "binary.pgc"
158 
159   if (sqlca.sqlcode)
160     {
161       printf ("fetch error = %ld\n", sqlca.sqlcode);
162       exit (sqlca.sqlcode);
163     }
164 
165   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);}
166 #line 81 "binary.pgc"
167 
168 
169   /* do not print a.accs because big/little endian will have different outputs here */
170   printf ("name=%s, byte=", empl.name);
171   for (i=0; i<4; i++)
172 	printf("(%o)", (unsigned char)empl.byte[i]);
173   printf("\n");
174 
175   ECPGset_var( 2, &( empl.idnum ), __LINE__);\
176  /* declare A binary cursor for select byte from empl where idnum = $1  */
177 #line 89 "binary.pgc"
178 
179   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ",
180 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long),
181 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
182 #line 90 "binary.pgc"
183 
184   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch A", ECPGt_EOIT,
185 	ECPGt_char,&(pointer),(long)0,(long)1,(1)*sizeof(char),
186 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
187 #line 91 "binary.pgc"
188 
189   if (sqlca.sqlcode)
190     {
191       printf ("fetch error = %ld\n", sqlca.sqlcode);
192       exit (sqlca.sqlcode);
193     }
194 
195   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);}
196 #line 98 "binary.pgc"
197 
198 
199   printf ("pointer=");
200   for (i=0; i<4; i++)
201 	printf("(%o)", (unsigned char)pointer[i]);
202   printf("\n");
203   free(pointer);
204 
205   { ECPGdisconnect(__LINE__, "CURRENT");}
206 #line 106 "binary.pgc"
207 
208   exit (0);
209 }
210