| 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 <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]; |
| 56 |
} sqlerrm; |
| 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 "alloc.pgc" |
| 97 |
|
| 98 |
|
| 99 |
#line 1 "regression.h" |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
#line 19 "alloc.pgc" |
| 107 |
|
| 108 |
|
| 109 |
/* exec sql whenever sqlerror sqlprint ; */ |
| 110 |
#line 21 "alloc.pgc" |
| 111 |
|
| 112 |
/* exec sql whenever not found sqlprint ; */ |
| 113 |
#line 22 "alloc.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 "alloc.pgc" |
| 130 |
int value ; |
| 131 |
|
| 132 |
#line 34 "alloc.pgc" |
| 133 |
char name [ 100 ] ; |
| 134 |
|
| 135 |
#line 35 "alloc.pgc" |
| 136 |
char ** r = NULL ; |
| 137 |
/* exec sql end declare section */ |
| 138 |
#line 36 "alloc.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 "alloc.pgc" |
| 146 |
|
| 147 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 148 |
#line 41 "alloc.pgc" |
| 149 |
|
| 150 |
{ ECPGsetcommit(__LINE__, "on", NULL); |
| 151 |
#line 42 "alloc.pgc" |
| 152 |
|
| 153 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 154 |
#line 42 "alloc.pgc" |
| 155 |
|
| 156 |
for (i = 1; i <= REPEATS; ++i) |
| 157 |
{ |
| 158 |
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT, |
| 159 |
ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char), |
| 160 |
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); |
| 161 |
#line 45 "alloc.pgc" |
| 162 |
|
| 163 |
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint(); |
| 164 |
#line 45 "alloc.pgc" |
| 165 |
|
| 166 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 167 |
#line 45 "alloc.pgc" |
| 168 |
|
| 169 |
free(r); |
| 170 |
r = NULL; |
| 171 |
} |
| 172 |
{ ECPGdisconnect(__LINE__, name); |
| 173 |
#line 49 "alloc.pgc" |
| 174 |
|
| 175 |
if (sqlca.sqlcode < 0) sqlprint();} |
| 176 |
#line 49 "alloc.pgc" |
| 177 |
|
| 178 |
|
| 179 |
return 0; |
| 180 |
} |
| 181 |
|
| 182 |
int main () |
| 183 |
{ |
| 184 |
intptr_t i; |
| 185 |
#ifdef WIN32 |
| 186 |
HANDLE threads[THREADS]; |
| 187 |
#else |
| 188 |
pthread_t threads[THREADS]; |
| 189 |
#endif |
| 190 |
|
| 191 |
#ifdef WIN32 |
| 192 |
for (i = 0; i < THREADS; ++i) |
| 193 |
{ |
| 194 |
unsigned id; |
| 195 |
threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id); |
| 196 |
} |
| 197 |
|
| 198 |
WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE); |
| 199 |
for (i = 0; i < THREADS; ++i) |
| 200 |
CloseHandle(threads[i]); |
| 201 |
#else |
| 202 |
for (i = 0; i < THREADS; ++i) |
| 203 |
pthread_create(&threads[i], NULL, fn, (void *) i); |
| 204 |
for (i = 0; i < THREADS; ++i) |
| 205 |
pthread_join(threads[i], NULL); |
| 206 |
#endif |
| 207 |
|
| 208 |
return 0; |
| 209 |
} |