-
Notifications
You must be signed in to change notification settings - Fork 3.9k
GH-47707: [C++][FlightRPC] Add tests for descriptor handle allocation #48053
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
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. Similar here, would need to rebase after #47762 merged to get rid of duplicate changes, as this PR depends on it |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| #include "arrow/flight/sql/odbc/tests/odbc_test_suite.h" | ||
|
|
||
| #include "arrow/flight/sql/odbc/odbc_impl/platform.h" | ||
|
|
||
| #include <sql.h> | ||
| #include <sqltypes.h> | ||
| #include <sqlucode.h> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace arrow::flight::sql::odbc { | ||
|
|
||
| template <typename T> | ||
| class ConnectionInfoTest : public T {}; | ||
|
|
||
| class ConnectionInfoMockTest : public FlightSQLODBCMockTestBase {}; | ||
| using TestTypes = ::testing::Types<ConnectionInfoMockTest, FlightSQLODBCRemoteTestBase>; | ||
| TYPED_TEST_SUITE(ConnectionInfoTest, TestTypes); | ||
| // These information types are implemented by the Driver Manager alone. | ||
| TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDriverHdesc) { | ||
| SQLHDESC descriptor; | ||
|
|
||
| // Allocate a descriptor using alloc handle | ||
| ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_DESC, this->conn, &descriptor)); | ||
|
|
||
| // Value returned from driver manager is the desc address | ||
| SQLHDESC local_desc = descriptor; | ||
| EXPECT_EQ(SQL_SUCCESS, SQLGetInfo(this->conn, SQL_HANDLE_DESC, &local_desc, 0, 0)); | ||
| EXPECT_GT(local_desc, static_cast<SQLHSTMT>(0)); | ||
|
|
||
| // Free descriptor handle | ||
| ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DESC, descriptor)); | ||
| } | ||
|
|
||
| } // namespace arrow::flight::sql::odbc |
|
Contributor
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. This PR needs to be rebased onto |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| #include "arrow/flight/sql/odbc/tests/odbc_test_suite.h" | ||
|
|
||
| #include "arrow/flight/sql/odbc/odbc_impl/platform.h" | ||
|
|
||
| #include <sql.h> | ||
| #include <sqltypes.h> | ||
| #include <sqlucode.h> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace arrow::flight::sql::odbc { | ||
|
|
||
| template <typename T> | ||
| class ErrorsTest : public T {}; | ||
|
|
||
| using TestTypes = | ||
| ::testing::Types<FlightSQLODBCMockTestBase, FlightSQLODBCRemoteTestBase>; | ||
| TYPED_TEST_SUITE(ErrorsTest, TestTypes); | ||
|
|
||
| template <typename T> | ||
| class ErrorsOdbcV2Test : public T {}; | ||
|
|
||
| using TestTypesOdbcV2 = | ||
| ::testing::Types<FlightSQLOdbcV2MockTestBase, FlightSQLOdbcV2RemoteTestBase>; | ||
| TYPED_TEST_SUITE(ErrorsOdbcV2Test, TestTypesOdbcV2); | ||
|
|
||
| template <typename T> | ||
| class ErrorsHandleTest : public T {}; | ||
|
|
||
| using TestTypesHandle = | ||
| ::testing::Types<FlightSQLOdbcHandleMockTestBase, FlightSQLOdbcHandleRemoteTestBase>; | ||
| TYPED_TEST_SUITE(ErrorsHandleTest, TestTypesHandle); | ||
|
|
||
| TYPED_TEST(ErrorsTest, TestSQLGetDiagFieldWForDescriptorFailureFromDriverManager) { | ||
| SQLHDESC descriptor; | ||
|
|
||
| // Allocate a descriptor using alloc handle | ||
| ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_DESC, this->conn, &descriptor)); | ||
|
|
||
| EXPECT_EQ(SQL_ERROR, | ||
| SQLGetDescField(descriptor, 1, SQL_DESC_DATETIME_INTERVAL_CODE, 0, 0, 0)); | ||
|
|
||
| // Retrieve all supported header level and record level data | ||
| SQLSMALLINT HEADER_LEVEL = 0; | ||
| SQLSMALLINT RECORD_1 = 1; | ||
|
|
||
| // SQL_DIAG_NUMBER | ||
| SQLINTEGER diag_number; | ||
| SQLSMALLINT diag_number_length; | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, | ||
| SQLGetDiagField(SQL_HANDLE_DESC, descriptor, HEADER_LEVEL, SQL_DIAG_NUMBER, | ||
| &diag_number, sizeof(SQLINTEGER), &diag_number_length)); | ||
|
|
||
| EXPECT_EQ(1, diag_number); | ||
|
|
||
| // SQL_DIAG_SERVER_NAME | ||
| SQLWCHAR server_name[kOdbcBufferSize]; | ||
| SQLSMALLINT server_name_length; | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, | ||
| SQLGetDiagField(SQL_HANDLE_DESC, descriptor, RECORD_1, SQL_DIAG_SERVER_NAME, | ||
| server_name, kOdbcBufferSize, &server_name_length)); | ||
|
|
||
| // SQL_DIAG_MESSAGE_TEXT | ||
| SQLWCHAR message_text[kOdbcBufferSize]; | ||
| SQLSMALLINT message_text_length; | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, | ||
| SQLGetDiagField(SQL_HANDLE_DESC, descriptor, RECORD_1, SQL_DIAG_MESSAGE_TEXT, | ||
| message_text, kOdbcBufferSize, &message_text_length)); | ||
|
|
||
| EXPECT_GT(message_text_length, 100); | ||
|
|
||
| // SQL_DIAG_NATIVE | ||
| SQLINTEGER diag_native; | ||
| SQLSMALLINT diag_native_length; | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, | ||
| SQLGetDiagField(SQL_HANDLE_DESC, descriptor, RECORD_1, SQL_DIAG_NATIVE, | ||
| &diag_native, sizeof(diag_native), &diag_native_length)); | ||
|
|
||
| EXPECT_EQ(0, diag_native); | ||
|
|
||
| // SQL_DIAG_SQLSTATE | ||
| const SQLSMALLINT sql_state_size = 6; | ||
| SQLWCHAR sql_state[sql_state_size]; | ||
| SQLSMALLINT sql_state_length; | ||
| EXPECT_EQ( | ||
| SQL_SUCCESS, | ||
| 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)); | ||
|
|
||
| // Free descriptor handle | ||
| EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DESC, descriptor)); | ||
| } | ||
|
|
||
| TYPED_TEST(ErrorsTest, TestSQLGetDiagRecForDescriptorFailureFromDriverManager) { | ||
| SQLHDESC descriptor; | ||
|
|
||
| // Allocate a descriptor using alloc handle | ||
| ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_DESC, this->conn, &descriptor)); | ||
|
|
||
| EXPECT_EQ(SQL_ERROR, | ||
| SQLGetDescField(descriptor, 1, SQL_DESC_DATETIME_INTERVAL_CODE, 0, 0, 0)); | ||
|
|
||
| SQLWCHAR sql_state[6]; | ||
| SQLINTEGER native_error; | ||
| SQLWCHAR message[kOdbcBufferSize]; | ||
| SQLSMALLINT message_length; | ||
|
|
||
| ASSERT_EQ(SQL_SUCCESS, | ||
| SQLGetDiagRec(SQL_HANDLE_DESC, descriptor, 1, sql_state, &native_error, | ||
| message, kOdbcBufferSize, &message_length)); | ||
|
|
||
| EXPECT_GT(message_length, 60); | ||
|
|
||
| EXPECT_EQ(0, native_error); | ||
|
|
||
| // API not implemented error from driver manager | ||
| EXPECT_EQ(std::wstring(L"IM001"), std::wstring(sql_state)); | ||
|
|
||
| EXPECT_TRUE(!std::wstring(message).empty()); | ||
|
|
||
| // Free descriptor handle | ||
| EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DESC, descriptor)); | ||
| } | ||
|
|
||
| } // namespace arrow::flight::sql::odbc |
Uh oh!
There was an error while loading. Please reload this page.
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.
TODO - add
/briefdoxygen doc forRevertAppDescriptorinodbc_statement.h