PostgreSQL Source Code  git master
sql-binary.c
Go to the documentation of this file.
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 /* exec sql whenever sqlerror stop ; */
49 #line 16 "binary.pgc"
50 
51 
52 int
53 main (void)
54 {
55  /* exec sql begin declare section */
56 
57 
58 
59 
60 #line 22 "binary.pgc"
61  struct TBempl empl ;
62 
63 #line 23 "binary.pgc"
64  char * pointer = NULL ;
65 
66 #line 24 "binary.pgc"
67  char * data = "\\001\\155\\000\\212" ;
68 /* exec sql end declare section */
69 #line 25 "binary.pgc"
70 
71  int i;
72 
73  ECPGdebug (1, stderr);
74 
75  empl.idnum = 1;
76  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
77 #line 31 "binary.pgc"
78 
79 if (sqlca.sqlcode < 0) exit (1);}
80 #line 31 "binary.pgc"
81 
82  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set bytea_output = escape", ECPGt_EOIT, ECPGt_EORT);
83 #line 32 "binary.pgc"
84 
85 if (sqlca.sqlcode < 0) exit (1);}
86 #line 32 "binary.pgc"
87 
88  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea )", ECPGt_EOIT, ECPGt_EORT);
89 #line 34 "binary.pgc"
90 
91 if (sqlca.sqlcode < 0) exit (1);}
92 #line 34 "binary.pgc"
93 
94  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into empl values ( 1 , 'first user' , 320 , $1 )",
95  ECPGt_char,&(data),(long)0,(long)1,(1)*sizeof(char),
96  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
97 #line 35 "binary.pgc"
98 
99 if (sqlca.sqlcode < 0) exit (1);}
100 #line 35 "binary.pgc"
101 
102  ECPGset_var( 0, &( empl.idnum ), __LINE__);\
103  /* declare C cursor for select name , accs , byte from empl where idnum = $1 */
104 #line 36 "binary.pgc"
105 
106 if (sqlca.sqlcode < 0) exit (1);
107 #line 36 "binary.pgc"
108 
109 #line 36 "binary.pgc"
110 
111  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select name , accs , byte from empl where idnum = $1 ",
112  ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long),
113  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
114 #line 37 "binary.pgc"
115 
116 if (sqlca.sqlcode < 0) exit (1);}
117 #line 37 "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 38 "binary.pgc"
127 
128 if (sqlca.sqlcode < 0) exit (1);}
129 #line 38 "binary.pgc"
130 
131  printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
132 
133  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
134 #line 41 "binary.pgc"
135 
136 if (sqlca.sqlcode < 0) exit (1);}
137 #line 41 "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 44 "binary.pgc"
144 
145 if (sqlca.sqlcode < 0) exit (1);
146 #line 44 "binary.pgc"
147 
148 #line 44 "binary.pgc"
149 
150  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ",
151  ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long),
152  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
153 #line 45 "binary.pgc"
154 
155 if (sqlca.sqlcode < 0) exit (1);}
156 #line 45 "binary.pgc"
157 
158  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch B", ECPGt_EOIT,
159  ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char),
160  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
161  ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short),
162  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
163  ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char),
164  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
165 #line 46 "binary.pgc"
166 
167 if (sqlca.sqlcode < 0) exit (1);}
168 #line 46 "binary.pgc"
169 
170  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);
171 #line 47 "binary.pgc"
172 
173 if (sqlca.sqlcode < 0) exit (1);}
174 #line 47 "binary.pgc"
175 
176 
177  /* do not print a.accs because big/little endian will have different outputs here */
178  printf ("name=%s, byte=", empl.name);
179  for (i=0; i<4; i++)
180  printf("(%o)", (unsigned char)empl.byte[i]);
181  printf("\n");
182 
183  ECPGset_var( 2, &( empl.idnum ), __LINE__);\
184  /* declare A binary cursor for select byte from empl where idnum = $1 */
185 #line 55 "binary.pgc"
186 
187 if (sqlca.sqlcode < 0) exit (1);
188 #line 55 "binary.pgc"
189 
190 #line 55 "binary.pgc"
191 
192  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ",
193  ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long),
194  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
195 #line 56 "binary.pgc"
196 
197 if (sqlca.sqlcode < 0) exit (1);}
198 #line 56 "binary.pgc"
199 
200  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch A", ECPGt_EOIT,
201  ECPGt_char,&(pointer),(long)0,(long)1,(1)*sizeof(char),
202  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
203 #line 57 "binary.pgc"
204 
205 if (sqlca.sqlcode < 0) exit (1);}
206 #line 57 "binary.pgc"
207 
208  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);
209 #line 58 "binary.pgc"
210 
211 if (sqlca.sqlcode < 0) exit (1);}
212 #line 58 "binary.pgc"
213 
214 
215  if (pointer) {
216  printf ("pointer=");
217  for (i=0; i<4; i++)
218  printf("(%o)", (unsigned char)pointer[i]);
219  printf("\n");
220  free(pointer);
221  }
222 
223  { ECPGdisconnect(__LINE__, "CURRENT");
224 #line 68 "binary.pgc"
225 
226 if (sqlca.sqlcode < 0) exit (1);}
227 #line 68 "binary.pgc"
228 
229  exit (0);
230 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:673
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_char
Definition: ecpgtype.h:43
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2277
#define free(a)
Definition: header.h:65
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:519
int i
Definition: isn.c:73
exit(1)
const void * data
#define printf(...)
Definition: port.h:244
int main(void)
Definition: sql-binary.c:53
#define ECPGdebug(X, Y)
Definition: sql-binary.c:7
#define sqlca
Definition: sqlca.h:59
mmChar name[21]
Definition: preproc-type.c:71
char byte[20]
Definition: sql-binary.c:43
access accs
Definition: preproc-type.c:74
short accs
Definition: sql-binary.c:40
mmInteger idnum
Definition: preproc-type.c:68
long idnum
Definition: sql-binary.c:34