Skip to content

Commit

Permalink
Fix path length issue with ibmdb on Windows (#228)
Browse files Browse the repository at this point in the history
add the CLI Driver path to list of DLL search paths only once if there are many DB connections
  • Loading branch information
amochin authored Oct 11, 2024
1 parent 1182dd0 commit 4cde94d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/common_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ jobs:
MYSQL_DRIVER: mysql-connector-odbc-8.0.22-linux-glibc2.12-x86-64bit

- name: Check ODBC setup
if: matrix.py_db_module == 'pyodbc'
run: |
echo "*** odbcinst -j"
odbcinst -j
Expand Down
27 changes: 15 additions & 12 deletions src/DatabaseLibrary/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class ConnectionManager:
def __init__(self):
self.omit_trailing_semicolon: bool = False
self.connection_store: ConnectionStore = ConnectionStore()
self.ibmdb_driver_already_added_to_path: bool = False

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

if db_api_module_name in ["ibm_db", "ibm_db_dbi"]:
if os.name == "nt":
spec = importlib.util.find_spec(db_api_module_name)
if spec is not None:
logger.info(
f"Importing DB module '{db_api_module_name}' on Windows requires configuring the DLL directory for CLI driver"
)
site_packages_path = os.path.dirname(spec.origin)
clidriver_bin_path = os.path.join(site_packages_path, "clidriver", "bin")
if os.path.exists(clidriver_bin_path):
os.add_dll_directory(clidriver_bin_path)
logger.info(f"Added default CLI driver location to DLL search path: '{clidriver_bin_path}'")
else:
logger.info(f"Default CLI driver location folder not found: '{clidriver_bin_path}'")
if not self.ibmdb_driver_already_added_to_path:
spec = importlib.util.find_spec(db_api_module_name)
if spec is not None:
logger.info(
f"Importing DB module '{db_api_module_name}' on Windows requires configuring the DLL directory for CLI driver"
)
site_packages_path = os.path.dirname(spec.origin)
clidriver_bin_path = os.path.join(site_packages_path, "clidriver", "bin")
if os.path.exists(clidriver_bin_path):
os.add_dll_directory(clidriver_bin_path)
self.ibmdb_driver_already_added_to_path = True
logger.info(f"Added default CLI driver location to DLL search path: '{clidriver_bin_path}'")
else:
logger.info(f"Default CLI driver location folder not found: '{clidriver_bin_path}'")

db_api_2 = importlib.import_module(db_api_module_name)

Expand Down

0 comments on commit 4cde94d

Please sign in to comment.