PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 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

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

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

Referenced by main().

#define PGDLLIMPORT

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

#define POSTGRES_SQLCA_H

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

#define sqlca   (*ECPGget_sqlca())

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

Referenced by main().

#define SQLERRMC_LEN   150

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

Function Documentation

struct sqlca_t* ECPGget_sqlca ( void  )

Definition at line 142 of file misc.c.

143 {
144 #ifdef ENABLE_THREAD_SAFETY
145  struct sqlca_t *sqlca;
146 
147  pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
148 
149  sqlca = pthread_getspecific(sqlca_key);
150  if (sqlca == NULL)
151  {
152  sqlca = malloc(sizeof(struct sqlca_t));
153  if (sqlca == NULL)
154  return NULL;
155  ecpg_init_sqlca(sqlca);
156  pthread_setspecific(sqlca_key, sqlca);
157  }
158  return sqlca;
159 #else
160  return &sqlca;
161 #endif
162 }
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
#define malloc(a)
Definition: header.h:50
Definition: sqlca.h:19
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
static struct sqlca_t sqlca
Definition: misc.c:63
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
int main ( void  )

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

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

96 {
97  /* exec sql begin declare section */
98 
99 
100 
101 #line 10 "define.pgc"
102  int i ;
103 
104 #line 11 "define.pgc"
105  char s [ 200 ] ;
106 /* exec sql end declare section */
107 #line 12 "define.pgc"
108 
109 
110  ECPGdebug(1, stderr);
111 
112  /* exec sql whenever sqlerror do sqlprint ( ) ; */
113 #line 16 "define.pgc"
114 
115  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
116 #line 17 "define.pgc"
117 
118 if (sqlca.sqlcode < 0) sqlprint ( );}
119 #line 17 "define.pgc"
120 
121 
122  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);
123 #line 19 "define.pgc"
124 
125 if (sqlca.sqlcode < 0) sqlprint ( );}
126 #line 19 "define.pgc"
127 
128  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 29 , 'abcdef' )", ECPGt_EOIT, ECPGt_EORT);
129 #line 20 "define.pgc"
130 
131 if (sqlca.sqlcode < 0) sqlprint ( );}
132 #line 20 "define.pgc"
133 
134 
135 
136  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'defined' )", ECPGt_EOIT, ECPGt_EORT);
137 #line 23 "define.pgc"
138 
139 if (sqlca.sqlcode < 0) sqlprint ( );}
140 #line 23 "define.pgc"
141 
142 
143 
144 
145 
146 
147 
148 
149  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'someothervar not defined' )", ECPGt_EOIT, ECPGt_EORT);
150 #line 31 "define.pgc"
151 
152 if (sqlca.sqlcode < 0) sqlprint ( );}
153 #line 31 "define.pgc"
154 
155 
156 
157 
158 
159  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select 1 , 29 :: text || '-' || 'abcdef'", ECPGt_EOIT,
160  ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
161  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
162  ECPGt_char,(s),(long)200,(long)1,(200)*sizeof(char),
163  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
164 #line 36 "define.pgc"
165 
166 if (sqlca.sqlcode < 0) sqlprint ( );}
167 #line 36 "define.pgc"
168 
169 
170  printf("i: %d, s: %s\n", i, s);
171 
172 
173 
174  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 29 , 'no string' )", ECPGt_EOIT, ECPGt_EORT);
175 #line 42 "define.pgc"
176 
177 if (sqlca.sqlcode < 0) sqlprint ( );}
178 #line 42 "define.pgc"
179 
180 
181 
182  /* no value */
183 
184 
185 
186 
187 
188 
189 
190  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set TIMEZONE to 'UTC'", ECPGt_EOIT, ECPGt_EORT);
191 #line 53 "define.pgc"
192 
193 if (sqlca.sqlcode < 0) sqlprint ( );}
194 #line 53 "define.pgc"
195 
196 
197 
198  { ECPGdisconnect(__LINE__, "CURRENT");
199 #line 56 "define.pgc"
200 
201 if (sqlca.sqlcode < 0) sqlprint ( );}
202 #line 56 "define.pgc"
203 
204  return 0;
205 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
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
#define sqlca
Definition: sql-define.c:70
#define ECPGdebug(X, Y)
Definition: sql-define.c:7
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
void sqlprint(void)
Definition: error.c:336
int i