Skip to content

Commit

Permalink
Fix parsing conn string with a trailing comma
Browse files Browse the repository at this point in the history
When connection string includes a trailing comma, existing impl in
Connect::ParseInputStr was doing an early exit without setting DSN
value to dbc->dsn. Because of this DSN was not used and default
:memory: instance was created.

The problem is not OS specific, but was happening on Windows all the
time because Windows ODBC Driver Manager is appending comma to the
passed connection string when calling SQLDriverConnect.

test_connect_odbc was extended to cover the trailing comma and also
parameters overriding in connection string.

Fixes: #29, #48
  • Loading branch information
staticlibs committed Feb 1, 2025
1 parent e3f4ba7 commit 03d2b7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/connect/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ SQLRETURN Connect::ParseInputStr() {
input_str.erase(0, row_pos + 1);
}

if (input_str.empty()) {
return SQL_SUCCESS;
}

SQLRETURN ret = FindKeyValPair(input_str);
if (ret != SQL_SUCCESS) {
return ret;
if (!input_str.empty()) {
SQLRETURN ret = FindKeyValPair(input_str);
if (ret != SQL_SUCCESS) {
return ret;
}
}

// Extract the DSN from the config map as it is needed to read from the .odbc.ini file
Expand Down
20 changes: 20 additions & 0 deletions test/tests/connect_with_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ TEST_CASE("Test SQLConnect with Ini File", "[odbc]") {
DISCONNECT_FROM_DATABASE(env, dbc);
#endif
}

// Connect to the database using the ini file when connection string
// has extra options and a trailing comma
TEST_CASE("Test SQLConnect with Ini File with extra options", "[odbc]") {
#if defined ODBC_LINK_ODBCINST || defined WIN32
// Connect to the database using the ini file
SQLHANDLE env;
SQLHANDLE dbc;
DRIVER_CONNECT_TO_DATABASE(env, dbc, "DSN=DuckDB;allow_unsigned_extensions=false;");

// Check that the database is set
CheckDatabase(dbc);

// Check that allow_unsigned_extensions is set from connection string
CheckConfig(dbc, "allow_unsigned_extensions", "false");

// Disconnect from the database
DISCONNECT_FROM_DATABASE(env, dbc);
#endif
}

0 comments on commit 03d2b7e

Please sign in to comment.