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

Referenced by main().

#define PGDLLIMPORT

Definition at line 21 of file sql-indicators.c.

#define POSTGRES_SQLCA_H

Definition at line 15 of file sql-indicators.c.

#define sqlca   (*ECPGget_sqlca())

Definition at line 72 of file sql-indicators.c.

#define SQLERRMC_LEN   150

Definition at line 25 of file sql-indicators.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-indicators.c.

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

95 {
96  /* exec sql begin declare section */
97 
98 
99 
100 #line 9 "indicators.pgc"
101  int intvar = 5 ;
102 
103 #line 10 "indicators.pgc"
104  int nullind = - 1 ;
105 /* exec sql end declare section */
106 #line 11 "indicators.pgc"
107 
108 
109  ECPGdebug(1,stderr);
110 
111  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
112 #line 15 "indicators.pgc"
113 
114  { ECPGsetcommit(__LINE__, "off", NULL);}
115 #line 16 "indicators.pgc"
116 
117 
118  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table indicator_test ( \"id\" int primary key , \"str\" text not null , val int null )", ECPGt_EOIT, ECPGt_EORT);}
119 #line 21 "indicators.pgc"
120 
121  { ECPGtrans(__LINE__, NULL, "commit work");}
122 #line 22 "indicators.pgc"
123 
124 
125  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 1 , 'Hello' , 0 )", ECPGt_EOIT, ECPGt_EORT);}
126 #line 24 "indicators.pgc"
127 
128 
129  /* use indicator in insert */
130  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 2 , 'Hi there' , $1 )",
131  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
132  ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
133 #line 27 "indicators.pgc"
134 
135  nullind = 0;
136  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 3 , 'Good evening' , $1 )",
137  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
138  ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
139 #line 29 "indicators.pgc"
140 
141  { ECPGtrans(__LINE__, NULL, "commit work");}
142 #line 30 "indicators.pgc"
143 
144 
145  /* use indicators to get information about selects */
146  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 1", ECPGt_EOIT,
147  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
148  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
149 #line 33 "indicators.pgc"
150 
151  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 2", ECPGt_EOIT,
152  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
153  ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
154 #line 34 "indicators.pgc"
155 
156  printf("intvar: %d, nullind: %d\n", intvar, nullind);
157  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 3", ECPGt_EOIT,
158  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
159  ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
160 #line 36 "indicators.pgc"
161 
162  printf("intvar: %d, nullind: %d\n", intvar, nullind);
163 
164  /* use indicators for update */
165  intvar = 5; nullind = -1;
166  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update indicator_test set val = $1 where id = 1",
167  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
168  ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
169 #line 41 "indicators.pgc"
170 
171  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 1", ECPGt_EOIT,
172  ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
173  ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
174 #line 42 "indicators.pgc"
175 
176  printf("intvar: %d, nullind: %d\n", intvar, nullind);
177 
178  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table indicator_test", ECPGt_EOIT, ECPGt_EORT);}
179 #line 45 "indicators.pgc"
180 
181  { ECPGtrans(__LINE__, NULL, "commit work");}
182 #line 46 "indicators.pgc"
183 
184 
185  { ECPGdisconnect(__LINE__, "CURRENT");}
186 #line 48 "indicators.pgc"
187 
188  return 0;
189 }
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
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-indicators.c:7
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:165