00001
00002
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008
00009 #line 1 "prep.pgc"
00010 #include <stdlib.h>
00011 #include "ecpg_config.h"
00012
00013 #ifndef ENABLE_THREAD_SAFETY
00014 int
00015 main(void)
00016 {
00017 printf("No threading enabled.\n");
00018 return 0;
00019 }
00020 #else
00021 #ifdef WIN32
00022 #define WIN32_LEAN_AND_MEAN
00023 #include <windows.h>
00024 #include <process.h>
00025 #else
00026 #include <pthread.h>
00027 #endif
00028 #include <stdio.h>
00029
00030 #define THREADS 16
00031 #define REPEATS 50
00032
00033
00034 #line 1 "sqlca.h"
00035 #ifndef POSTGRES_SQLCA_H
00036 #define POSTGRES_SQLCA_H
00037
00038 #ifndef PGDLLIMPORT
00039 #if defined(WIN32) || defined(__CYGWIN__)
00040 #define PGDLLIMPORT __declspec (dllimport)
00041 #else
00042 #define PGDLLIMPORT
00043 #endif
00044 #endif
00045
00046 #define SQLERRMC_LEN 150
00047
00048 #ifdef __cplusplus
00049 extern "C"
00050 {
00051 #endif
00052
00053 struct sqlca_t
00054 {
00055 char sqlcaid[8];
00056 long sqlabc;
00057 long sqlcode;
00058 struct
00059 {
00060 int sqlerrml;
00061 char sqlerrmc[SQLERRMC_LEN];
00062 } sqlerrm;
00063 char sqlerrp[8];
00064 long sqlerrd[6];
00065
00066
00067
00068
00069
00070
00071
00072
00073 char sqlwarn[8];
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 char sqlstate[5];
00088 };
00089
00090 struct sqlca_t *ECPGget_sqlca(void);
00091
00092 #ifndef POSTGRES_ECPG_INTERNAL
00093 #define sqlca (*ECPGget_sqlca())
00094 #endif
00095
00096 #ifdef __cplusplus
00097 }
00098 #endif
00099
00100 #endif
00101
00102 #line 24 "prep.pgc"
00103
00104
00105 #line 1 "regression.h"
00106
00107
00108
00109
00110
00111
00112 #line 25 "prep.pgc"
00113
00114
00115
00116 #line 27 "prep.pgc"
00117
00118
00119 #line 28 "prep.pgc"
00120
00121
00122 #ifdef WIN32
00123 static unsigned __stdcall fn(void* arg)
00124 #else
00125 static void* fn(void* arg)
00126 #endif
00127 {
00128 int i;
00129
00130
00131
00132
00133
00134
00135 #line 39 "prep.pgc"
00136 int value ;
00137
00138 #line 40 "prep.pgc"
00139 char name [ 100 ] ;
00140
00141 #line 41 "prep.pgc"
00142 char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ;
00143
00144 #line 42 "prep.pgc"
00145
00146
00147 value = (long)arg;
00148 sprintf(name, "Connection: %d", value);
00149
00150 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , name, 0);
00151 #line 47 "prep.pgc"
00152
00153 if (sqlca.sqlcode < 0) sqlprint();}
00154 #line 47 "prep.pgc"
00155
00156 { ECPGsetcommit(__LINE__, "on", NULL);
00157 #line 48 "prep.pgc"
00158
00159 if (sqlca.sqlcode < 0) sqlprint();}
00160 #line 48 "prep.pgc"
00161
00162 for (i = 1; i <= REPEATS; ++i)
00163 {
00164 { ECPGprepare(__LINE__, NULL, 0, "i", query);
00165 #line 51 "prep.pgc"
00166
00167 if (sqlca.sqlcode < 0) sqlprint();}
00168 #line 51 "prep.pgc"
00169
00170 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
00171 ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
00172 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00173 #line 52 "prep.pgc"
00174
00175 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
00176 #line 52 "prep.pgc"
00177
00178 if (sqlca.sqlcode < 0) sqlprint();}
00179 #line 52 "prep.pgc"
00180
00181 }
00182 { ECPGdeallocate(__LINE__, 0, NULL, "i");
00183 #line 54 "prep.pgc"
00184
00185 if (sqlca.sqlcode < 0) sqlprint();}
00186 #line 54 "prep.pgc"
00187
00188 { ECPGdisconnect(__LINE__, name);
00189 #line 55 "prep.pgc"
00190
00191 if (sqlca.sqlcode < 0) sqlprint();}
00192 #line 55 "prep.pgc"
00193
00194
00195 return 0;
00196 }
00197
00198 int main ()
00199 {
00200 int i;
00201 #ifdef WIN32
00202 HANDLE threads[THREADS];
00203 #else
00204 pthread_t threads[THREADS];
00205 #endif
00206
00207 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
00208 #line 69 "prep.pgc"
00209
00210 if (sqlca.sqlcode < 0) sqlprint();}
00211 #line 69 "prep.pgc"
00212
00213 { ECPGsetcommit(__LINE__, "on", NULL);
00214 #line 70 "prep.pgc"
00215
00216 if (sqlca.sqlcode < 0) sqlprint();}
00217 #line 70 "prep.pgc"
00218
00219 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
00220 #line 71 "prep.pgc"
00221
00222 if (sqlca.sqlcode < 0) sqlprint();}
00223 #line 71 "prep.pgc"
00224
00225 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
00226 #line 72 "prep.pgc"
00227
00228 if (sqlca.sqlcode < 0) sqlprint();}
00229 #line 72 "prep.pgc"
00230
00231 { ECPGdisconnect(__LINE__, "CURRENT");
00232 #line 73 "prep.pgc"
00233
00234 if (sqlca.sqlcode < 0) sqlprint();}
00235 #line 73 "prep.pgc"
00236
00237
00238 #ifdef WIN32
00239 for (i = 0; i < THREADS; ++i)
00240 {
00241 unsigned id;
00242 threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
00243 }
00244
00245 WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
00246 for (i = 0; i < THREADS; ++i)
00247 CloseHandle(threads[i]);
00248 #else
00249 for (i = 0; i < THREADS; ++i)
00250 pthread_create(&threads[i], NULL, fn, (void *) (long) i);
00251 for (i = 0; i < THREADS; ++i)
00252 pthread_join(threads[i], NULL);
00253 #endif
00254
00255 return 0;
00256 }
00257 #endif