PostgreSQL Source Code  git master
sql-binary.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for sql-binary.c:

Go to the source code of this file.

Data Structures

struct  TBempl
 

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file sql-binary.c.

Referenced by main().

Function Documentation

◆ main()

int main ( void  )

Definition at line 53 of file sql-binary.c.

References TBempl::accs, TBempl::byte, ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGset_var(), ECPGst_normal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_long, ECPGt_NO_INDICATOR, ECPGt_short, free, i, TBempl::idnum, TBempl::name, printf, and sqlca.

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:684
#define sqlca
Definition: sqlca.h:59
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:2279
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:531
#define printf(...)
Definition: port.h:198
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
#define ECPGdebug(X, Y)
Definition: sql-binary.c:7
#define free(a)
Definition: header.h:65
int i