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 #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 */ MemprofThreadLocalMallocStorageMemprofThreadLocalMallocStorage77 /* 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 "prep.pgc" 104 105 106 #line 1 "regression.h" 107 108 109 110 111 112 113 #line 26 "prep.pgc" 114 115 116 /* exec sql whenever sqlerror sqlprint ; */ 117 #line 28 "prep.pgc" 118 119 /* exec sql whenever not found sqlprint ; */ 120 #line 29 "prep.pgc" 121 122 123 #ifdef WIN32 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 "prep.pgc" 137 int value ; 138 139 #line 41 "prep.pgc" 140 char name [ 100 ] ; 141 142 #line 42 "prep.pgc" 143 char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ; 144 /* exec sql end declare section */ 145 #line 43 "prep.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 "prep.pgc" 159 160 if (sqlca.sqlcode < 0) sqlprint();} 161 #line 54 "prep.pgc" 162 163 { ECPGsetcommit(__LINE__, "on", NULL); 164 #line 55 "prep.pgc" 165 166 if (sqlca.sqlcode < 0) sqlprint();} 167 #line 55 "prep.pgc" 168 169 for (i = 1; i <= REPEATS; ++i) 170 { 171 { ECPGprepare(__LINE__, NULL, 0, "i", query); 172 #line 58 "prep.pgc" 173 174 if (sqlca.sqlcode < 0) sqlprint();} 175 #line 58 "prep.pgc" 176 177 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i", 178 ECPGt_int,&(value),(long)1,(long)1,sizeof(int), 179 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); 180 #line 59 "prep.pgc" 181 182 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint(); 183 #line 59 "prep.pgc" 184 185 if (sqlca.sqlcode < 0) sqlprint();} 186 #line 59 "prep.pgc" 187 188 } 189 { ECPGdeallocate(__LINE__, 0, NULL, "i"); 190 #line 61 "prep.pgc" 191 192 if (sqlca.sqlcode < 0) sqlprint();} 193 #line 61 "prep.pgc" 194 195 { ECPGdisconnect(__LINE__, name); 196 #line 62 "prep.pgc" 197 198 if (sqlca.sqlcode < 0) sqlprint();} 199 #line 62 "prep.pgc" 200 201 202 return 0; 203 } 204 205 int main () 206 { 207 int i; 208 #ifdef WIN32 209 HANDLE threads[THREADS]; 210 #else 211 pthread_t threads[THREADS]; 212 #endif 213 214 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); 215 #line 76 "prep.pgc" 216 217 if (sqlca.sqlcode < 0) sqlprint();} 218 #line 76 "prep.pgc" 219 220 { ECPGsetcommit(__LINE__, "on", NULL); 221 #line 77 "prep.pgc" 222 223 if (sqlca.sqlcode < 0) sqlprint();} 224 #line 77 "prep.pgc" 225 226 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT); 227 #line 78 "prep.pgc" 228 229 if (sqlca.sqlcode < 0) sqlprint();} 230 #line 78 "prep.pgc" 231 232 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT); 233 #line 79 "prep.pgc" 234 235 if (sqlca.sqlcode < 0) sqlprint();} 236 #line 79 "prep.pgc" 237 238 { ECPGdisconnect(__LINE__, "CURRENT"); 239 #line 80 "prep.pgc" 240 241 if (sqlca.sqlcode < 0) sqlprint();} 242 #line 80 "prep.pgc" 243 244 245 #ifdef WIN32 246 for (i = 0; i < THREADS; ++i) 247 { 248 unsigned id; 249 threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id); 250 } 251 252 WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE); 253 for (i = 0; i < THREADS; ++i) 254 CloseHandle(threads[i]); 255 #else 256 for (i = 0; i < THREADS; ++i) 257 pthread_create(&threads[i], NULL, fn, (void *) (long) i); 258 for (i = 0; i < THREADS; ++i) 259 pthread_join(threads[i], NULL); 260 #endif 261 262 return 0; 263 } 264 #endif 265