Skip to content

Commit

Permalink
Merge pull request #10961 from rouault/fix_10960
Browse files Browse the repository at this point in the history
CPLODBCSession::EstablishSession(): recode DSN to Windows current ANSI page
  • Loading branch information
rouault authored Oct 8, 2024
2 parents 2f07a3d + 9fb9511 commit b7dc483
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions autotest/ogr/ogr_pgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
###############################################################################

import os
import shutil
import sys

import gdaltest
Expand Down Expand Up @@ -961,3 +962,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
15 changes: 13 additions & 2 deletions port/cpl_odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,16 @@ int CPLODBCSession::EstablishSession(const char *pszDSN, const char *pszUserid,
if (pszPassword == nullptr)
pszPassword = "";

std::string osDSN(pszDSN);
#if defined(_WIN32)
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)
{
Expand All @@ -710,15 +720,16 @@ int CPLODBCSession::EstablishSession(const char *pszDSN, const char *pszUserid,

bFailed = CPL_TO_BOOL(Failed(SQLDriverConnect(
m_hDBC, nullptr,
reinterpret_cast<SQLCHAR *>(const_cast<char *>(pszDSN)),
reinterpret_cast<SQLCHAR *>(const_cast<char *>(osDSN.c_str())),
static_cast<SQLSMALLINT>(strlen(pszDSN)), szOutConnString,
sizeof(szOutConnString), &nOutConnStringLen, SQL_DRIVER_NOPROMPT)));
}
else
{
CPLDebug("ODBC", "SQLConnect(%s)", pszDSN);
bFailed = CPL_TO_BOOL(Failed(SQLConnect(
m_hDBC, reinterpret_cast<SQLCHAR *>(const_cast<char *>(pszDSN)),
m_hDBC,
reinterpret_cast<SQLCHAR *>(const_cast<char *>(osDSN.c_str())),
SQL_NTS, reinterpret_cast<SQLCHAR *>(const_cast<char *>(pszUserid)),
SQL_NTS,
reinterpret_cast<SQLCHAR *>(const_cast<char *>(pszPassword)),
Expand Down

0 comments on commit b7dc483

Please sign in to comment.