[Fdo-trac] [fdo-trac] #1018: Fix up ODBC provider on Linux
FDO
trac_fdo at osgeo.org
Wed Oct 21 01:26:11 PDT 2026
#1018: Fix up ODBC provider on Linux
---------------------------+----------------------
Reporter: jng | Owner: jng
Type: defect | Status: closed
Priority: major | Milestone: 4.2.0
Component: ODBC Provider | Version:
Severity: 3 | Resolution: fixed
Keywords: | External ID:
---------------------------+----------------------
Changes (by jng):
* resolution: => fixed
* status: assigned => closed
Comment:
In [changeset:"8417" 8417]:
{{{#!CommitTicketReference repository="" revision="8417"
Port the ODBC provider to Linux and activate its SQL Server and Access
suites
The ODBC provider built against unixODBC but had never been exercised
here: its
unit-test fixtures were all behind #ifdef _WIN32, and the shared driver
had a
number of assumptions that either only held on Windows or only held where
sizeof(long) == sizeof(int). Both provider suites now run on Linux --
OdbcSqlServerTests against Microsoft's ODBC Driver 17 for SQL Server, and
OdbcAccessTests against mdb-tools, the only file-based ODBC driver
packaged by
the distributions -- and both are green in Debug and Release.
Defects that only show on LP64
- define.c: RDBI_LONG is a C long to the RDBI layer, which sizes and
strides a
result array by sizeof(long) -- 8 here -- while get_o_t_s binds the
4-byte
SQL_C_LONG for it. The driver wrote one element per row where the
layer read
and stepped two, so every row from the second on delivered half of its
own
value and half of its neighbour's. Bind SQL_C_SBIGINT when the
caller's
buffer is wider than a SQLINTEGER.
- desc_slct.c sized RDBI_INT by sizeof(long) for the same reason;
RDBI_INT is
an int to the layer, so size it by sizeof(int).
- fetch.c stored SQL_ATTR_ROWS_FETCHED_PTR in an int. The driver writes
a
SQLULEN there, so the 8-byte store overran the adjacent stack slot.
- geom.c declared the SQLParamData token as SQLSMALLINT, which truncates
the
pointer the driver hands back. It is a SQLPOINTER, as in the SQL
Server
Spatial provider's copy of this driver.
- SchemaMgr/Ph/Mgr.cpp/.h: the ODBC reserved-word map was a class-
static, and
this file is compiled into both the provider DSO and the unit-test
executable, so its destructor ran twice at process exit. Make it a
function-local static, initialised and destroyed once.
Driver handling off Windows
- connect.c classified drivers by the Windows DLL names only, so the
Linux
SQL Server driver was never recognised; match msodbcsql and tdsodbc as
substrings of SQL_DRIVER_NAME, which off Windows is the driver
library's
file name. SQLGetInfo(SQL_DRIVER_NAME) is not implemented by every
driver
either, so treat a failure as "unknown" and fall back to SQL_DBMS_NAME
instead of failing the connection, and accept SQL_SUCCESS_WITH_INFO.
- Odbc.cpp: RDBMS_LIB_NAME lost its ".so" suffix and getComDir() matches
it as
a prefix (the loaded name is versioned, libODBCProvider-4.2.0.so) and
tolerates link-map entries with no slash, such as linux-vdso.so.1,
which
previously produced a NULL dereference.
- FdoRdbmsOdbcConnectionInfo.cpp: recognise mdb-tools as a file
provider, and
accept the Database= keyword alongside DBQ=, which is the spelling the
driver uses in a DSN.
- FdoRdbmsOdbcConnection.cpp and FdoRdbmsFilterProcessor.cpp/.h: mdb-
tools'
SQL parser accepts neither a table alias nor a table-qualified column
name,
so FDO's "SELECT T.C FROM T ALIAS" was a parse error. Add a
mUseTablePrefix
switch beside mUseTableAliases and turn both off for connections that
identify the mdb-tools driver. Every other driver keeps the SQL it
had.
mdb-tools, the Linux Access driver
- constants.h and connect.c: add ODBCDriverType_MDBTools, classified
from
SQL_DBMS_NAME, which is the only identification the driver offers.
- pkeys_.c: skip the SQLSpecialColumns approach for it. The driver
returns
success but its result set cannot be fetched -- it segfaults in libmdb
--
so identity properties come from the SQLColumns fallback.
- objects_.c: drop the VIEW rows. mdb-tools lists Access saved queries
as
views but cannot execute them, and it ignores both the name and the
type
filter passed to SQLTables, so a view could not be described or
selected.
- col_.c: describe the probe query's columns with SQLDescribeCol for
this
driver. mdb-tools implements only SQL_DESC_NAME, SQL_DESC_TYPE,
SQL_DESC_LENGTH, SQL_DESC_UNSIGNED and SQL_DESC_DISPLAY_SIZE -- every
other
SQLColAttribute is an error -- and its SQLColumns reports
SQL_UNKNOWN_TYPE
for many Access columns, while SQLDescribeCol reports the real type.
The
probe also stops sending a constant WHERE predicate, which the driver
neither needs (the probe never fetches a row) nor releases.
- desc_slct.c: execute the prepared statement before describing it. mdb-
tools
reports no result columns until SQLExecute, and FDO describes the
select
list first, so every query came back with zero columns.
Test harness and test cases
- OdbcConnectionUtil: name the SQL Server driver by
FDO_SQLSERVER_ODBC_DRIVER
(default ODBC Driver 17 for SQL Server) and the Access driver by
FDO_ACCESS_ODBC_DRIVER (default MDBTools off Windows), and use them in
the
generated connection strings. Add GetAccessConnectString(), which
builds
DRIVER={...};DBQ=<test data>/MSTest.mdb -- mdb-tools needs no DSN and
takes
Database= only in a DSN -- and resolve the test data directory from
/proc/self/exe, as the Windows version does with GetModuleFileName, so
the
path is sized for a Linux path rather than MAX_PATH.
Connection_WithDSN
falls back to the DRIVER= string off Windows, since Setup*DSN() is
Windows-only, and do_rdbi_init() initialises the context on every
platform
instead of returning success without doing so.
- OdbcBaseSetup: Sql2DbAutocommit() runs data-store DDL (CREATE/DROP
DATABASE)
with autocommit temporarily on, which SQL Server requires, and
restores it
before re-throwing.
- Registrations and implementations move out of #ifdef _WIN32 for the
SQL
Server fixtures in OdbcFdoDeleteTest, OdbcFdoInsertTest,
OdbcFdoUpdateTest,
OdbcFdoSelectTest, OdbcFdoAdvancedSelectTest, OdbcFdoSchemaTest,
OdbcFdoMultiThreadTest, OdbcFdoSqlCmdTest, OdbcDescribeSchemaTest,
OdbcFdoConnectTest and OdbcFdoConnectionInfoTest, and for the read-
only
Access fixtures of OdbcDescribeSchemaTest, OdbcFdoSelectTest,
OdbcFdoMultiThreadTest, OdbcFdoSchemaTest, OdbcFdoConnectTest and
OdbcFdoConnectionInfoTest. What stays Windows-only is what needs a
driver
that does not exist here: the Excel, dBase and Text fixtures, and the
Access
write fixtures, the two view selects, the date-filter test and the
computed-identifier arithmetic test, none of which mdb-tools can
serve.
- Fix the fixture constructors CppUnit instantiates: the private ones
become
public, since the suite registration constructs the fixture and GCC
rejects
a private constructor there. pOdbcConnectionUtil also loses its static
linkage in OdbcTestRegister.cpp, so the other translation units can
declare
it extern.
- SQLCMD_8BIT_TABLE_NAME is written as L"Fd\u00e9SqlTest": the source
held a
UTF-8 replacement character instead of the e-acute it meant, and SQL
Server
rejects the resulting name.
Memory leaks (LeakSanitizer, Debug)
- FdoConnectionInfoTest's mExpectedFileList is a vector of raw
FileNameDataSet* that only ClearFileNameList() released, and the
fixtures
that populate it never call it, so every AddFileNameToList() left the
FdoStringP-holding dataset behind (40 B per entry, direct). The
destructor
now releases whatever is still held.
- The col_.c probe change above removed 62 of the 86 leaked objects the
Access suite reported -- one glib chunk per WHERE expression,
allocated by
mdb-tools' own SQL engine and never freed -- leaving only the chunks
its
own filtered queries produce, which are the driver's defect rather
than
FDO's and are suppressed by the test harness rather than fixed here.
Verification
- OdbcSqlServerTests, ubuntu22 amd64, ODBC Driver 17 against the dbs
compose
mssql_cs instance: Debug OK (87), Release OK (87). 0 direct leak
records;
5,056 B in 4 indirect records, all from
FdoExpressionEngineUtilDataReader::GetAggregateClassDef in the shared
Expression Engine, reached through
FdoAdvancedSelectTest::TestMaxBoolProperty.
- OdbcAccessTests, ubuntu22 amd64, odbc-mdbtools 1.0.0: Debug OK (35),
Release OK (35). The suite reports no records; before the probe change
it
reported 40,810 B in 168 allocations, including a direct record of
26,144 B
in 86 objects, of which 62 objects were the probe's WHERE expressions.
- The other Odbc* suites are unchanged: MySQL and PostGIS run off their
own
init files and were not part of this work.
API/ABI: the cycle is in freeze mode. Nothing under a shipped Inc/
directory
changes -- the headers touched here are under Providers/**/Src and are not
installed -- so the provider-facing surface does not move and no baseline
needs
re-cutting.
Fixes #1018
}}}
--
Ticket URL: <https://trac.osgeo.org/fdo/ticket/1018#comment:1>
FDO <http://fdo.osgeo.org/>
Feature Data Objects
More information about the fdo-trac
mailing list