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

Referenced by main().

#define PGDLLIMPORT

Definition at line 20 of file sql-dynalloc2.c.

#define POSTGRES_SQLCA_H

Definition at line 14 of file sql-dynalloc2.c.

#define sqlca   (*ECPGget_sqlca())

Definition at line 71 of file sql-dynalloc2.c.

Referenced by main().

#define SQLERRMC_LEN   150

Definition at line 24 of file sql-dynalloc2.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 94 of file sql-dynalloc2.c.

References ECPGallocate_desc(), ECPGconnect(), ECPGd_data, ECPGd_EODT, ECPGd_indicator, ECPGdeallocate_desc(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGfree_auto_mem(), ECPGget_desc(), ECPGget_desc_header(), ECPGst_normal, ECPGt_char, ECPGt_descriptor, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), i, sqlca, and sqlprint().

95 {
96  /* exec sql begin declare section */
97 
98 
99 
100 
101 
102 
103 #line 9 "dynalloc2.pgc"
104  int * ip1 = 0 ;
105 
106 #line 10 "dynalloc2.pgc"
107  char ** cp2 = 0 ;
108 
109 #line 11 "dynalloc2.pgc"
110  int * ipointer1 = 0 ;
111 
112 #line 12 "dynalloc2.pgc"
113  int * ipointer2 = 0 ;
114 
115 #line 13 "dynalloc2.pgc"
116  int colnum ;
117 /* exec sql end declare section */
118 #line 14 "dynalloc2.pgc"
119 
120  int i;
121 
122  ECPGdebug(1, stderr);
123 
124  /* exec sql whenever sqlerror do sqlprint ( ) ; */
125 #line 19 "dynalloc2.pgc"
126 
127  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
128 #line 20 "dynalloc2.pgc"
129 
130 if (sqlca.sqlcode < 0) sqlprint ( );}
131 #line 20 "dynalloc2.pgc"
132 
133 
134  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to postgres", ECPGt_EOIT, ECPGt_EORT);
135 #line 22 "dynalloc2.pgc"
136 
137 if (sqlca.sqlcode < 0) sqlprint ( );}
138 #line 22 "dynalloc2.pgc"
139 
140 
141  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);
142 #line 24 "dynalloc2.pgc"
143 
144 if (sqlca.sqlcode < 0) sqlprint ( );}
145 #line 24 "dynalloc2.pgc"
146 
147  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 1 , 'one' )", ECPGt_EOIT, ECPGt_EORT);
148 #line 25 "dynalloc2.pgc"
149 
150 if (sqlca.sqlcode < 0) sqlprint ( );}
151 #line 25 "dynalloc2.pgc"
152 
153  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 2 , 'two' )", ECPGt_EOIT, ECPGt_EORT);
154 #line 26 "dynalloc2.pgc"
155 
156 if (sqlca.sqlcode < 0) sqlprint ( );}
157 #line 26 "dynalloc2.pgc"
158 
159  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'three' )", ECPGt_EOIT, ECPGt_EORT);
160 #line 27 "dynalloc2.pgc"
161 
162 if (sqlca.sqlcode < 0) sqlprint ( );}
163 #line 27 "dynalloc2.pgc"
164 
165  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 4 , 'four' )", ECPGt_EOIT, ECPGt_EORT);
166 #line 28 "dynalloc2.pgc"
167 
168 if (sqlca.sqlcode < 0) sqlprint ( );}
169 #line 28 "dynalloc2.pgc"
170 
171  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 5 , null )", ECPGt_EOIT, ECPGt_EORT);
172 #line 29 "dynalloc2.pgc"
173 
174 if (sqlca.sqlcode < 0) sqlprint ( );}
175 #line 29 "dynalloc2.pgc"
176 
177  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , null )", ECPGt_EOIT, ECPGt_EORT);
178 #line 30 "dynalloc2.pgc"
179 
180 if (sqlca.sqlcode < 0) sqlprint ( );}
181 #line 30 "dynalloc2.pgc"
182 
183 
184  ECPGallocate_desc(__LINE__, "mydesc");
185 #line 32 "dynalloc2.pgc"
186 
187 if (sqlca.sqlcode < 0) sqlprint ( );
188 #line 32 "dynalloc2.pgc"
189 
190  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from test", ECPGt_EOIT,
191  ECPGt_descriptor, "mydesc", 1L, 1L, 1L,
192  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
193 #line 33 "dynalloc2.pgc"
194 
195 if (sqlca.sqlcode < 0) sqlprint ( );}
196 #line 33 "dynalloc2.pgc"
197 
198  { ECPGget_desc_header(__LINE__, "mydesc", &(colnum));
199 
200 #line 34 "dynalloc2.pgc"
201 
202 if (sqlca.sqlcode < 0) sqlprint ( );}
203 #line 34 "dynalloc2.pgc"
204 
205  { ECPGget_desc(__LINE__, "mydesc", 1,ECPGd_indicator,
206  ECPGt_int,&(ipointer1),(long)1,(long)0,sizeof(int), ECPGd_data,
207  ECPGt_int,&(ip1),(long)1,(long)0,sizeof(int), ECPGd_EODT);
208 
209 #line 35 "dynalloc2.pgc"
210 
211 if (sqlca.sqlcode < 0) sqlprint ( );}
212 #line 35 "dynalloc2.pgc"
213 
214  { ECPGget_desc(__LINE__, "mydesc", 2,ECPGd_indicator,
215  ECPGt_int,&(ipointer2),(long)1,(long)0,sizeof(int), ECPGd_data,
216  ECPGt_char,&(cp2),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
217 
218 #line 36 "dynalloc2.pgc"
219 
220 if (sqlca.sqlcode < 0) sqlprint ( );}
221 #line 36 "dynalloc2.pgc"
222 
223 
224  printf("Result (%d columns):\n", colnum);
225  for (i=0;i < sqlca.sqlerrd[2];++i)
226  {
227  if (ipointer1[i]) printf("NULL, ");
228  else printf("%d, ",ip1[i]);
229 
230  if (ipointer2[i]) printf("NULL, ");
231  else printf("'%s', ",cp2[i]);
232  printf("\n");
233  }
235  printf("\n");
236 
237  ECPGdeallocate_desc(__LINE__, "mydesc");
238 #line 51 "dynalloc2.pgc"
239 
240 if (sqlca.sqlcode < 0) sqlprint ( );
241 #line 51 "dynalloc2.pgc"
242 
243  { ECPGtrans(__LINE__, NULL, "rollback");
244 #line 52 "dynalloc2.pgc"
245 
246 if (sqlca.sqlcode < 0) sqlprint ( );}
247 #line 52 "dynalloc2.pgc"
248 
249  { ECPGdisconnect(__LINE__, "CURRENT");
250 #line 53 "dynalloc2.pgc"
251 
252 if (sqlca.sqlcode < 0) sqlprint ( );}
253 #line 53 "dynalloc2.pgc"
254 
255  return 0;
256 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:759
void ECPGfree_auto_mem(void)
Definition: memory.c:138
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 ECPGdebug(X, Y)
Definition: sql-dynalloc2.c:7
#define sqlca
Definition: sql-dynalloc2.c:71
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
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:245
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition: descriptor.c:91
void sqlprint(void)
Definition: error.c:336
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:712
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
int i