Skip to content

Commit

Permalink
Add IBM DB driver to path only once
Browse files Browse the repository at this point in the history
  • Loading branch information
amochin committed Oct 11, 2024
1 parent 1182dd0 commit 37a15b2
Showing 1 changed file with 15 additions and 12 deletions.
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 37a15b2

Please sign in to comment.