diff --git a/autotest/ogr/ogr_pgeo.py b/autotest/ogr/ogr_pgeo.py index 66f4a3f39aed..8cdb442ba6d6 100755 --- a/autotest/ogr/ogr_pgeo.py +++ b/autotest/ogr/ogr_pgeo.py @@ -30,6 +30,7 @@ ############################################################################### import os +import shutil import sys import gdaltest @@ -977,3 +978,14 @@ def test_ogr_openfilegdb_read_relationships(): assert rel.GetForwardPathLabel() == "attachment" assert rel.GetBackwardPathLabel() == "object" assert rel.GetRelatedTableType() == "media" + + +def test_ogr_pgeo_non_ascii(tmp_path): + + non_ascii_filename = str(tmp_path / "éé.mdb") + shutil.copy("data/pgeo/sample.mdb", non_ascii_filename) + + pgeo_ds = ogr.Open(non_ascii_filename) + assert pgeo_ds is not None + + assert pgeo_ds.GetLayerCount() == 4 diff --git a/port/cpl_odbc.cpp b/port/cpl_odbc.cpp index 7996994807ed..f354ab592021 100644 --- a/port/cpl_odbc.cpp +++ b/port/cpl_odbc.cpp @@ -717,6 +717,16 @@ int CPLODBCSession::EstablishSession(const char *pszDSN, const char *pszUserid, if (pszPassword == nullptr) pszPassword = ""; + std::string osDSN(pszDSN); +#if defined(_WIN32) && !defined(NETCDF_USES_UTF8) + if (CPLTestBool(CPLGetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"))) + { + char *pszTemp = CPLRecode(pszDSN, CPL_ENC_UTF8, "CP_ACP"); + osDSN = pszTemp; + CPLFree(pszTemp); + } +#endif + bool bFailed = false; if (strstr(pszDSN, "=") != nullptr) { @@ -726,7 +736,7 @@ int CPLODBCSession::EstablishSession(const char *pszDSN, const char *pszUserid, bFailed = CPL_TO_BOOL(Failed(SQLDriverConnect( m_hDBC, nullptr, - reinterpret_cast(const_cast(pszDSN)), + reinterpret_cast(const_cast(osDSN.c_str())), static_cast(strlen(pszDSN)), szOutConnString, sizeof(szOutConnString), &nOutConnStringLen, SQL_DRIVER_NOPROMPT))); } @@ -734,7 +744,8 @@ int CPLODBCSession::EstablishSession(const char *pszDSN, const char *pszUserid, { CPLDebug("ODBC", "SQLConnect(%s)", pszDSN); bFailed = CPL_TO_BOOL(Failed(SQLConnect( - m_hDBC, reinterpret_cast(const_cast(pszDSN)), + m_hDBC, + reinterpret_cast(const_cast(osDSN.c_str())), SQL_NTS, reinterpret_cast(const_cast(pszUserid)), SQL_NTS, reinterpret_cast(const_cast(pszPassword)),