Skip to content

Commit c98f368

Browse files
committed
Address comment from Rob and add SQLDisconnect test case
1 parent 2779187 commit c98f368

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,8 @@ SQLRETURN SQLConnectW(SQLHDBC conn, SQLWCHAR* dsnName, SQLSMALLINT dsnNameLen,
395395

396396
using ODBC::SqlWcharToString;
397397

398-
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
399-
400398
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
399+
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
401400
std::string dsn = SqlWcharToString(dsnName, dsnNameLen);
402401

403402
Configuration config;

cpp/src/arrow/flight/sql/odbc/tests/connection_test.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,44 @@ TEST(SQLConnect, TestSQLConnectDSNPrecedence) {
709709

710710
EXPECT_TRUE(ret == SQL_SUCCESS);
711711
}
712+
713+
TEST(SQLDisconnect, TestSQLDisconnectWithoutConnection) {
714+
// ODBC Environment
715+
SQLHENV env;
716+
SQLHDBC conn;
717+
718+
// Allocate an environment handle
719+
SQLRETURN ret = SQLAllocEnv(&env);
720+
721+
EXPECT_TRUE(ret == SQL_SUCCESS);
722+
723+
ret = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
724+
725+
EXPECT_TRUE(ret == SQL_SUCCESS);
726+
727+
// Allocate a connection using alloc handle
728+
ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
729+
730+
EXPECT_TRUE(ret == SQL_SUCCESS);
731+
732+
// Attempt to disconnect without a connection, expect to fail
733+
ret = SQLDisconnect(conn);
734+
735+
EXPECT_TRUE(ret == SQL_ERROR);
736+
737+
// Expect ODBC driver manager to return error state
738+
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, std::string("08003"));
739+
740+
// Free connection handle
741+
ret = SQLFreeHandle(SQL_HANDLE_DBC, conn);
742+
743+
EXPECT_TRUE(ret == SQL_SUCCESS);
744+
745+
// Free environment handle
746+
ret = SQLFreeHandle(SQL_HANDLE_ENV, env);
747+
748+
EXPECT_TRUE(ret == SQL_SUCCESS);
749+
}
712750
} // namespace integration_tests
713751
} // namespace odbc
714752
} // namespace flight

0 commit comments

Comments
 (0)