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 "descriptor.pgc"
10 #ifdef ENABLE_THREAD_SAFETY
11 #ifdef WIN32
12 #define WIN32_LEAN_AND_MEAN
13 #include <windows.h>
14 #include <process.h>
15 #include <locale.h>
16 #else
17 #include <pthread.h>
18 #endif
19 #endif
20 #include <stdio.h>
21 
22 #define THREADS		16
23 #define REPEATS		50000
24 
25 
26 #line 1 "sqlca.h"
27 #ifndef POSTGRES_SQLCA_H
28 #define POSTGRES_SQLCA_H
29 
30 #ifndef PGDLLIMPORT
31 #if  defined(WIN32) || defined(__CYGWIN__)
32 #define PGDLLIMPORT __declspec (dllimport)
33 #else
34 #define PGDLLIMPORT
35 #endif							/* __CYGWIN__ */
36 #endif							/* PGDLLIMPORT */
37 
38 #define SQLERRMC_LEN	150
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
45 struct sqlca_t
46 {
47 	char		sqlcaid[8];
48 	long		sqlabc;
49 	long		sqlcode;
50 	struct
51 	{
52 		int			sqlerrml;
53 		char		sqlerrmc[SQLERRMC_LEN];
54 	}			sqlerrm;
55 	char		sqlerrp[8];
56 	long		sqlerrd[6];
57 	/* Element 0: empty						*/
58 	/* 1: OID of processed tuple if applicable			*/
59 	/* 2: number of rows processed				*/
60 	/* after an INSERT, UPDATE or				*/
61 	/* DELETE statement					*/
62 	/* 3: empty						*/
63 	/* 4: empty						*/
64 	/* 5: empty						*/
65 	char		sqlwarn[8];
66 	/* Element 0: set to 'W' if at least one other is 'W'	*/
67 	/* 1: if 'W' at least one character string		*/
68 	/* value was truncated when it was			*/
69 	/* stored into a host variable.             */
70 
71 	/*
72 	 * 2: if 'W' a (hopefully) non-fatal notice occurred
73 	 */	/* 3: empty */
74 	/* 4: empty						*/
75 	/* 5: empty						*/
76 	/* 6: empty						*/
77 	/* 7: empty						*/
78 
79 	char		sqlstate[5];
80 };
81 
82 struct sqlca_t *ECPGget_sqlca(void);
83 
84 #ifndef POSTGRES_ECPG_INTERNAL
85 #define sqlca (*ECPGget_sqlca())
86 #endif
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif
93 
94 #line 16 "descriptor.pgc"
95 
96 /* exec sql whenever sqlerror  sqlprint ; */
97 #line 17 "descriptor.pgc"
98 
99 /* exec sql whenever not found  sqlprint ; */
100 #line 18 "descriptor.pgc"
101 
102 
103 #if defined(ENABLE_THREAD_SAFETY) && defined(WIN32)
104 static unsigned __stdcall fn(void* arg)
105 #else
106 static void* fn(void* arg)
107 #endif
108 {
109 	int i;
110 
111 	for (i = 1; i <= REPEATS; ++i)
112 	{
113 		ECPGallocate_desc(__LINE__, "mydesc");
114 #line 30 "descriptor.pgc"
115 
116 if (sqlca.sqlcode < 0) sqlprint();
117 #line 30 "descriptor.pgc"
118 
119 		ECPGdeallocate_desc(__LINE__, "mydesc");
120 #line 31 "descriptor.pgc"
121 
122 if (sqlca.sqlcode < 0) sqlprint();
123 #line 31 "descriptor.pgc"
124 
125 	}
126 
127 	return 0;
128 }
129 
130 int main ()
131 {
132 #ifdef ENABLE_THREAD_SAFETY
133 	int i;
134 #ifdef WIN32
135 	HANDLE threads[THREADS];
136 #else
137 	pthread_t threads[THREADS];
138 #endif
139 
140 #ifdef WIN32
141 	for (i = 0; i < THREADS; ++i)
142 	{
143 		unsigned id;
144 		threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
145 	}
146 
147 	WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
148 	for (i = 0; i < THREADS; ++i)
149 		CloseHandle(threads[i]);
150 #else
151 	for (i = 0; i < THREADS; ++i)
152 		pthread_create(&threads[i], NULL, fn, NULL);
153 	for (i = 0; i < THREADS; ++i)
154 		pthread_join(threads[i], NULL);
155 #endif
156 #else
157 	fn(NULL);
158 #endif
159 
160 	return 0;
161 }
162