Skip to content

Commit

Permalink
Fix for libdb2 for createdb and dropdb (#953)
Browse files Browse the repository at this point in the history
* Fix for libdb2 for createdb and dropdb
  • Loading branch information
Earammak authored Jun 28, 2024
1 parent b0e7026 commit f29f531
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions ibm_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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
Expand All @@ -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" );
Expand Down Expand Up @@ -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
}

/*
Expand All @@ -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 ) ) {
Expand All @@ -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
Expand All @@ -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" );
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f29f531

Please sign in to comment.