Skip to content

Commit 26365e1

Browse files
committed
ibm_db - set driver path to DLL libs (fix #223)
1 parent d4ba70a commit 26365e1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/DatabaseLibrary/connection_manager.py

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import importlib
16+
import os
1617
from configparser import ConfigParser, NoOptionError, NoSectionError
1718
from dataclasses import dataclass
1819
from pathlib import Path
@@ -316,6 +317,22 @@ def _arg_or_config(arg_value, param_name, *, old_param_name=None, mandatory=Fals
316317
db_api_module_name = "pyodbc"
317318
else:
318319
db_api_module_name = db_module
320+
321+
if db_api_module_name in ["ibm_db", "ibm_db_dbi"]:
322+
if os.name == "nt":
323+
spec = importlib.util.find_spec("ibm_db")
324+
if spec is not None:
325+
logger.info(
326+
f"Importing DB module '{db_api_module_name}' on Windows requires configuring the DLL directory for CLI driver"
327+
)
328+
site_packages_path = os.path.dirname(spec.origin)
329+
clidriver_bin_path = os.path.join(site_packages_path, "clidriver", "bin")
330+
if os.path.exists(clidriver_bin_path):
331+
os.add_dll_directory(clidriver_bin_path)
332+
logger.info(f"Added default CLI driver location to DLL search path: '{clidriver_bin_path}'")
333+
else:
334+
logger.info(f"Default CLI driver location folder not found: '{clidriver_bin_path}'")
335+
319336
db_api_2 = importlib.import_module(db_api_module_name)
320337

321338
if db_module in ["MySQLdb", "pymysql"]:

0 commit comments

Comments
 (0)