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

Go to the source code of this file.

Data Structures

struct  sqlca_t
 

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 
#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 
#define POSTGRES_SQLCA_H
 
#define PGDLLIMPORT
 
#define SQLERRMC_LEN   150
 
#define sqlca   (*ECPGget_sqlca())
 

Functions

struct sqlca_tECPGget_sqlca (void)
 
int main (void)
 

Macro Definition Documentation

◆ ECPGdebug [1/2]

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

Definition at line 22 of file sql-define.c.

◆ ECPGdebug [2/2]

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

Definition at line 22 of file sql-define.c.

◆ PGDLLIMPORT

#define PGDLLIMPORT

Definition at line 34 of file sql-define.c.

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

Definition at line 28 of file sql-define.c.

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

Definition at line 85 of file sql-define.c.

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 38 of file sql-define.c.

Function Documentation

◆ ECPGget_sqlca()

struct sqlca_t* ECPGget_sqlca ( void  )

Definition at line 108 of file misc.c.

109 {
110  struct sqlca_t *sqlca;
111 
112  pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
113 
115  if (sqlca == NULL)
116  {
117  sqlca = malloc(sizeof(struct sqlca_t));
118  if (sqlca == NULL)
119  return NULL;
122  }
123  return sqlca;
124 }
#define malloc(a)
Definition: header.h:50
static pthread_key_t sqlca_key
Definition: misc.c:58
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
static void ecpg_sqlca_key_init(void)
Definition: misc.c:102
static pthread_once_t sqlca_key_once
Definition: misc.c:59
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

◆ main()

int main ( void  )

Definition at line 110 of file sql-define.c.

111 {
112  /* exec sql begin declare section */
113 
114 
115 
116 #line 10 "define.pgc"
117  int i ;
118 
119 #line 11 "define.pgc"
120  char s [ 200 ] ;
121 /* exec sql end declare section */
122 #line 12 "define.pgc"
123 
124 
125  ECPGdebug(1, stderr);
126 
127  /* exec sql whenever sqlerror do sqlprint ( ) ; */
128 #line 16 "define.pgc"
129 
130  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
131 #line 17 "define.pgc"
132 
133 if (sqlca.sqlcode < 0) sqlprint ( );}
134 #line 17 "define.pgc"
135 
136 
137  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);
138 #line 19 "define.pgc"
139 
140 if (sqlca.sqlcode < 0) sqlprint ( );}
141 #line 19 "define.pgc"
142 
143  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 29 , 'abcdef' )", ECPGt_EOIT, ECPGt_EORT);
144 #line 20 "define.pgc"
145 
146 if (sqlca.sqlcode < 0) sqlprint ( );}
147 #line 20 "define.pgc"
148 
149 
150 
151  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'defined' )", ECPGt_EOIT, ECPGt_EORT);
152 #line 23 "define.pgc"
153 
154 if (sqlca.sqlcode < 0) sqlprint ( );}
155 #line 23 "define.pgc"
156 
157 
158 
159 
160 
161 
162 
163 
164  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'someothervar not defined' )", ECPGt_EOIT, ECPGt_EORT);
165 #line 31 "define.pgc"
166 
167 if (sqlca.sqlcode < 0) sqlprint ( );}
168 #line 31 "define.pgc"
169 
170 
171 
172 
173 
174  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select 1 , 29 :: text || '-' || 'abcdef'", ECPGt_EOIT,
175  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
176  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
177  ECPGt_char,(s),(long)200,(long)1,(200)*sizeof(char),
178  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
179 #line 36 "define.pgc"
180 
181 if (sqlca.sqlcode < 0) sqlprint ( );}
182 #line 36 "define.pgc"
183 
184 
185  printf("i: %d, s: %s\n", i, s);
186 
187 
188 
189  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 29 , 'no string' )", ECPGt_EOIT, ECPGt_EORT);
190 #line 42 "define.pgc"
191 
192 if (sqlca.sqlcode < 0) sqlprint ( );}
193 #line 42 "define.pgc"
194 
195 
196 
197  /* no value */
198 
199 
200 
201 
202 
203 
204 
205  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set TIMEZONE to 'UTC'", ECPGt_EOIT, ECPGt_EORT);
206 #line 53 "define.pgc"
207 
208 if (sqlca.sqlcode < 0) sqlprint ( );}
209 #line 53 "define.pgc"
210 
211 
212 
213  /* test handling of a macro defined on the command line */
214  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select 123", ECPGt_EOIT,
215  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
216  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
217 #line 57 "define.pgc"
218 
219 if (sqlca.sqlcode < 0) sqlprint ( );}
220 #line 57 "define.pgc"
221 
222  printf("original CMDLINESYM: %d\n", i);
223 
224 
225 
226  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select 42", ECPGt_EOIT,
227  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
228  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
229 #line 62 "define.pgc"
230 
231 if (sqlca.sqlcode < 0) sqlprint ( );}
232 #line 62 "define.pgc"
233 
234  printf("redefined CMDLINESYM: %d\n", i);
235 
236 
237 
238  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select 43", ECPGt_EOIT,
239  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
240  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
241 #line 67 "define.pgc"
242 
243 if (sqlca.sqlcode < 0) sqlprint ( );}
244 #line 67 "define.pgc"
245 
246  printf("redefined CMDLINESYM: %d\n", i);
247 
248 
249 
250 
251 
252 
253 
254  /* this macro should not have carried over from define_prelim.pgc */
255 
256 
257 
258 
259  { ECPGdisconnect(__LINE__, "CURRENT");
260 #line 81 "define.pgc"
261 
262 if (sqlca.sqlcode < 0) sqlprint ( );}
263 #line 81 "define.pgc"
264 
265  return 0;
266 }
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_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_char
Definition: ecpgtype.h:43
void sqlprint(void)
Definition: error.c:334
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
int i
Definition: isn.c:73
#define printf(...)
Definition: port.h:244
#define sqlca
Definition: sql-define.c:85
#define ECPGdebug(X, Y)
Definition: sql-define.c:22

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGst_normal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, i, printf, sqlca, and sqlprint().