PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
compat_informix-test_informix2.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <ecpg_informix.h>
#include <stdio.h>
#include <stdlib.h>
#include "sqltypes.h"
Include dependency graph for compat_informix-test_informix2.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)
 
static void sql_check (char *fn, char *caller, int ignore)
 
int main (void)
 

Macro Definition Documentation

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

Definition at line 9 of file compat_informix-test_informix2.c.

Referenced by main().

#define PGDLLIMPORT

Definition at line 25 of file compat_informix-test_informix2.c.

#define POSTGRES_SQLCA_H

Definition at line 19 of file compat_informix-test_informix2.c.

#define sqlca   (*ECPGget_sqlca())

Definition at line 76 of file compat_informix-test_informix2.c.

Referenced by main(), and sql_check().

#define SQLERRMC_LEN   150

Definition at line 29 of file compat_informix-test_informix2.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:45
Definition: sqlca.h:19
#define NULL
Definition: c.h:226
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 138 of file compat_informix-test_informix2.c.

References dbname, ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGt_timestamp, ECPGtrans(), free, NULL, PGTYPESinterval_from_asc(), PGTYPEStimestamp_add_interval(), sql_check(), sqlca, and sqlprint().

139 {
140  /* exec sql begin declare section */
141 
142 
143 
144 
145 
146 
147 #line 49 "test_informix2.pgc"
148  int c ;
149 
150 #line 50 "test_informix2.pgc"
151  timestamp d ;
152 
153 #line 51 "test_informix2.pgc"
154  timestamp e ;
155 
156 #line 52 "test_informix2.pgc"
157  timestamp maxd ;
158 
159 #line 53 "test_informix2.pgc"
160  char dbname [ 30 ] ;
161 /* exec sql end declare section */
162 #line 54 "test_informix2.pgc"
163 
164 
165  interval *intvl;
166 
167  /* exec sql whenever sqlerror sqlprint ; */
168 #line 58 "test_informix2.pgc"
169 
170 
171  ECPGdebug(1, stderr);
172 
173  strcpy(dbname, "ecpg1_regression");
174  { ECPGconnect(__LINE__, 1, dbname , NULL, NULL , NULL, 0);
175 #line 63 "test_informix2.pgc"
176 
177 if (sqlca.sqlcode < 0) sqlprint();}
178 #line 63 "test_informix2.pgc"
179 
180  sql_check("main", "connect", 0);
181 
182  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set DateStyle to 'DMY'", ECPGt_EOIT, ECPGt_EORT);
183 #line 66 "test_informix2.pgc"
184 
185 if (sqlca.sqlcode < 0) sqlprint();}
186 #line 66 "test_informix2.pgc"
187 
188 
189  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) )", ECPGt_EOIT, ECPGt_EORT);
190 #line 68 "test_informix2.pgc"
191 
192 if (sqlca.sqlcode < 0) sqlprint();}
193 #line 68 "test_informix2.pgc"
194 
195  sql_check("main", "create", 0);
196 
197  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into history ( customerid , timestamp , action_taken , narrative ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )", ECPGt_EOIT, ECPGt_EORT);
198 #line 73 "test_informix2.pgc"
199 
200 if (sqlca.sqlcode < 0) sqlprint();}
201 #line 73 "test_informix2.pgc"
202 
203  sql_check("main", "insert", 0);
204 
205  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select max ( timestamp ) from history", ECPGt_EOIT,
206  ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp),
207  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
208 #line 78 "test_informix2.pgc"
209 
210 if (sqlca.sqlcode < 0) sqlprint();}
211 #line 78 "test_informix2.pgc"
212 
213  sql_check("main", "select max", 100);
214 
215  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select customerid , timestamp from history where timestamp = $1 limit 1",
216  ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp),
217  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
218  ECPGt_int,&(c),(long)1,(long)1,sizeof(int),
219  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
220  ECPGt_timestamp,&(d),(long)1,(long)1,sizeof(timestamp),
221  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
222 #line 85 "test_informix2.pgc"
223 
224 if (sqlca.sqlcode < 0) sqlprint();}
225 #line 85 "test_informix2.pgc"
226 
227  sql_check("main", "select", 0);
228 
229  printf("Read in customer %d\n", c);
230 
231  intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL);
232  PGTYPEStimestamp_add_interval(&d, intvl, &e);
233  free(intvl);
234  c++;
235 
236  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into history ( customerid , timestamp , action_taken , narrative ) values ( $1 , $2 , 'test' , 'test' )",
237  ECPGt_int,&(c),(long)1,(long)1,sizeof(int),
238  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
239  ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp),
240  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
241 #line 97 "test_informix2.pgc"
242 
243 if (sqlca.sqlcode < 0) sqlprint();}
244 #line 97 "test_informix2.pgc"
245 
246  sql_check("main", "update", 0);
247 
248  { ECPGtrans(__LINE__, NULL, "commit");
249 #line 100 "test_informix2.pgc"
250 
251 if (sqlca.sqlcode < 0) sqlprint();}
252 #line 100 "test_informix2.pgc"
253 
254 
255  { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table history", ECPGt_EOIT, ECPGt_EORT);
256 #line 102 "test_informix2.pgc"
257 
258 if (sqlca.sqlcode < 0) sqlprint();}
259 #line 102 "test_informix2.pgc"
260 
261  sql_check("main", "drop", 0);
262 
263  { ECPGtrans(__LINE__, NULL, "commit");
264 #line 105 "test_informix2.pgc"
265 
266 if (sqlca.sqlcode < 0) sqlprint();}
267 #line 105 "test_informix2.pgc"
268 
269 
270  { ECPGdisconnect(__LINE__, "CURRENT");
271 #line 107 "test_informix2.pgc"
272 
273 if (sqlca.sqlcode < 0) sqlprint();}
274 #line 107 "test_informix2.pgc"
275 
276  sql_check("main", "disconnect", 0);
277 
278  printf("All OK!\n");
279 
280  exit(0);
281 
282 /*
283  Table "public.history"
284  Column | Type | Nullable
285 --------------+-----------------------------+----------
286  customerid | integer | not null
287  timestamp | timestamp without time zone | not null
288  action_taken | character(5) | not null
289  narrative | character varying(100) |
290 */
291 
292 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
int64 timestamp
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
static void sql_check(char *fn, char *caller, int ignore)
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
char * c
interval * PGTYPESinterval_from_asc(char *, char **)
Definition: interval.c:1021
#define ECPGdebug(X, Y)
int PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
Definition: timestamp.c:870
void sqlprint(void)
Definition: error.c:336
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
char * dbname
Definition: streamutil.c:38
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
e
Definition: preproc-init.c:82
static void sql_check ( char *  fn,
char *  caller,
int  ignore 
)
static

Definition at line 100 of file compat_informix-test_informix2.c.

References ECPGtrans(), NULL, sqlca, and SQLCODE.

Referenced by main().

101 {
102  char errorstring[255];
103 
104  if (SQLCODE == ignore)
105  return;
106  else
107  {
108  if (SQLCODE != 0)
109  {
110 
111  sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
112  SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
113  fprintf(stderr, "%s", errorstring);
114  printf("%s\n", errorstring);
115 
116  /* attempt a ROLLBACK */
117  { ECPGtrans(__LINE__, NULL, "rollback");}
118 #line 27 "test_informix2.pgc"
119 
120 
121  if (SQLCODE == 0)
122  {
123  sprintf(errorstring, "Rollback successful.\n");
124  } else {
125  sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
126  }
127 
128  fprintf(stderr, "%s", errorstring);
129  printf("%s\n", errorstring);
130 
131  exit(1);
132  }
133  }
134 }
static void * fn(void *arg)
#define NULL
Definition: c.h:226
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
#define SQLCODE
Definition: ecpglib.h:69