PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
thread-prep.c
Go to the documentation of this file.
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "prep.pgc"
10 #include <stdlib.h>
11 #include "ecpg_config.h"
12 
13 #ifndef ENABLE_THREAD_SAFETY
14 int
15 main(void)
16 {
17  printf("No threading enabled.\n");
18  return 0;
19 }
20 #else
21 #ifdef WIN32
22 #define WIN32_LEAN_AND_MEAN
23 #include <windows.h>
24 #include <process.h>
25 #else
26 #include <pthread.h>
27 #endif
28 #include <stdio.h>
29 
30 #define THREADS 16
31 #define REPEATS 50
32 
33 
34 #line 1 "sqlca.h"
35 #ifndef POSTGRES_SQLCA_H
36 #define POSTGRES_SQLCA_H
37 
38 #ifndef PGDLLIMPORT
39 #if defined(WIN32) || defined(__CYGWIN__)
40 #define PGDLLIMPORT __declspec (dllimport)
41 #else
42 #define PGDLLIMPORT
43 #endif /* __CYGWIN__ */
44 #endif /* PGDLLIMPORT */
45 
46 #define SQLERRMC_LEN 150
47 
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #endif
52 
53 struct sqlca_t
54 {
55  char sqlcaid[8];
56  long sqlabc;
57  long sqlcode;
58  struct
59  {
60  int sqlerrml;
61  char sqlerrmc[SQLERRMC_LEN];
62  } sqlerrm;
63  char sqlerrp[8];
64  long sqlerrd[6];
65  /* Element 0: empty */
66  /* 1: OID of processed tuple if applicable */
67  /* 2: number of rows processed */
68  /* after an INSERT, UPDATE or */
69  /* DELETE statement */
70  /* 3: empty */
71  /* 4: empty */
72  /* 5: empty */
73  char sqlwarn[8];
74  /* Element 0: set to 'W' if at least one other is 'W' */
75  /* 1: if 'W' at least one character string */
76  /* value was truncated when it was */
77  /* stored into a host variable. */
78 
79  /*
80  * 2: if 'W' a (hopefully) non-fatal notice occurred
81  */ /* 3: empty */
82  /* 4: empty */
83  /* 5: empty */
84  /* 6: empty */
85  /* 7: empty */
86 
87  char sqlstate[5];
88 };
89 
90 struct sqlca_t *ECPGget_sqlca(void);
91 
92 #ifndef POSTGRES_ECPG_INTERNAL
93 #define sqlca (*ECPGget_sqlca())
94 #endif
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif
101 
102 #line 24 "prep.pgc"
103 
104 
105 #line 1 "regression.h"
106 
107 
108 
109 
110 
111 
112 #line 25 "prep.pgc"
113 
114 
115 /* exec sql whenever sqlerror sqlprint ; */
116 #line 27 "prep.pgc"
117 
118 /* exec sql whenever not found sqlprint ; */
119 #line 28 "prep.pgc"
120 
121 
122 #ifdef WIN32
123 static unsigned __stdcall fn(void* arg)
124 #else
125 static void* fn(void* arg)
126 #endif
127 {
128  int i;
129 
130  /* exec sql begin declare section */
131 
132 
133 
134 
135 #line 39 "prep.pgc"
136  int value ;
137 
138 #line 40 "prep.pgc"
139  char name [ 100 ] ;
140 
141 #line 41 "prep.pgc"
142  char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ;
143 /* exec sql end declare section */
144 #line 42 "prep.pgc"
145 
146 
147  value = (long)arg;
148  sprintf(name, "Connection: %d", value);
149 
150  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
151 #line 47 "prep.pgc"
152 
153 if (sqlca.sqlcode < 0) sqlprint();}
154 #line 47 "prep.pgc"
155 
156  { ECPGsetcommit(__LINE__, "on", NULL);
157 #line 48 "prep.pgc"
158 
159 if (sqlca.sqlcode < 0) sqlprint();}
160 #line 48 "prep.pgc"
161 
162  for (i = 1; i <= REPEATS; ++i)
163  {
164  { ECPGprepare(__LINE__, NULL, 0, "i", query);
165 #line 51 "prep.pgc"
166 
167 if (sqlca.sqlcode < 0) sqlprint();}
168 #line 51 "prep.pgc"
169 
170  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
171  ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
172  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
173 #line 52 "prep.pgc"
174 
175 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
176 #line 52 "prep.pgc"
177 
178 if (sqlca.sqlcode < 0) sqlprint();}
179 #line 52 "prep.pgc"
180 
181  }
182  { ECPGdeallocate(__LINE__, 0, NULL, "i");
183 #line 54 "prep.pgc"
184 
185 if (sqlca.sqlcode < 0) sqlprint();}
186 #line 54 "prep.pgc"
187 
188  { ECPGdisconnect(__LINE__, name);
189 #line 55 "prep.pgc"
190 
191 if (sqlca.sqlcode < 0) sqlprint();}
192 #line 55 "prep.pgc"
193 
194 
195  return 0;
196 }
197 
198 int main ()
199 {
200  int i;
201 #ifdef WIN32
202  HANDLE threads[THREADS];
203 #else
204  pthread_t threads[THREADS];
205 #endif
206 
207  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
208 #line 69 "prep.pgc"
209 
210 if (sqlca.sqlcode < 0) sqlprint();}
211 #line 69 "prep.pgc"
212 
213  { ECPGsetcommit(__LINE__, "on", NULL);
214 #line 70 "prep.pgc"
215 
216 if (sqlca.sqlcode < 0) sqlprint();}
217 #line 70 "prep.pgc"
218 
219  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
220 #line 71 "prep.pgc"
221 
222 if (sqlca.sqlcode < 0) sqlprint();}
223 #line 71 "prep.pgc"
224 
225  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
226 #line 72 "prep.pgc"
227 
228 if (sqlca.sqlcode < 0) sqlprint();}
229 #line 72 "prep.pgc"
230 
231  { ECPGdisconnect(__LINE__, "CURRENT");
232 #line 73 "prep.pgc"
233 
234 if (sqlca.sqlcode < 0) sqlprint();}
235 #line 73 "prep.pgc"
236 
237 
238 #ifdef WIN32
239  for (i = 0; i < THREADS; ++i)
240  {
241  unsigned id;
242  threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
243  }
244 
245  WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
246  for (i = 0; i < THREADS; ++i)
247  CloseHandle(threads[i]);
248 #else
249  for (i = 0; i < THREADS; ++i)
250  pthread_create(&threads[i], NULL, fn, (void *) (long) i);
251  for (i = 0; i < THREADS; ++i)
252  pthread_join(threads[i], NULL);
253 #endif
254 
255  return 0;
256 }
257 #endif
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
long sqlabc
Definition: sqlca.h:22
struct sqlca_t::@124 sqlerrm
#define sqlca
Definition: sqlca.h:59
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
char sqlwarn[8]
Definition: sqlca.h:39
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:161
#define THREADS
int sqlerrml
Definition: sqlca.h:26
char sqlcaid[8]
Definition: sqlca.h:21
#define REPEATS
int main(void)
Definition: thread-prep.c:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
static struct @121 value
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
Definition: sqlca.h:19
long sqlerrd[6]
Definition: sqlca.h:30
char sqlstate[5]
Definition: sqlca.h:53
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
long sqlcode
Definition: sqlca.h:23
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition: prepare.c:253
void sqlprint(void)
Definition: error.c:336
static void * fn(void *arg)
#define NULL
Definition: c.h:229
#define SQLERRMC_LEN
Definition: sqlca.h:12
char sqlerrp[8]
Definition: sqlca.h:29
const char * name
Definition: encode.c:521
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:165
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
int i
void * arg
#define TRUE
Definition: c.h:217
#define pthread_t
Definition: pgbench.c:79