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 49 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, and sqlca.

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 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
#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:2037
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:524
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