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

Macro Definition Documentation

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

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

Referenced by main().

#define PGDLLIMPORT

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

#define POSTGRES_SQLCA_H

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

#define sqlca   (*ECPGget_sqlca())

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

Referenced by main().

#define SQLERRMC_LEN   150

Definition at line 23 of file sql-code100.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
#define NULL
Definition: c.h:229
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-code100.c.

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), NULL, and sqlca.

96 { /* exec sql begin declare section */
97 
98 
99 #line 9 "code100.pgc"
100  int index ;
101 /* exec sql end declare section */
102 #line 10 "code100.pgc"
103 
104 
105 
106  ECPGdebug(1,stderr);
107 
108  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
109 #line 15 "code100.pgc"
110 
111  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
112 
113  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( \"index\" numeric ( 3 ) primary key , \"payload\" int4 not null )", ECPGt_EOIT, ECPGt_EORT);}
114 #line 20 "code100.pgc"
115 
116  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
117  { ECPGtrans(__LINE__, NULL, "commit work");}
118 #line 22 "code100.pgc"
119 
120  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
121 
122  for (index=0;index<10;++index)
123  { { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( payload , index ) values ( 0 , $1 )",
124  ECPGt_int,&(index),(long)1,(long)1,sizeof(int),
125  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
126 #line 28 "code100.pgc"
127 
128  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
129  }
130  { ECPGtrans(__LINE__, NULL, "commit work");}
131 #line 31 "code100.pgc"
132 
133  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
134 
135  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update test set payload = payload + 1 where index = - 1", ECPGt_EOIT, ECPGt_EORT);}
136 #line 35 "code100.pgc"
137 
138  if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
139 
140  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "delete from test where index = - 1", ECPGt_EOIT, ECPGt_EORT);}
141 #line 38 "code100.pgc"
142 
143  if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
144 
145  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( select * from test where index = - 1 )", ECPGt_EOIT, ECPGt_EORT);}
146 #line 41 "code100.pgc"
147 
148  if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
149 
150  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);}
151 #line 44 "code100.pgc"
152 
153  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
154  { ECPGtrans(__LINE__, NULL, "commit work");}
155 #line 46 "code100.pgc"
156 
157  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
158 
159  { ECPGdisconnect(__LINE__, "CURRENT");}
160 #line 49 "code100.pgc"
161 
162  if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
163  return 0;
164 }
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
Definition: type.h:90
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
#define ECPGdebug(X, Y)
Definition: sql-code100.c:7
#define NULL
Definition: c.h:229
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
#define sqlca
Definition: sql-code100.c:70