forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Implement SQLGetDiagRec #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d33f4e
Implement SQLGetDiagRec
rscales ff0f351
Add changes to address code review comments
rscales a04fc52
Change to have call to GetStringAttribute populate either messageText…
rscales ca1ecef
Update to use const on read only variables
rscales 66123b5
Remove const for size variable as can not be passed into GetStringAtt…
rscales 7b98157
Set flag to true when using wide char
rscales 8e6fb95
Pass sql state buffer length to GetStringAttribute
rscales 9ab72a4
Change to return sql success for unknown types
rscales 5c40cd8
Add test to retrieve diagnostic record after connection failure
rscales File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -400,8 +400,7 @@ TEST(SQLDriverConnect, TestSQLDriverConnectInvalidUid) { | |
|
|
||
| EXPECT_TRUE(ret == SQL_ERROR); | ||
|
|
||
| // TODO uncomment this check when SQLGetDiagRec is implemented | ||
| // VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, std::string("28000")); | ||
| VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, std::string("28000")); | ||
|
|
||
| // TODO: Check that outstr remains empty after SqlWcharToString | ||
| // is fixed to handle empty `outstr` | ||
|
|
@@ -621,8 +620,7 @@ TEST(SQLConnect, TestSQLConnectInvalidUid) { | |
| // so connection still fails despite passing valid uid in SQLConnect call | ||
| EXPECT_TRUE(ret == SQL_ERROR); | ||
|
|
||
| // TODO uncomment this check when SQLGetDiagRec is implemented | ||
| // VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, std::string("28000")); | ||
| VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, std::string("28000")); | ||
|
|
||
| // Remove DSN | ||
| EXPECT_TRUE(UnregisterDsn(dsn)); | ||
|
|
@@ -747,6 +745,82 @@ TEST(SQLDisconnect, TestSQLDisconnectWithoutConnection) { | |
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
| } | ||
|
|
||
| TEST(SQLGetDiagRec, TestSQLGetDiagRecForConnectFailure) { | ||
| // ODBC Environment | ||
| SQLHENV env; | ||
| SQLHDBC conn; | ||
|
|
||
| // Allocate an environment handle | ||
| SQLRETURN ret = SQLAllocEnv(&env); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
|
|
||
| ret = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
|
|
||
| // Allocate a connection using alloc handle | ||
| ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
|
|
||
| // Connect string | ||
| ASSERT_OK_AND_ASSIGN(std::string connect_str, | ||
| arrow::internal::GetEnvVar(TEST_CONNECT_STR)); | ||
| // Append invalid uid to connection string | ||
| connect_str += std::string("uid=non_existent_id;"); | ||
|
|
||
| ASSERT_OK_AND_ASSIGN(std::wstring wconnect_str, | ||
| arrow::util::UTF8ToWideString(connect_str)); | ||
| std::vector<SQLWCHAR> connect_str0(wconnect_str.begin(), wconnect_str.end()); | ||
|
|
||
| SQLWCHAR outstr[ODBC_BUFFER_SIZE]; | ||
| SQLSMALLINT outstrlen; | ||
|
|
||
| // Connecting to ODBC server. | ||
| ret = SQLDriverConnect(conn, NULL, &connect_str0[0], | ||
| static_cast<SQLSMALLINT>(connect_str0.size()), outstr, | ||
| ODBC_BUFFER_SIZE, &outstrlen, SQL_DRIVER_NOPROMPT); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_ERROR); | ||
|
|
||
| if (ret != SQL_SUCCESS) { | ||
| std::cerr << GetOdbcErrorMessage(SQL_HANDLE_DBC, conn) << std::endl; | ||
| } | ||
|
Comment on lines
+788
to
+790
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 added the code for debugging, it can be removed |
||
|
|
||
| SQLWCHAR sql_state[6]; | ||
| SQLINTEGER native_error; | ||
| SQLWCHAR message[ODBC_BUFFER_SIZE]; | ||
| SQLSMALLINT message_length; | ||
|
|
||
| ret = SQLGetDiagRec(SQL_HANDLE_DBC, conn, 1, sql_state, &native_error, message, | ||
| ODBC_BUFFER_SIZE, &message_length); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
|
|
||
| EXPECT_TRUE(message_length > 200); | ||
|
|
||
| EXPECT_TRUE(native_error == 200); | ||
|
|
||
| // 28000 | ||
| EXPECT_TRUE(sql_state[0] == '2'); | ||
| EXPECT_TRUE(sql_state[1] == '8'); | ||
| EXPECT_TRUE(sql_state[2] == '0'); | ||
| EXPECT_TRUE(sql_state[3] == '0'); | ||
| EXPECT_TRUE(sql_state[4] == '0'); | ||
|
|
||
| // Free connection handle | ||
| ret = SQLFreeHandle(SQL_HANDLE_DBC, conn); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
|
|
||
| // Free environment handle | ||
| ret = SQLFreeHandle(SQL_HANDLE_ENV, env); | ||
|
|
||
| EXPECT_TRUE(ret == SQL_SUCCESS); | ||
| } | ||
|
|
||
| } // namespace integration_tests | ||
| } // namespace odbc | ||
| } // namespace flight | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.