diff --git a/mssql_python/libs/macos/lib/libltdl.7.dylib b/mssql_python/libs/macos/lib/libltdl.7.dylib index e0999cec..c9a76757 100644 Binary files a/mssql_python/libs/macos/lib/libltdl.7.dylib and b/mssql_python/libs/macos/lib/libltdl.7.dylib differ diff --git a/mssql_python/libs/macos/lib/libmsodbcsql.18.dylib b/mssql_python/libs/macos/lib/libmsodbcsql.18.dylib index 56605d67..ab929d06 100755 Binary files a/mssql_python/libs/macos/lib/libmsodbcsql.18.dylib and b/mssql_python/libs/macos/lib/libmsodbcsql.18.dylib differ diff --git a/mssql_python/libs/macos/lib/libodbcinst.2.dylib b/mssql_python/libs/macos/lib/libodbcinst.2.dylib index d8a149f9..83a60102 100755 Binary files a/mssql_python/libs/macos/lib/libodbcinst.2.dylib and b/mssql_python/libs/macos/lib/libodbcinst.2.dylib differ diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index bbc1dd50..8d42a560 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -102,6 +102,7 @@ else() message(STATUS "Auto-detected pybind11 include directory: ${PYBIND11_INCLUDE_DIR}") endif() + # Find Python Library for linking execute_process( COMMAND python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))" @@ -154,8 +155,29 @@ if(APPLE AND (NOT PYTHON_LIB_DIR OR "${PYTHON_LIB_DIR}" STREQUAL "")) message(STATUS "Python library not found in standard locations, will try using framework") # When using a framework, we don't specify the library directly endif() +elseif(WIN32 AND (NOT PYTHON_LIB_DIR OR "${PYTHON_LIB_DIR}" STREQUAL "" OR "${PYTHON_LIB_DIR}" STREQUAL "None")) + # On Windows, if PYTHON_LIB_DIR is not set, we will try to find it using sysconfig + message(STATUS "PYTHON_LIB_DIR is None or empty for Windows, trying to find it using sysconfig") + # Use Python Executable to find the library directory + execute_process( + COMMAND python -c "import sys, os; print(os.path.dirname(sys.executable))" + OUTPUT_VARIABLE PYTHON_EXEC_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "Python executable directory: ${PYTHON_EXEC_DIR}") + # Set the library directory based on the executable directory + set(PYTHON_LIB_DIR "${PYTHON_EXEC_DIR}/libs") + message(STATUS "Using Python library directory: ${PYTHON_LIB_DIR}") endif() +if(DEFINED ENV{CUSTOM_PYTHON_LIB_DIR} AND NOT "$ENV{CUSTOM_PYTHON_LIB_DIR}" STREQUAL "" AND NOT "$ENV{CUSTOM_PYTHON_LIB_DIR}" STREQUAL "None") + message(STATUS "CUSTOM_PYTHON_LIB_DIR is set, using it") + set(PYTHON_LIB_DIR $ENV{CUSTOM_PYTHON_LIB_DIR}) + message(STATUS "Using custom Python library directory: ${PYTHON_LIB_DIR}") +endif() + +message(STATUS "Final Python library directory: ${PYTHON_LIB_DIR}") + # Determine which source file to use based on platform if(APPLE) set(DDBC_SOURCE "ddbc_bindings_mac.cpp") diff --git a/mssql_python/pybind/configure_dylibs.sh b/mssql_python/pybind/configure_dylibs.sh index 35ea68d9..bff2bebe 100755 --- a/mssql_python/pybind/configure_dylibs.sh +++ b/mssql_python/pybind/configure_dylibs.sh @@ -66,8 +66,8 @@ done <<< "$OTOOL_LIST" if [ -n "$OLD_LIBODBCINST_PATH" ]; then echo "Fixing libmsodbcsql.18.dylib dependency on libodbcinst.2.dylib..." echo " Changing: $OLD_LIBODBCINST_PATH" - echo " To: $LIBODBCINST_PATH" - install_name_tool -change "$OLD_LIBODBCINST_PATH" "$LIBODBCINST_PATH" "$LIBMSODBCSQL_PATH" + echo " To: @loader_path/libodbcinst.2.dylib" + install_name_tool -change "$OLD_LIBODBCINST_PATH" "@loader_path/libodbcinst.2.dylib" "$LIBMSODBCSQL_PATH" else echo "Warning: libodbcinst dependency not found in libmsodbcsql.18.dylib" fi @@ -75,13 +75,27 @@ fi if [ -n "$OLD_LIBLTDL_PATH" ] && [ -f "$LIBLTDL_PATH" ]; then echo "Fixing libodbcinst.2.dylib dependency on libltdl.7.dylib..." echo " Changing: $OLD_LIBLTDL_PATH" - echo " To: $LIBLTDL_PATH" - install_name_tool -change "$OLD_LIBLTDL_PATH" "$LIBLTDL_PATH" "$LIBODBCINST_PATH" + echo " To: @loader_path/libltdl.7.dylib" + install_name_tool -change "$OLD_LIBLTDL_PATH" "@loader_path/libltdl.7.dylib" "$LIBODBCINST_PATH" else echo "Note: libltdl dependency not found or not needed" fi # Force codesign the dylibs + +# First set the IDs of the libraries using @loader_path +echo "Setting library IDs with @loader_path..." +echo "Setting ID for libmsodbcsql.18.dylib..." +install_name_tool -id "@loader_path/libmsodbcsql.18.dylib" "$LIBMSODBCSQL_PATH" + +echo "Setting ID for libodbcinst.2.dylib..." +install_name_tool -id "@loader_path/libodbcinst.2.dylib" "$LIBODBCINST_PATH" + +if [ -f "$LIBLTDL_PATH" ]; then + echo "Setting ID for libltdl.7.dylib..." + install_name_tool -id "@loader_path/libltdl.7.dylib" "$LIBLTDL_PATH" +fi + echo "Codesigning libmsodbcsql.18.dylib..." codesign -s - -f "$LIBMSODBCSQL_PATH" 2>/dev/null diff --git a/mssql_python/pybind/ddbc_bindings_mac.cpp b/mssql_python/pybind/ddbc_bindings_mac.cpp index 094c6206..85b39001 100644 --- a/mssql_python/pybind/ddbc_bindings_mac.cpp +++ b/mssql_python/pybind/ddbc_bindings_mac.cpp @@ -1083,23 +1083,34 @@ ErrorInfo SQLCheckError_Wrap(SQLSMALLINT handleType, intptr_t handle, SQLRETURN std::wstring SanitizeConnectionString(const std::wstring& connectionString) { // This function will remove the UID and Pwd parameters for security reasons std::wstring sanitizedString = connectionString; - // Remove UID and Pwd parameters - size_t uidPos = sanitizedString.find(L"UID="); + std::wstring lowerCaseString = sanitizedString; + // Convert the string to lowercase for case-insensitive search + // Using lowerCaseString to avoid modifying the original string + // This is necessary because towlower works on wide characters + std::transform(lowerCaseString.begin(), lowerCaseString.end(), lowerCaseString.begin(), + ::towlower); + // Can be UID or uid or UID, test only on lowercase uid + size_t uidPos = lowerCaseString.find(L"uid="); if (uidPos != std::wstring::npos) { size_t endPos = sanitizedString.find(L';', uidPos); if (endPos != std::wstring::npos) { sanitizedString.erase(uidPos, endPos - uidPos + 1); + lowerCaseString.erase(uidPos, endPos - uidPos + 1); } else { sanitizedString.erase(uidPos); + lowerCaseString.erase(uidPos); } } - size_t pwdPos = sanitizedString.find(L"Pwd="); + // Can be Pwd or pwd or PWD, test only on lowercase pwd + size_t pwdPos = lowerCaseString.find(L"pwd="); if (pwdPos != std::wstring::npos) { size_t endPos = sanitizedString.find(L';', pwdPos); if (endPos != std::wstring::npos) { sanitizedString.erase(pwdPos, endPos - pwdPos + 1); + lowerCaseString.erase(pwdPos, endPos - pwdPos + 1); } else { sanitizedString.erase(pwdPos); + lowerCaseString.erase(pwdPos); } } return sanitizedString; diff --git a/setup.py b/setup.py index 8a160703..090fb353 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import sys from setuptools import setup, find_packages from setuptools.dist import Distribution -from setuptools.command.bdist_wheel import bdist_wheel +from wheel.bdist_wheel import bdist_wheel # Custom distribution to force platform-specific wheel class BinaryDistribution(Distribution):