Skip to content

Add SQLError Tests - #82

Merged
alinaliBQ merged 7 commits into
apache-odbcfrom
sql-error-tests
Aug 8, 2025
Merged

Add SQLError Tests#82
alinaliBQ merged 7 commits into
apache-odbcfrom
sql-error-tests

Conversation

@alinaliBQ

@alinaliBQ alinaliBQ commented Aug 6, 2025

Copy link
Copy Markdown

Add tests to SQLError as it is expected for driver manager to map SQLError calls to SQLGetDiagRec.

  • Move diagnostic tests from connection_test.cc to errors_test.cc
  • Add initial values for SQLHandles in test suite to prevent segfault errors

* add test to free null handles. Without handle value initialization, segfault error was seen
Move `SQLGetDiagField` and `SQLGetDiagRec` tests to `errors_test.cc`
* Update SQLGetDiagRec and SQLGetDiagField tests also
EXPECT_EQ(ret, SQL_SUCCESS);
}

TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetDiagFieldWForConnectFailure) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved these tests to errors_test.cc

@alinaliBQ
alinaliBQ marked this pull request as ready for review August 6, 2025 22:13

EXPECT_EQ(native_error, 100);

EXPECT_EQ(std::wstring(sql_state), std::wstring(L"HY000"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually need to add 2.x tests for this. In ODBC 2.x error states are supposed to start with S1xxx instead of HY.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this James. I have added tests with ODBC ver 2. I also changed the connection error test to return a "optional feature not implemented" code and can verify the Windows driver manager is automatically mapping HYXXX to S1XXX codes.

* Add ODBC Ver 2 tests
@alinaliBQ
alinaliBQ requested a review from jduo August 7, 2025 23:05
this->connect(SQL_OV_ODBC2);

// Attempt to set environment attribute after connection handle allocation
SQLRETURN ret = SQLSetEnvAttr(this->env, SQL_ATTR_ODBC_VERSION,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test will reach the driver as the DM will see this as a function sequence error (trying to change ODBC version after already being connected).

@alinaliBQ alinaliBQ Aug 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's true. I had left a comment below indicating that this is from the driver manager (so DM functionality is tested), let me change the test to make the call reach the driver

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had renamed the test to say the error is from driver manager to make it clearer.
I have looked into this and unfortunately the driver manager intercepts all SQLGetEnvAttr and SQLSetEnvAttr calls. Even if the driver code is reached and the driver returns an error, the driver manager will report it on the driver's behalf.

For example, I have tried to set unsupported ODBC version 3.80 before driver connection, and driver manager puts the error inside the connection handle instead of the environment handle:

01000: [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr).

* update test name to indicate if error handling is from driver manager.
* add tests for warnings.

* fix lint errors.
* remove SQL_ATTR_APP_ROW_DESC that is not applicable to Env Attr.
@alinaliBQ
alinaliBQ merged commit 524d981 into apache-odbc Aug 8, 2025
24 checks passed
@alinaliBQ
alinaliBQ deleted the sql-error-tests branch August 8, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants