Skip to content

Commit

Permalink
Support for python3.12 (#913)
Browse files Browse the repository at this point in the history
* Support for python3.12

Signed-off-by: Balram Choudhary <[email protected]>
  • Loading branch information
bchoudhary6415 authored Feb 19, 2024
1 parent 443cd61 commit 89e5f29
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/bld_wheels_and_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
matrix:
os: [windows-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.1
- name: Build wheels
uses: pypa/cibuildwheel@v2.12.2
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_BUILD: "*-win_amd64"
CIBW_SKIP: "cp36-* pp*"
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4.3.1
with:
path: ./wheelhouse/*.whl

Expand All @@ -36,9 +36,9 @@ jobs:
matrix:
os: [windows-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.1
- name: Build wheels
uses: pypa/cibuildwheel@v2.12.2
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_BUILD: "*-win32"
CIBW_SKIP: "cp36-* pp*"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://github.com/ibmdb/python-ibmdb/wiki/APIs

<a name="prereq"></a>
## Pre-requisites
Install Python 3.7 <= 3.11. The minimum python version supported by driver is python 3.7 and the latest version supported is python 3.11.
Install Python 3.7 <= 3.12. The minimum python version supported by driver is python 3.7 and the latest version supported is python 3.12.

### To install ibm_db on z/OS system

Expand Down
24 changes: 12 additions & 12 deletions ibm_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1438,19 +1438,19 @@ static PyObject *_python_ibm_db_connect_helper( PyObject *self, PyObject *args,
#ifdef __MVS__
rc = SQLConnectW((SQLHDBC)conn_res->hdbc,
database,
PyUnicode_GetSize(databaseObj)*2,
PyUnicode_GetLength(databaseObj)*2,
uid,
PyUnicode_GetSize(uidObj)*2,
PyUnicode_GetLength(uidObj)*2,
password,
PyUnicode_GetSize(passwordObj)*2);
PyUnicode_GetLength(passwordObj)*2);
#else
rc = SQLConnectW((SQLHDBC)conn_res->hdbc,
database,
PyUnicode_GetSize(databaseObj),
PyUnicode_GetLength(databaseObj),
uid,
PyUnicode_GetSize(uidObj),
PyUnicode_GetLength(uidObj),
password,
PyUnicode_GetSize(passwordObj));
PyUnicode_GetLength(passwordObj));
#endif
Py_END_ALLOW_THREADS;
}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ static PyObject* getSQLWCharAsPyUnicodeObject(SQLWCHAR* sqlwcharData, int sqlwch

if (maxuniValue <= 65536) {
/* this is UCS2 python.. nothing to do really */
return PyUnicode_FromUnicode((Py_UNICODE *)sqlwcharData, sqlwcharBytesLen / sizeof(SQLWCHAR));
return PyUnicode_FromWideChar((Py_UNICODE *)sqlwcharData, sqlwcharBytesLen / sizeof(SQLWCHAR));
}

if (is_bigendian()) {
Expand Down Expand Up @@ -1619,15 +1619,15 @@ static SQLWCHAR* getUnicodeDataAsSQLWCHAR(PyObject *pyobj, int *isNewBuffer)
long maxuniValue;
PyObject *pyUTFobj;
SQLWCHAR* pNewBuffer = NULL;
int nCharLen = PyUnicode_GET_SIZE(pyobj);
int nCharLen = PyUnicode_GET_LENGTH(pyobj);

sysmodule = PyImport_ImportModule("sys");
maxuni = PyObject_GetAttrString(sysmodule, "maxunicode");
maxuniValue = PyInt_AsLong(maxuni);

if (maxuniValue <= 65536) {
*isNewBuffer = 0;
return (SQLWCHAR*)PyUnicode_AS_UNICODE(pyobj);
return (SQLWCHAR*)PyUnicode_AsWideCharString(pyobj,maxuniValue);
}

*isNewBuffer = 1;
Expand Down Expand Up @@ -5373,7 +5373,7 @@ static PyObject *_python_ibm_db_prepare_helper(conn_handle *conn_res, PyObject *
if (PyString_Check(py_stmt) || PyUnicode_Check(py_stmt)) {
py_stmt = PyUnicode_FromObject(py_stmt);
if (py_stmt != NULL && py_stmt != Py_None) {
stmt_size = PyUnicode_GetSize(py_stmt);
stmt_size = PyUnicode_GetLength(py_stmt);
} else {
PyErr_SetString(PyExc_Exception, "Error occure during processing of statement");
return NULL;
Expand Down Expand Up @@ -5893,7 +5893,7 @@ static int _python_ibm_db_bind_data( stmt_handle *stmt_res, param_node *curr, Py
tmp_uvalue = NULL;
}
tmp_uvalue = getUnicodeDataAsSQLWCHAR(item, &isNewBuffer);
curr->ivalue = PyUnicode_GetSize(item);
curr->ivalue = PyUnicode_GetLength(item);
curr->ivalue = curr->ivalue * sizeof(SQLWCHAR);
}
param_length = curr->ivalue;
Expand Down Expand Up @@ -6060,7 +6060,7 @@ static int _python_ibm_db_bind_data( stmt_handle *stmt_res, param_node *curr, Py
curr->uvalue = NULL;
}
curr->uvalue = getUnicodeDataAsSQLWCHAR(bind_data, &isNewBuffer);
curr->ivalue = PyUnicode_GetSize(bind_data);
curr->ivalue = PyUnicode_GetLength(bind_data);
curr->ivalue = curr->ivalue * sizeof(SQLWCHAR);
}
param_length = curr->ivalue;
Expand Down
2 changes: 1 addition & 1 deletion ibm_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define StringOBJ_FromStr(str) PyUnicode_DecodeLocale(str, NULL)
#define PyString_Check PyUnicode_Check
#define StringObj_Format PyUnicode_Format
#define StringObj_Size PyUnicode_GET_SIZE
#define StringObj_Size PyUnicode_GET_LENGTH
#define MOD_RETURN_ERROR NULL
#define MOD_RETURN_VAL(mod) mod
#define INIT_ibm_db PyInit_ibm_db
Expand Down
14 changes: 10 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
import urllib2 as request
from cStringIO import StringIO as BytesIO

from distutils import ccompiler
from distutils import sysconfig as distutils_sysconfig
from distutils.sysconfig import get_python_lib
if sys.version_info.major == 3 and sys.version_info.minor >= 12:
from setuptools._distutils import ccompiler
from setuptools._distutils import sysconfig as distutils_sysconfig
from setuptools._distutils.sysconfig import get_python_lib
else:
from distutils import ccompiler
from distutils import sysconfig as distutils_sysconfig
from distutils.sysconfig import get_python_lib
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install
Expand Down Expand Up @@ -62,7 +67,7 @@ def _printAndExit(msg):

def _errormessage(option):
if(option == "downloadFailedWin"):
message = "\nPlease download the clidriver manually from the above link and unzip the contents into a particular location.\nSet the location of the directory to the system enviroment variable \"IBM_DB_HOME\"\nExample set IBM_DB_HOME=C:\downloads\db2driver\clidriver\nOnce the above settings are done please try installing ibm_db again."
message = "\nPlease download the clidriver manually from the above link and unzip the contents into a particular location.\nSet the location of the directory to the system enviroment variable \"IBM_DB_HOME\"\nExample set IBM_DB_HOME=C:/downloads/db2driver/clidriver\nOnce the above settings are done please try installing ibm_db again."
if(option == "downloadFailed"):
message = "\nPlease download the clidriver manually from the above link and untar the contents into a particular directory.\nSet the location of the directory to the system enviroment variable \"IBM_DB_HOME\"\nExample export IBM_DB_HOME=/home/db2driver/clidriver\nOnce the above settings are done try installing ibm_db again."
if(option == "includeFolderMissing"):
Expand Down Expand Up @@ -525,6 +530,7 @@ def print_exception( e, url):
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: Database :: Front-Ends'],

long_description = 'Python DBI driver for IBM Db2 for LUW, IBM Informix, IBM Db2 for iSeries(AS400) and IBM Db2 for z/OS servers',
Expand Down

0 comments on commit 89e5f29

Please sign in to comment.