Skip to content

Commit 4cde94d

Browse files
authored
Fix path length issue with ibmdb on Windows (#228)
add the CLI Driver path to list of DLL search paths only once if there are many DB connections
1 parent 1182dd0 commit 4cde94d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

.github/workflows/common_tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ jobs:
115115
MYSQL_DRIVER: mysql-connector-odbc-8.0.22-linux-glibc2.12-x86-64bit
116116

117117
- name: Check ODBC setup
118+
if: matrix.py_db_module == 'pyodbc'
118119
run: |
119120
echo "*** odbcinst -j"
120121
odbcinst -j

src/DatabaseLibrary/connection_manager.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class ConnectionManager:
143143
def __init__(self):
144144
self.omit_trailing_semicolon: bool = False
145145
self.connection_store: ConnectionStore = ConnectionStore()
146+
self.ibmdb_driver_already_added_to_path: bool = False
146147

147148
@staticmethod
148149
def _hide_password_values(string_with_pass, params_separator=","):
@@ -320,18 +321,20 @@ def _arg_or_config(arg_value, param_name, *, old_param_name=None, mandatory=Fals
320321

321322
if db_api_module_name in ["ibm_db", "ibm_db_dbi"]:
322323
if os.name == "nt":
323-
spec = importlib.util.find_spec(db_api_module_name)
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}'")
324+
if not self.ibmdb_driver_already_added_to_path:
325+
spec = importlib.util.find_spec(db_api_module_name)
326+
if spec is not None:
327+
logger.info(
328+
f"Importing DB module '{db_api_module_name}' on Windows requires configuring the DLL directory for CLI driver"
329+
)
330+
site_packages_path = os.path.dirname(spec.origin)
331+
clidriver_bin_path = os.path.join(site_packages_path, "clidriver", "bin")
332+
if os.path.exists(clidriver_bin_path):
333+
os.add_dll_directory(clidriver_bin_path)
334+
self.ibmdb_driver_already_added_to_path = True
335+
logger.info(f"Added default CLI driver location to DLL search path: '{clidriver_bin_path}'")
336+
else:
337+
logger.info(f"Default CLI driver location folder not found: '{clidriver_bin_path}'")
335338

336339
db_api_2 = importlib.import_module(db_api_module_name)
337340

0 commit comments

Comments
 (0)