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