Skip to content

Commit

Permalink
CPLODBCSession::EstablishSession(): recode DSN to Windows current ANS…
Browse files Browse the repository at this point in the history
…I page
  • Loading branch information
rouault committed Oct 7, 2024
1 parent 46ad0f1 commit 9541573
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 @@ -30,6 +30,7 @@
###############################################################################

import os
import shutil
import sys

import gdaltest
Expand Down Expand Up @@ -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
15 changes: 13 additions & 2 deletions port/cpl_odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -726,15 +736,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 9541573

Please sign in to comment.