From fb62b7b8a79b46e2d2744eb00419b310b4248415 Mon Sep 17 00:00:00 2001 From: ek Date: Thu, 27 Jun 2024 18:40:31 +0530 Subject: [PATCH 1/2] Fix for libdb2 for createdb and dropdb --- ibm_db.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/ibm_db.c b/ibm_db.c index 8c04c207..f59ef6f3 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,6 @@ 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" ); - return -1; -#else if ( !NIL_P( conn_res ) ) { if ( NIL_P( dbNameObj ) ) { @@ -2066,6 +2074,8 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P #ifdef _WIN32 cliLib = DLOPEN( LIBDB2 ); +#elif _AIX + cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY ); #else cliLib = DLOPEN( LIBDB2, RTLD_LAZY ); #endif @@ -2118,7 +2128,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,11 +2151,6 @@ 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" ); - return -1; -#else - if ( !NIL_P( conn_res ) ) { if ( NIL_P( dbNameObj ) ) { PyErr_SetString( PyExc_Exception, "Supplied database name Parameter is invalid" ); @@ -2167,6 +2171,8 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int #ifdef _WIN32 cliLib = DLOPEN( LIBDB2 ); +#elif _AIX + cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY ); #else cliLib = DLOPEN( LIBDB2, RTLD_LAZY ); #endif @@ -2218,7 +2224,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 From 0a19b511e93f80331b205b16e9aa453aaaf313c1 Mon Sep 17 00:00:00 2001 From: ek Date: Fri, 28 Jun 2024 14:19:58 +0530 Subject: [PATCH 2/2] Fix for libdb2 for createdb and dropdb --- ibm_db.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ibm_db.c b/ibm_db.c index f59ef6f3..715bd941 100644 --- a/ibm_db.c +++ b/ibm_db.c @@ -2033,6 +2033,10 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P sqlcreatedbType sqlcreatedb; #endif +#if defined(__MVS__) + PyErr_SetString( PyExc_Exception, "Not supported: This function not supported on this platform" ); + return -1; +#endif if ( !NIL_P( conn_res ) ) { if ( NIL_P( dbNameObj ) ) { @@ -2072,6 +2076,7 @@ static int _python_ibm_db_createdb(conn_handle *conn_res, PyObject *dbNameObj, P } } +#ifndef __MVS__ #ifdef _WIN32 cliLib = DLOPEN( LIBDB2 ); #elif _AIX @@ -2085,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" ); @@ -2151,6 +2157,11 @@ static int _python_ibm_db_dropdb(conn_handle *conn_res, PyObject *dbNameObj, int void *cliLib; #endif +#if defined(__MVS__) + PyErr_SetString( PyExc_Exception, "Not supported: This function not supported on this platform" ); + return -1; +#endif + if ( !NIL_P( conn_res ) ) { if ( NIL_P( dbNameObj ) ) { PyErr_SetString( PyExc_Exception, "Supplied database name Parameter is invalid" ); @@ -2168,7 +2179,7 @@ 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 @@ -2182,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" );