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 "alloc.pgc"
10 #include <stdlib.h>
11 #include "ecpg_config.h"
12 
13 #ifndef ENABLE_THREAD_SAFETY
14 int
main(void)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 #include <locale.h>
26 #else
27 #include <pthread.h>
28 #endif
29 #include <stdio.h>
30 
31 #define THREADS		16
32 #define REPEATS		50
33 
34 
35 #line 1 "sqlca.h"
36 #ifndef POSTGRES_SQLCA_H
37 #define POSTGRES_SQLCA_H
38 
39 #ifndef PGDLLIMPORT
40 #if  defined(WIN32) || defined(__CYGWIN__)
41 #define PGDLLIMPORT __declspec (dllimport)
42 #else
43 #define PGDLLIMPORT
44 #endif							/* __CYGWIN__ */
45 #endif							/* PGDLLIMPORT */
46 
47 #define SQLERRMC_LEN	150
48 
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
54 struct sqlca_t
55 {
56 	char		sqlcaid[8];
57 	long		sqlabc;
58 	long		sqlcode;
59 	struct
60 	{
61 		int			sqlerrml;
62 		char		sqlerrmc[SQLERRMC_LEN];
63 	}			sqlerrm;
64 	char		sqlerrp[8];
65 	long		sqlerrd[6];
66 	/* Element 0: empty						*/
67 	/* 1: OID of processed tuple if applicable			*/
68 	/* 2: number of rows processed				*/
69 	/* after an INSERT, UPDATE or				*/
70 	/* DELETE statement					*/
71 	/* 3: empty						*/
72 	/* 4: empty						*/
73 	/* 5: empty						*/
74 	char		sqlwarn[8];
75 	/* Element 0: set to 'W' if at least one other is 'W'	*/
76 	/* 1: if 'W' at least one character string		*/
77 	/* value was truncated when it was			*/
78 	/* stored into a host variable.             */
79 
80 	/*
81 	 * 2: if 'W' a (hopefully) non-fatal notice occurred
82 	 */	/* 3: empty */
83 	/* 4: empty						*/
84 	/* 5: empty						*/
85 	/* 6: empty						*/
86 	/* 7: empty						*/
87 
88 	char		sqlstate[5];
89 };
90 
91 struct sqlca_t *ECPGget_sqlca(void);
92 
93 #ifndef POSTGRES_ECPG_INTERNAL
94 #define sqlca (*ECPGget_sqlca())
95 #endif
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif
102 
103 #line 25 "alloc.pgc"
104 
105 
106 #line 1 "regression.h"
107 
108 
109 
110 
111 
112 
113 #line 26 "alloc.pgc"
114 
115 
116 /* exec sql whenever sqlerror  sqlprint ; */
117 #line 28 "alloc.pgc"
118 
119 /* exec sql whenever not found  sqlprint ; */
120 #line 29 "alloc.pgc"
121 
122 
123 #ifdef WIN32
fn(void * arg)124 static unsigned __stdcall fn(void* arg)
125 #else
126 static void* fn(void* arg)
127 #endif
128 {
129 	int i;
130 
131 	/* exec sql begin declare section */
132 
133 
134 
135 
136 #line 40 "alloc.pgc"
137  int value ;
138 
139 #line 41 "alloc.pgc"
140  char name [ 100 ] ;
141 
142 #line 42 "alloc.pgc"
143  char ** r = NULL ;
144 /* exec sql end declare section */
145 #line 43 "alloc.pgc"
146 
147 
148 #ifdef WIN32
149 #ifdef _MSC_VER                /* requires MSVC */
150 	_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
151 #endif
152 #endif
153 
154 	value = (long)arg;
155 	sprintf(name, "Connection: %d", value);
156 
157 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
158 #line 54 "alloc.pgc"
159 
160 if (sqlca.sqlcode < 0) sqlprint();}
161 #line 54 "alloc.pgc"
162 
163 	{ ECPGsetcommit(__LINE__, "on", NULL);
164 #line 55 "alloc.pgc"
165 
166 if (sqlca.sqlcode < 0) sqlprint();}
167 #line 55 "alloc.pgc"
168 
169 	for (i = 1; i <= REPEATS; ++i)
170 	{
171 		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT,
172 	ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char),
173 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
174 #line 58 "alloc.pgc"
175 
176 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
177 #line 58 "alloc.pgc"
178 
179 if (sqlca.sqlcode < 0) sqlprint();}
180 #line 58 "alloc.pgc"
181 
182 		free(r);
183 		r = NULL;
184 	}
185 	{ ECPGdisconnect(__LINE__, name);
186 #line 62 "alloc.pgc"
187 
188 if (sqlca.sqlcode < 0) sqlprint();}
189 #line 62 "alloc.pgc"
190 
191 
192 	return 0;
193 }
194 
main()195 int main ()
196 {
197 	int i;
198 #ifdef WIN32
199 	HANDLE threads[THREADS];
200 #else
201 	pthread_t threads[THREADS];
202 #endif
203 
204 #ifdef WIN32
205 	for (i = 0; i < THREADS; ++i)
206 	{
207 		unsigned id;
208 		threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
209 	}
210 
211 	WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
212 	for (i = 0; i < THREADS; ++i)
213 		CloseHandle(threads[i]);
214 #else
215 	for (i = 0; i < THREADS; ++i)
216 		pthread_create(&threads[i], NULL, fn, (void *) (long) i);
217 	for (i = 0; i < THREADS; ++i)
218 		pthread_join(threads[i], NULL);
219 #endif
220 
221 	return 0;
222 }
223 #endif
224