From adedecb572e2c999d8ad9675933b4baa91649261 Mon Sep 17 00:00:00 2001 From: Earamma K Date: Thu, 16 Apr 2026 16:58:49 +0530 Subject: [PATCH 1/2] add SQL_ATTR_DEFERRED_PREPARE support and update INSTALL.md for ibm_db DLL loading on Windows Signed-off-by: Earamma K --- INSTALL.md | 37 ++++++++++++++++++++++--------------- ibm_db.c | 4 ++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index af4da9b5..1ce92cb6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -85,31 +85,38 @@ pip install ibm_db --no-binary :all: --no-cache-dir - When ibm_db get installed from wheel package, you can find clidriver under site_packages directory of Python. You need to copy license file under `site_packages/clidriver/license` to be effective, if any. -**Note:** For windows after installing `ibm_db`, recieves the below error when we try to import ibm_db : +**Windows DLL resolution (Python 3.8+):** -```>python -Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32 -Type "help", "copyright", "credits" or "license" for more information. ->>> import ibm_db -Traceback (most recent call last): - File "", line 1, in -ImportError: DLL load failed while importing ibm_db: The specified module could not be found. ->>> +Since Python 3.8, the `PATH` environment variable is no longer used for DLL resolution on Windows (see https://bugs.python.org/issue36085). The `ibm_db` package now handles this **automatically** by installing an `ibm_db_dll.pth` file into `site-packages`. This file runs at Python startup and registers the clidriver `bin` directory via `os.add_dll_directory()`, so `import ibm_db` works out of the box. + +If `IBM_DB_HOME` is set, the `.pth` file uses `%IBM_DB_HOME%\bin`; otherwise it uses the bundled `site-packages\clidriver\bin`. + +**If you still see `ImportError: DLL load failed` after a fresh install**, verify that the `.pth` file exists: + +``` +python -c "import os, sysconfig; print(os.path.isfile(os.path.join(sysconfig.get_path('purelib'), 'ibm_db_dll.pth')))" ``` -We need to make sure to set dll path of dependent library of clidriver before importing the module as: +If it prints `False`, reinstall ibm_db: ``` +pip uninstall ibm_db +pip install ibm_db +``` + +**Manual fallback:** If the automatic fix does not work in your environment, you can set the DLL path directly in your code before importing the module: + +```python import os os.add_dll_directory('path to clidriver installation until bin') import ibm_db - -e.g: -os.add_dll_directory('C:\\Program Files\\IBM\\CLIDRIVER\\bin') -import ibm_db ``` -Refer https://bugs.python.org/issue36085 for more details. +To find your clidriver `bin` path, run: + +``` +python -c "import os, site, sysconfig; paths=[os.path.join(site.getusersitepackages(),'clidriver','bin'), os.path.join(sysconfig.get_path('purelib'),'clidriver','bin')]; print(next((p for p in paths if os.path.isdir(p)), 'clidriver not found - reinstall ibm_db'))" +``` #### 1.2 Manual Installation diff --git a/ibm_db.c b/ibm_db.c index f549b440..99e3485d 100644 --- a/ibm_db.c +++ b/ibm_db.c @@ -16604,6 +16604,7 @@ static PyObject *ibm_db_get_option(PyObject *self, PyObject *args) case SQL_ATTR_ROWCOUNT_PREFETCH: case SQL_ATTR_QUERY_TIMEOUT: #ifndef __MVS__ + case SQL_ATTR_DEFERRED_PREPARE: case SQL_ATTR_CALL_RETURN: #endif isInteger = 1; @@ -19331,6 +19332,9 @@ INIT_ibm_db(void) PyModule_AddIntConstant(m, "SQL_ATTR_PARAMSET_SIZE", SQL_ATTR_PARAMSET_SIZE); PyModule_AddIntConstant(m, "SQL_ATTR_PARAM_BIND_TYPE", SQL_ATTR_PARAM_BIND_TYPE); PyModule_AddIntConstant(m, "SQL_PARAM_BIND_BY_COLUMN", SQL_PARAM_BIND_BY_COLUMN); +#ifndef __MVS__ + PyModule_AddIntConstant(m, "SQL_ATTR_DEFERRED_PREPARE", SQL_ATTR_DEFERRED_PREPARE); +#endif PyModule_AddIntConstant(m, "SQL_ATTR_XML_DECLARATION", SQL_ATTR_XML_DECLARATION); #ifndef __MVS__ PyModule_AddIntConstant(m, "SQL_ATTR_CLIENT_APPLCOMPAT", SQL_ATTR_CLIENT_APPLCOMPAT); From 1d0a1240f06cbd74be2ca1f95aca2c88a96cedab Mon Sep 17 00:00:00 2001 From: Earamma K Date: Thu, 16 Apr 2026 17:15:51 +0530 Subject: [PATCH 2/2] Add SQL_ATTR_DEFERRED_PREPARE attribute support, updated README.md and INSTALL.md for ibm_db DLL loading on Windows Signed-off-by: Earamma K --- INSTALL.md | 11 ++++++++++- README.md | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 1ce92cb6..35848249 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -87,7 +87,16 @@ pip install ibm_db --no-binary :all: --no-cache-dir **Windows DLL resolution (Python 3.8+):** -Since Python 3.8, the `PATH` environment variable is no longer used for DLL resolution on Windows (see https://bugs.python.org/issue36085). The `ibm_db` package now handles this **automatically** by installing an `ibm_db_dll.pth` file into `site-packages`. This file runs at Python startup and registers the clidriver `bin` directory via `os.add_dll_directory()`, so `import ibm_db` works out of the box. +Since Python 3.8, the `PATH` environment variable is no longer used for DLL resolution on Windows (see https://bugs.python.org/issue36085). You may see the following error when importing `ibm_db`: + +``` +>>> import ibm_db +Traceback (most recent call last): + File "", line 1, in +ImportError: DLL load failed while importing ibm_db: The specified module could not be found. +``` + +The `ibm_db` package now handles this **automatically** by installing an `ibm_db_dll.pth` file into `site-packages`. This file runs at Python startup and registers the clidriver `bin` directory via `os.add_dll_directory()`, so `import ibm_db` works out of the box. If `IBM_DB_HOME` is set, the `.pth` file uses `%IBM_DB_HOME%\bin`; otherwise it uses the bundled `site-packages\clidriver\bin`. diff --git a/README.md b/README.md index 9429e678..bee09f02 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,16 @@ pip install ibm_db --no-binary :all: --no-cache-dir **Windows DLL resolution (Python 3.8+):** -Since Python 3.8, the `PATH` environment variable is no longer used for DLL resolution on Windows (see https://bugs.python.org/issue36085). The `ibm_db` package now handles this **automatically** by installing an `ibm_db_dll.pth` file into `site-packages`. This file runs at Python startup and registers the clidriver `bin` directory via `os.add_dll_directory()`, so `import ibm_db` works out of the box. +Since Python 3.8, the `PATH` environment variable is no longer used for DLL resolution on Windows (see https://bugs.python.org/issue36085). You may see the following error when importing `ibm_db`: + +``` +>>> import ibm_db +Traceback (most recent call last): + File "", line 1, in +ImportError: DLL load failed while importing ibm_db: The specified module could not be found. +``` + +The `ibm_db` package now handles this **automatically** by installing an `ibm_db_dll.pth` file into `site-packages`. This file runs at Python startup and registers the clidriver `bin` directory via `os.add_dll_directory()`, so `import ibm_db` works out of the box. If `IBM_DB_HOME` is set, the `.pth` file uses `%IBM_DB_HOME%\bin`; otherwise it uses the bundled `site-packages\clidriver\bin`.