Add SQLError Tests - #82
Conversation
* 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) { |
There was a problem hiding this comment.
Moved these tests to errors_test.cc
|
|
||
| EXPECT_EQ(native_error, 100); | ||
|
|
||
| EXPECT_EQ(std::wstring(sql_state), std::wstring(L"HY000")); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Please review:
https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/sqlstate-mappings?view=sql-server-ver15
Perhaps this can come in a different PR?
There was a problem hiding this comment.
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
| this->connect(SQL_OV_ODBC2); | ||
|
|
||
| // Attempt to set environment attribute after connection handle allocation | ||
| SQLRETURN ret = SQLSetEnvAttr(this->env, SQL_ATTR_ODBC_VERSION, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Add tests to SQLError as it is expected for driver manager to map SQLError calls to SQLGetDiagRec.
connection_test.cctoerrors_test.cc