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