From f29f531630aa60ec9ec58a7c6ad7f177e732ef24 Mon Sep 17 00:00:00 2001 From: Earammak <107038275+Earammak@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:45:49 +0530 Subject: [PATCH] Fix for libdb2 for createdb and dropdb (#953) * Fix for libdb2 for createdb and dropdb --- ibm_db.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/ibm_db.c b/ibm_db.c index 8c04c207..715bd941 100644 --- a/ibm_db.c +++ b/ibm_db.c @@ -57,25 +57,37 @@ static PyObject* getSQLWCharAsPyUnicodeObject(SQLWCHAR* sqlwcharData, int sqlwch const int _check_i = 1; #define is_bigendian() ( (*(char*)&_check_i) == 0 ) static int is_systemi, is_informix; /* 1 == TRUE; 0 == FALSE; */ + #ifdef _WIN32 #define DLOPEN LoadLibrary #define DLSYM GetProcAddress #define DLCLOSE FreeLibrary +#ifdef _WIN64 +#define LIBDB2 "db2cli64.dll" +#else +#define LIBDB2 "db2cli.dll" +#endif #elif _AIX #define DLOPEN dlopen #define DLSYM dlsym #define DLCLOSE dlclose -#define LIBDB2 "libdb2.a" +#ifdef __64BIT__ +/*64-bit library in the archive libdb2.a*/ +#define LIBDB2 "libdb2.a(shr_64.o)" #else +/*32-bit library in the archive libdb2.a*/ +#define LIBDB2 "libdb2.a(shr.o)" +#endif +#elif __APPLE__ #define DLOPEN dlopen #define DLSYM dlsym #define DLCLOSE dlclose -#define LIBDB2 "libdb2.so.1" -#endif -#ifdef _WIN64 -#define LIBDB2 "db2cli64.dll" +#define LIBDB2 "libdb2.dylib" #else -#define LIBDB2 "db2cli.dll" +#define DLOPEN dlopen +#define DLSYM dlsym +#define DLCLOSE dlclose +#define LIBDB2 "libdb2.so.1" #endif /* Defines a linked list structure for error messages */ @@ -2021,10 +2033,10 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P sqlcreatedbType sqlcreatedb; #endif -#if defined __APPLE__ || defined _AIX - PyErr_SetString( PyExc_Exception, "Not supported: This function is currently not supported on this platform" ); +#if defined(__MVS__) + PyErr_SetString( PyExc_Exception, "Not supported: This function not supported on this platform" ); return -1; -#else +#endif if ( !NIL_P( conn_res ) ) { if ( NIL_P( dbNameObj ) ) { @@ -2064,8 +2076,11 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P } } +#ifndef __MVS__ #ifdef _WIN32 cliLib = DLOPEN( LIBDB2 ); +#elif _AIX + cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY ); #else cliLib = DLOPEN( LIBDB2, RTLD_LAZY ); #endif @@ -2075,6 +2090,7 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P _python_clear_local_var( dbNameObj, dbName, codesetObj, codeset, modeObj, mode, isNewBuffer ); return -1; } +#endif Py_BEGIN_ALLOW_THREADS; #ifdef _WIN32 sqlcreatedb = DLSYM( cliLib, "SQLCreateDbW" ); @@ -2118,7 +2134,6 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P PyErr_SetString( PyExc_Exception, "Supplied connection object Parameter is invalid" ); return -1; } -#endif } /* @@ -2142,10 +2157,10 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int void *cliLib; #endif -#if defined __APPLE__ || defined _AIX - PyErr_SetString( PyExc_Exception, "Not supported: This function is currently not supported on this platform" ); +#if defined(__MVS__) + PyErr_SetString( PyExc_Exception, "Not supported: This function not supported on this platform" ); return -1; -#else +#endif if ( !NIL_P( conn_res ) ) { if ( NIL_P( dbNameObj ) ) { @@ -2164,9 +2179,11 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int } else { return -1; } - +#ifndef __MVS__ #ifdef _WIN32 cliLib = DLOPEN( LIBDB2 ); +#elif _AIX + cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY ); #else cliLib = DLOPEN( LIBDB2, RTLD_LAZY ); #endif @@ -2176,6 +2193,7 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int _python_clear_local_var( dbNameObj, dbName, NULL, NULL, NULL, NULL, isNewBuffer ); return -1; } +#endif Py_BEGIN_ALLOW_THREADS; #ifdef _WIN32 sqldropdb = DLSYM( cliLib, "SQLDropDbW" ); @@ -2218,7 +2236,6 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int PyErr_SetString( PyExc_Exception, "Supplied connection object Parameter is invalid" ); return -1; } -#endif } /*!# ibm_db.createdb