PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sql-quote.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for sql-quote.c:

Go to the source code of this file.

Macros

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

Functions

int main ()
 

Macro Definition Documentation

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

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

Referenced by main().

Function Documentation

int main ( void  )

Definition at line 25 of file sql-quote.c.

References ECPG_NOT_FOUND, ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), i, NULL, sqlca, and sqlprint().

25  {
26  /* exec sql begin declare section */
27 
28 
29 
30 #line 9 "quote.pgc"
31  char var [ 25 ] ;
32 
33 #line 10 "quote.pgc"
34  int i ;
35 /* exec sql end declare section */
36 #line 11 "quote.pgc"
37 
38 
39  ECPGdebug(1, stderr);
40  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
41 #line 14 "quote.pgc"
42 
43 
44  { ECPGsetcommit(__LINE__, "on", NULL);}
45 #line 16 "quote.pgc"
46 
47  /* exec sql whenever sql_warning sqlprint ; */
48 #line 17 "quote.pgc"
49 
50  /* exec sql whenever sqlerror sqlprint ; */
51 #line 18 "quote.pgc"
52 
53 
54  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table \"My_Table\" ( Item1 int , Item2 text )", ECPGt_EOIT, ECPGt_EORT);
55 #line 20 "quote.pgc"
56 
57 if (sqlca.sqlwarn[0] == 'W') sqlprint();
58 #line 20 "quote.pgc"
59 
60 if (sqlca.sqlcode < 0) sqlprint();}
61 #line 20 "quote.pgc"
62 
63 
64  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
65 #line 22 "quote.pgc"
66 
67 if (sqlca.sqlwarn[0] == 'W') sqlprint();
68 #line 22 "quote.pgc"
69 
70 if (sqlca.sqlcode < 0) sqlprint();}
71 #line 22 "quote.pgc"
72 
73 
74  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show standard_conforming_strings", ECPGt_EOIT,
75  ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
76  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
77 #line 24 "quote.pgc"
78 
79 if (sqlca.sqlwarn[0] == 'W') sqlprint();
80 #line 24 "quote.pgc"
81 
82 if (sqlca.sqlcode < 0) sqlprint();}
83 #line 24 "quote.pgc"
84 
85  printf("Standard conforming strings: %s\n", var);
86 
87  /* this is a\\b actually */
88  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into \"My_Table\" values ( 1 , 'a\\\\\\\\b' )", ECPGt_EOIT, ECPGt_EORT);
89 #line 28 "quote.pgc"
90 
91 if (sqlca.sqlwarn[0] == 'W') sqlprint();
92 #line 28 "quote.pgc"
93 
94 if (sqlca.sqlcode < 0) sqlprint();}
95 #line 28 "quote.pgc"
96 
97  /* this is a\\b */
98  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into \"My_Table\" values ( 1 , E'a\\\\\\\\b' )", ECPGt_EOIT, ECPGt_EORT);
99 #line 30 "quote.pgc"
100 
101 if (sqlca.sqlwarn[0] == 'W') sqlprint();
102 #line 30 "quote.pgc"
103 
104 if (sqlca.sqlcode < 0) sqlprint();}
105 #line 30 "quote.pgc"
106 
107 
108  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to on", ECPGt_EOIT, ECPGt_EORT);
109 #line 32 "quote.pgc"
110 
111 if (sqlca.sqlwarn[0] == 'W') sqlprint();
112 #line 32 "quote.pgc"
113 
114 if (sqlca.sqlcode < 0) sqlprint();}
115 #line 32 "quote.pgc"
116 
117 
118  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show standard_conforming_strings", ECPGt_EOIT,
119  ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
120  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
121 #line 34 "quote.pgc"
122 
123 if (sqlca.sqlwarn[0] == 'W') sqlprint();
124 #line 34 "quote.pgc"
125 
126 if (sqlca.sqlcode < 0) sqlprint();}
127 #line 34 "quote.pgc"
128 
129  printf("Standard conforming strings: %s\n", var);
130 
131  /* this is a\\\\b actually */
132  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into \"My_Table\" values ( 2 , 'a\\\\\\\\b' )", ECPGt_EOIT, ECPGt_EORT);
133 #line 38 "quote.pgc"
134 
135 if (sqlca.sqlwarn[0] == 'W') sqlprint();
136 #line 38 "quote.pgc"
137 
138 if (sqlca.sqlcode < 0) sqlprint();}
139 #line 38 "quote.pgc"
140 
141  /* this is a\\b */
142  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into \"My_Table\" values ( 2 , E'a\\\\\\\\b' )", ECPGt_EOIT, ECPGt_EORT);
143 #line 40 "quote.pgc"
144 
145 if (sqlca.sqlwarn[0] == 'W') sqlprint();
146 #line 40 "quote.pgc"
147 
148 if (sqlca.sqlcode < 0) sqlprint();}
149 #line 40 "quote.pgc"
150 
151 
152  { ECPGtrans(__LINE__, NULL, "begin");
153 #line 42 "quote.pgc"
154 
155 if (sqlca.sqlwarn[0] == 'W') sqlprint();
156 #line 42 "quote.pgc"
157 
158 if (sqlca.sqlcode < 0) sqlprint();}
159 #line 42 "quote.pgc"
160 
161  /* declare C cursor for select * from \"My_Table\" */
162 #line 43 "quote.pgc"
163 
164 
165  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select * from \"My_Table\"", ECPGt_EOIT, ECPGt_EORT);
166 #line 45 "quote.pgc"
167 
168 if (sqlca.sqlwarn[0] == 'W') sqlprint();
169 #line 45 "quote.pgc"
170 
171 if (sqlca.sqlcode < 0) sqlprint();}
172 #line 45 "quote.pgc"
173 
174 
175  /* exec sql whenever not found break ; */
176 #line 47 "quote.pgc"
177 
178 
179  while (true)
180  {
181  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
182  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
183  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
184  ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
185  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
186 #line 51 "quote.pgc"
187 
188 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
189 #line 51 "quote.pgc"
190 
191 if (sqlca.sqlwarn[0] == 'W') sqlprint();
192 #line 51 "quote.pgc"
193 
194 if (sqlca.sqlcode < 0) sqlprint();}
195 #line 51 "quote.pgc"
196 
197  printf("value: %d %s\n", i, var);
198  }
199 
200  { ECPGtrans(__LINE__, NULL, "rollback");
201 #line 55 "quote.pgc"
202 
203 if (sqlca.sqlwarn[0] == 'W') sqlprint();
204 #line 55 "quote.pgc"
205 
206 if (sqlca.sqlcode < 0) sqlprint();}
207 #line 55 "quote.pgc"
208 
209  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table \"My_Table\"", ECPGt_EOIT, ECPGt_EORT);
210 #line 56 "quote.pgc"
211 
212 if (sqlca.sqlwarn[0] == 'W') sqlprint();
213 #line 56 "quote.pgc"
214 
215 if (sqlca.sqlcode < 0) sqlprint();}
216 #line 56 "quote.pgc"
217 
218 
219  { ECPGdisconnect(__LINE__, "ALL");
220 #line 58 "quote.pgc"
221 
222 if (sqlca.sqlwarn[0] == 'W') sqlprint();
223 #line 58 "quote.pgc"
224 
225 if (sqlca.sqlcode < 0) sqlprint();}
226 #line 58 "quote.pgc"
227 
228 
229  return 0;
230 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
#define ECPGdebug(X, Y)
Definition: sql-quote.c:7
#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:2030
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 ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
void sqlprint(void)
Definition: error.c:336
#define NULL
Definition: c.h:226
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:165
int i