<borschow@roguewave.com>.
#include <string.h>
#include "descriptor.h"
+#if defined (POSIX_MULTITHREAD_SUPPORT)
+#include <pthread.h>
+#endif
typedef enum
{
#define CC_set_errornumber(x, n) (x->__error_number = n)
/* For Multi-thread */
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
#define INIT_CONN_CS(x) InitializeCriticalSection(&((x)->cs))
#define ENTER_CONN_CS(x) EnterCriticalSection(&((x)->cs))
#define LEAVE_CONN_CS(x) LeaveCriticalSection(&((x)->cs))
#define DELETE_CONN_CS(x) DeleteCriticalSection(&((x)->cs))
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+#define INIT_CONN_CS(x) pthread_mutex_init(&((x)->cs),0)
+#define ENTER_CONN_CS(x) pthread_mutex_lock(&((x)->cs))
+#define LEAVE_CONN_CS(x) pthread_mutex_unlock(&((x)->cs))
+#define DELETE_CONN_CS(x) pthread_mutex_destroy(&((x)->cs))
#else
#define INIT_CONN_CS(x)
#define ENTER_CONN_CS(x)
int be_key; /* auth code needed to send cancel */
UInt4 isolation;
char *current_schema;
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
CRITICAL_SECTION cs;
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+ pthread_mutex_t cs;
#endif /* WIN_MULTITHREAD_SUPPORT */
};
/* The one instance of the handles */
ConnectionClass *conns[MAX_CONNECTIONS];
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
CRITICAL_SECTION conns_cs;
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+pthread_mutex_t conns_cs;
#endif /* WIN_MULTITHREAD_SUPPORT */
char *errormsg;
int errornumber;
Int4 flag;
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
CRITICAL_SECTION cs;
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+ pthread_mutex_t cs;
#endif /* WIN_MULTITHREAD_SUPPORT */
};
#define EN_unset_pooling(env) (env->flag &= ~EN_CONN_POOLING)
/* For Multi-thread */
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined( WIN_MULTITHREAD_SUPPORT)
#define INIT_CONNS_CS InitializeCriticalSection(&conns_cs)
#define ENTER_CONNS_CS EnterCriticalSection(&conns_cs)
#define LEAVE_CONNS_CS LeaveCriticalSection(&conns_cs)
#define ENTER_ENV_CS(x) EnterCriticalSection(&((x)->cs))
#define LEAVE_ENV_CS(x) LeaveCriticalSection(&((x)->cs))
#define DELETE_ENV_CS(x) DeleteCriticalSection(&((x)->cs))
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+#define INIT_CONNS_CS pthread_mutex_init(&conns_cs,0)
+#define ENTER_CONNS_CS pthread_mutex_lock(&conns_cs)
+#define LEAVE_CONNS_CS pthread_mutex_unlock(&conns_cs)
+#define DELETE_CONNS_CS pthread_mutex_destroy(&conns_cs)
+#define INIT_ENV_CS(x) pthread_mutex_init(&((x)->cs),0)
+#define ENTER_ENV_CS(x) pthread_mutex_lock(&((x)->cs))
+#define LEAVE_ENV_CS(x) pthread_mutex_unlock(&((x)->cs))
+#define DELETE_ENV_CS(x) pthread_mutex_destroy(&((x)->cs))
#else
#define INIT_CONNS_CS
#define ENTER_CONNS_CS
return;
}
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
CRITICAL_SECTION qlog_cs, mylog_cs;
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+pthread_mutex_t qlog_cs, mylog_cs;
#endif /* WIN_MULTITHREAD_SUPPORT */
static int mylog_on = 0,
qlog_on = 0;
fprintf(LOGFP, "[%d]", GetCurrentThreadId());
#endif /* WIN32 */
#endif /* WIN_MULTITHREAD_SUPPORT */
+#if defined(POSIX_MULTITHREAD_SUPPORT)
+ if (LOGFP)
+ fprintf(LOGFP, "[%d]", pthread_self());
+#endif /* POSIX_MULTITHREAD_SUPPORT */
if (LOGFP)
vfprintf(LOGFP, fmt, args);
*/
#define Q_LOG
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
#define INIT_QLOG_CS InitializeCriticalSection(&qlog_cs)
#define ENTER_QLOG_CS EnterCriticalSection(&qlog_cs)
#define LEAVE_QLOG_CS LeaveCriticalSection(&qlog_cs)
#define ENTER_MYLOG_CS EnterCriticalSection(&mylog_cs)
#define LEAVE_MYLOG_CS LeaveCriticalSection(&mylog_cs)
#define DELETE_MYLOG_CS DeleteCriticalSection(&mylog_cs)
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+#define INIT_QLOG_CS pthread_mutex_init(&qlog_cs,0)
+#define ENTER_QLOG_CS pthread_mutex_lock(&qlog_cs)
+#define LEAVE_QLOG_CS pthread_mutex_unlock(&qlog_cs)
+#define DELETE_QLOG_CS pthread_mutex_destroy(&qlog_cs)
+#define INIT_MYLOG_CS pthread_mutex_init(&mylog_cs,0)
+#define ENTER_MYLOG_CS pthread_mutex_lock(&mylog_cs)
+#define LEAVE_MYLOG_CS pthread_mutex_unlock(&mylog_cs)
+#define DELETE_MYLOG_CS pthread_mutex_destroy(&mylog_cs)
#else
#define INIT_QLOG_CS
#define ENTER_QLOG_CS
EN_unset_pooling(env);
ret = SQL_SUCCESS;
break;
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT) || defined(POSIX_MULTITHREAD_SUPPORT)
case SQL_CP_ONE_PER_DRIVER:
EN_set_pooling(env);
ret = SQL_SUCCESS;
case SQL_ATTR_CONNECTION_DEAD:
case SQL_ATTR_CONNECTION_TIMEOUT:
case SQL_ATTR_METADATA_ID:
- CC_set_error(conn, STMT_INVALID_OPTION_IDENTIFIER, "Unsupported connect attribute (Set)");
+ case SQL_ATTR_ENLIST_IN_DTC:
+ CC_set_error(conn, STMT_OPTION_NOT_FOR_THE_DRIVER, "Unsupported connect attribute (Set)");
return SQL_ERROR;
default:
ret = PGAPI_SetConnectOption(ConnectionHandle, (UWORD) Attribute, (UDWORD) Value);
#ifdef WIN32
HINSTANCE NEAR s_hModule; /* Saved module handle. */
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
extern CRITICAL_SECTION qlog_cs, mylog_cs, conns_cs;
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+extern pthread_mutex_t qlog_cs, mylog_cs, conns_cs;
#endif /* WIN_MULTITHREAD_SUPPORT */
/* This is where the Driver Manager attaches to this Driver */
case DLL_PROCESS_DETACH:
DELETE_CONNS_CS;
+ DELETE_MYLOG_CS;
DELETE_QLOG_CS;
- DELETE_MYLOG_CS;
WSACleanup();
return TRUE;
return SQL_NO_DATA_FOUND;
/* just to avoid a crash if the user insists on calling this */
/* function even if SQL_ExecDirect has reported an Error */
- SC_set_error(stmt, STMT_SEQUENCE_ERROR, "Bindings were not allocated properly.");
+ SC_set_error(stmt, STMT_INVALID_CURSOR_STATE_ERROR, "Bindings were not allocated properly.");
SC_log_error(func, "", stmt);
return SQL_ERROR;
}
return SQL_NO_DATA_FOUND;
/* just to avoid a crash if the user insists on calling this */
/* function even if SQL_ExecDirect has reported an Error */
- SC_set_error(stmt, STMT_SEQUENCE_ERROR, "Bindings were not allocated properly.");
+ SC_set_error(stmt, STMT_INVALID_CURSOR_STATE_ERROR, "Bindings were not allocated properly.");
SC_log_error(func, "", stmt);
return SQL_ERROR;
}
char
SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname)
{
- struct hostent *host;
+#if defined (POSIX_MULTITHREAD_SUPPORT)
+ const int bufsz = 8192;
+ char buf[bufsz];
+ int error = 0;
+ struct hostent host;
+ struct hostent* hp = &host;
+#else
+ struct hostent* hp;
+#endif
unsigned long iaddr;
if (self->socket != -1)
iaddr = inet_addr(hostname);
if (iaddr == INADDR_NONE)
{
- host = gethostbyname(hostname);
- if (host == NULL)
+#if defined (POSIX_MULTITHREAD_SUPPORT)
+ #if defined (PGS_REENTRANT_API_1) // solaris, irix
+ hp = gethostbyname_r(hostname, hp, buf, bufsz, &error);
+ #elif defined (PGS_REENTRANT_API_2) // linux
+ int result = 0;
+ result = gethostbyname_r(hostname, hp, buf, bufsz, &hp, &error);
+ if (result)
+ hp = 0;
+ #endif
+#else
+ hp = gethostbyname(hostname);
+#endif
+ if (hp == NULL)
{
self->errornumber = SOCKET_HOST_NOT_FOUND;
self->errormsg = "Could not resolve hostname.";
return 0;
}
- memcpy(&(self->sadr.sin_addr), host->h_addr, host->h_length);
+ memcpy(&(self->sadr.sin_addr), hp->h_addr, hp->h_length);
}
else
memcpy(&(self->sadr.sin_addr), (struct in_addr *) & iaddr, sizeof(iaddr));
#include "bind.h"
#include "descriptor.h"
+#if defined (POSIX_MULTITHREAD_SUPPORT)
+#include <pthread.h>
+#endif
#ifndef FALSE
#define FALSE (BOOL)0
* SetPos, SQLFetch) */
int save_rowset_size; /* saved rowset size in case of
* change/FETCH_NEXT */
- int rowset_start; /* start of rowset (an absolute row
+ Int4 rowset_start; /* start of rowset (an absolute row
* number) */
int bind_row; /* current offset for Multiple row/column
* binding */
Int4 from_pos;
Int4 where_pos;
Int4 last_fetch_count_include_ommitted;
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
CRITICAL_SECTION cs;
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+ pthread_mutex_t cs;
#endif /* WIN_MULTITHREAD_SUPPORT */
};
#define SC_is_fetchcursor(a) ((a->miscinfo & 2L) != 0)
/* For Multi-thread */
-#ifdef WIN_MULTITHREAD_SUPPORT
+#if defined(WIN_MULTITHREAD_SUPPORT)
#define INIT_STMT_CS(x) InitializeCriticalSection(&((x)->cs))
#define ENTER_STMT_CS(x) EnterCriticalSection(&((x)->cs))
#define LEAVE_STMT_CS(x) LeaveCriticalSection(&((x)->cs))
#define DELETE_STMT_CS(x) DeleteCriticalSection(&((x)->cs))
+#elif defined(POSIX_MULTITHREAD_SUPPORT)
+#define INIT_STMT_CS(x) pthread_mutex_init(&((x)->cs),0)
+#define ENTER_STMT_CS(x) pthread_mutex_lock(&((x)->cs))
+#define LEAVE_STMT_CS(x) pthread_mutex_unlock(&((x)->cs))
+#define DELETE_STMT_CS(x) pthread_mutex_destroy(&((x)->cs))
#else
#define INIT_STMT_CS(x)
#define ENTER_STMT_CS(x)
"$(INTDIR)\execute.obj" \
"$(INTDIR)\info.obj" \
"$(INTDIR)\lobj.obj" \
- "$(INTDIR)\win_md5.obj"
+ "$(INTDIR)\win_md5.obj" \
"$(INTDIR)\misc.obj" \
!IF "$(CFG)" == "MultibyteDebug"
"$(INTDIR)\multibyte.obj" \
"$(INTDIR)\info.obj" \
"$(INTDIR)\info30.obj" \
"$(INTDIR)\lobj.obj" \
- "$(INTDIR)\win_md5.obj"
+ "$(INTDIR)\win_md5.obj" \
"$(INTDIR)\misc.obj" \
!IF "$(CFG)" == "MultibyteDebug30"
"$(INTDIR)\multibyte.obj" \