PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 (const char *fn, const char *caller, int ignore)
 
int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

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

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

◆ PGDLLIMPORT

#define PGDLLIMPORT

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

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

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

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

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

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 29 of file compat_informix-test_informix2.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 136 of file compat_informix-test_informix2.c.

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

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

◆ sql_check()

static void sql_check ( const char *  fn,
const char *  caller,
int  ignore 
)
static

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

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 }
#define SQLCODE
Definition: ecpglib.h:48
#define sprintf
Definition: port.h:240
#define fprintf
Definition: port.h:242
static void * fn(void *arg)
Definition: thread-alloc.c:119

References ECPGtrans(), exit(), fn(), fprintf, printf, sprintf, sqlca, and SQLCODE.

Referenced by main().