-
Notifications
You must be signed in to change notification settings - Fork 0
SQLError implementation in macOS #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,8 @@ using TestTypesHandle = ::testing::Types<FlightSQLOdbcEnvConnHandleMockTestBase, | |
| FlightSQLOdbcEnvConnHandleRemoteTestBase>; | ||
| TYPED_TEST_SUITE(ErrorsHandleTest, TestTypesHandle); | ||
|
|
||
| using ODBC::SqlWcharToString; | ||
|
|
||
| TYPED_TEST(ErrorsHandleTest, TestSQLGetDiagFieldWForConnectFailure) { | ||
| // Invalid connect string | ||
| std::string connect_str = this->GetInvalidConnectionString(); | ||
|
|
@@ -119,7 +121,7 @@ TYPED_TEST(ErrorsHandleTest, TestSQLGetDiagFieldWForConnectFailure) { | |
| SQLGetDiagField(SQL_HANDLE_DBC, this->conn, RECORD_1, SQL_DIAG_SQLSTATE, sql_state, | ||
| sql_state_size * GetSqlWCharSize(), &sql_state_length)); | ||
|
|
||
| EXPECT_EQ(std::wstring(L"28000"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorState28000, SqlWcharToString(sql_state)); | ||
| } | ||
|
|
||
| TYPED_TEST(ErrorsHandleTest, DISABLED_TestSQLGetDiagFieldWForConnectFailureNTS) { | ||
|
|
@@ -218,7 +220,7 @@ TYPED_TEST(ErrorsTest, TestSQLGetDiagFieldWForDescriptorFailureFromDriverManager | |
| SQLGetDiagField(SQL_HANDLE_DESC, descriptor, RECORD_1, SQL_DIAG_SQLSTATE, sql_state, | ||
| sql_state_size * GetSqlWCharSize(), &sql_state_length)); | ||
|
|
||
| EXPECT_EQ(std::wstring(L"IM001"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateIM001, SqlWcharToString(sql_state)); | ||
|
|
||
| // Free descriptor handle | ||
| EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DESC, descriptor)); | ||
|
|
@@ -247,7 +249,7 @@ TYPED_TEST(ErrorsTest, TestSQLGetDiagRecForDescriptorFailureFromDriverManager) { | |
| EXPECT_EQ(0, native_error); | ||
|
|
||
| // API not implemented error from driver manager | ||
| EXPECT_EQ(std::wstring(L"IM001"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateIM001, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
|
|
||
|
|
@@ -284,7 +286,7 @@ TYPED_TEST(ErrorsHandleTest, TestSQLGetDiagRecForConnectFailure) { | |
|
|
||
| EXPECT_EQ(200, native_error); | ||
|
|
||
| EXPECT_EQ(std::wstring(L"28000"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorState28000, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
@@ -358,12 +360,12 @@ TYPED_TEST(ErrorsTest, TestSQLErrorEnvErrorFromDriverManager) { | |
| ASSERT_EQ(SQL_SUCCESS, SQLError(this->env, nullptr, nullptr, sql_state, &native_error, | ||
| message, SQL_MAX_MESSAGE_LENGTH, &message_length)); | ||
|
|
||
| EXPECT_GT(message_length, 50); | ||
| EXPECT_GT(message_length, 40); | ||
|
|
||
| EXPECT_EQ(0, native_error); | ||
|
|
||
| // Function sequence error state from driver manager | ||
| EXPECT_EQ(std::wstring(L"HY010"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateHY010, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
@@ -390,7 +392,7 @@ TYPED_TEST(ErrorsTest, TestSQLErrorConnError) { | |
| EXPECT_EQ(100, native_error); | ||
|
|
||
| // optional feature not supported error state | ||
| EXPECT_EQ(std::wstring(L"HYC00"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateHYC00, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
@@ -420,7 +422,7 @@ TYPED_TEST(ErrorsTest, TestSQLErrorStmtError) { | |
|
|
||
| EXPECT_EQ(100, native_error); | ||
|
|
||
| EXPECT_EQ(std::wstring(L"HY000"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateHY000, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
@@ -457,7 +459,7 @@ TYPED_TEST(ErrorsTest, TestSQLErrorStmtWarning) { | |
| EXPECT_EQ(1000100, native_error); | ||
|
|
||
| // Verify string truncation warning is reported | ||
| EXPECT_EQ(std::wstring(L"01004"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorState01004, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
@@ -479,22 +481,35 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorEnvErrorFromDriverManager) { | |
| ASSERT_EQ(SQL_SUCCESS, SQLError(this->env, nullptr, nullptr, sql_state, &native_error, | ||
| message, SQL_MAX_MESSAGE_LENGTH, &message_length)); | ||
|
|
||
| EXPECT_GT(message_length, 50); | ||
| EXPECT_GT(message_length, 40); | ||
|
|
||
| EXPECT_EQ(0, native_error); | ||
|
|
||
| // Function sequence error state from driver manager | ||
| EXPECT_EQ(std::wstring(L"S1010"), std::wstring(sql_state)); | ||
| #ifdef _WIN32 | ||
| // Windows Driver Manager returns S1010 | ||
| EXPECT_EQ(kErrorStateS1010, SqlWcharToString(sql_state)); | ||
| #else | ||
| // unix Driver Manager returns HY010 | ||
| EXPECT_EQ(kErrorStateHY010, SqlWcharToString(sql_state)); | ||
| #endif // _WIN32 | ||
|
|
||
|
Comment on lines
488
to
496
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am surprised that Windows Driver Manager (DM) returns |
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
||
| // TODO: verify that `SQLGetConnectOption` is not required by Excel. | ||
| #ifndef __APPLE__ | ||
| TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorConnError) { | ||
|
Comment on lines
+500
to
502
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still need to verify if For this PR, we are checking in the SQLErrors changes. |
||
| // Test ODBC 2.0 API SQLError with ODBC ver 2. | ||
| // Known Windows Driver Manager (DM) behavior: | ||
| // When application passes buffer length greater than SQL_MAX_MESSAGE_LENGTH (512), | ||
| // DM passes 512 as buffer length to SQLError. | ||
|
|
||
| // Known macOS Driver Manager (DM) behavior: | ||
| // Attempts to call SQLGetConnectOption without redirecting the API call to | ||
| // SQLGetConnectAttr. SQLGetConnectOption is not implemented as it is not required by | ||
| // macOS Excel. | ||
|
|
||
| // Attempt to set unsupported attribute | ||
| ASSERT_EQ(SQL_ERROR, | ||
| SQLGetConnectAttr(this->conn, SQL_ATTR_TXN_ISOLATION, 0, 0, nullptr)); | ||
|
|
@@ -511,10 +526,11 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorConnError) { | |
| EXPECT_EQ(100, native_error); | ||
|
|
||
| // optional feature not supported error state. Driver Manager maps state to S1C00 | ||
| EXPECT_EQ(std::wstring(L"S1C00"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateS1C00, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
| #endif // __APPLE__ | ||
|
|
||
| TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorStmtError) { | ||
| // Test ODBC 2.0 API SQLError with ODBC ver 2. | ||
|
|
@@ -540,7 +556,7 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorStmtError) { | |
| EXPECT_EQ(100, native_error); | ||
|
|
||
| // Driver Manager maps error state to S1000 | ||
| EXPECT_EQ(std::wstring(L"S1000"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorStateS1000, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
@@ -577,7 +593,7 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorStmtWarning) { | |
| EXPECT_EQ(1000100, native_error); | ||
|
|
||
| // Verify string truncation warning is reported | ||
| EXPECT_EQ(std::wstring(L"01004"), std::wstring(sql_state)); | ||
| EXPECT_EQ(kErrorState01004, SqlWcharToString(sql_state)); | ||
|
|
||
| EXPECT_FALSE(std::wstring(message).empty()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need a windows version of SQLError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rely on the driver manager for Windows to provide an implementation of SQLError, it is less error prone.
Driver Managers are supposed to handle ODBC 2.0 APIs like SQLError by mapping to ODBC 3.0 APIs, but macOS Driver Manager is missing on the functionality so we have to implement SQLError for macOS.