PostgreSQL Source Code  git master
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

◆ ECPGdebug

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

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

◆ PGDLLIMPORT

#define PGDLLIMPORT

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

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

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

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

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

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

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

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 ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:153
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_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:2277
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
#define printf(...)
Definition: port.h:244
#define ECPGdebug(X, Y)
Definition: sql-indicators.c:7

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