This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new df4ff903e5 GH-47789: [C++][FlightRPC] SQLGetFunctions Tests (#48031)
df4ff903e5 is described below
commit df4ff903e5009edad70081b5850bc350f0837df7
Author: Alina (Xi) Li <[email protected]>
AuthorDate: Mon Dec 29 17:12:18 2025 -0800
GH-47789: [C++][FlightRPC] SQLGetFunctions Tests (#48031)
### Rationale for this change
Add SQLGetFunctions Tests to make sure the ODBC driver manager's
implementation SQLGetFunctions is same as expected. The ODBC driver manager
interacts with the Flight SQL ODBC driver and determines the return values of
SQLGetFunctions based on that.
### What changes are included in this PR?
- SQLGetFunctions tests
### Are these changes tested?
- Tested in CI
### Are there any user-facing changes?
No
* GitHub Issue: #47789
Lead-authored-by: Alina (Xi) Li <[email protected]>
Co-authored-by: justing-bq <[email protected]>
Signed-off-by: David Li <[email protected]>
---
cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt | 1 +
.../flight/sql/odbc/tests/get_functions_test.cc | 220 +++++++++++++++++++++
2 files changed, 221 insertions(+)
diff --git a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
index 39284c750b..f4e90420a7 100644
--- a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
+++ b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
@@ -39,6 +39,7 @@ add_arrow_test(flight_sql_odbc_test
connection_info_test.cc
connection_test.cc
errors_test.cc
+ get_functions_test.cc
statement_attr_test.cc
statement_test.cc
tables_test.cc
diff --git a/cpp/src/arrow/flight/sql/odbc/tests/get_functions_test.cc
b/cpp/src/arrow/flight/sql/odbc/tests/get_functions_test.cc
new file mode 100644
index 0000000000..35d7f2f935
--- /dev/null
+++ b/cpp/src/arrow/flight/sql/odbc/tests/get_functions_test.cc
@@ -0,0 +1,220 @@
+// 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 GetFunctionsTest : public T {};
+
+using TestTypes =
+ ::testing::Types<FlightSQLODBCMockTestBase, FlightSQLODBCRemoteTestBase>;
+TYPED_TEST_SUITE(GetFunctionsTest, TestTypes);
+
+template <typename T>
+class GetFunctionsOdbcV2Test : public T {};
+
+using TestTypesOdbcV2 =
+ ::testing::Types<FlightSQLOdbcV2MockTestBase,
FlightSQLOdbcV2RemoteTestBase>;
+TYPED_TEST_SUITE(GetFunctionsOdbcV2Test, TestTypesOdbcV2);
+
+TYPED_TEST(GetFunctionsTest, TestSQLGetFunctionsAllFunctions) {
+ // Verify driver manager return values for SQLGetFunctions
+
+ SQLUSMALLINT api_exists[SQL_API_ODBC3_ALL_FUNCTIONS_SIZE];
+ const std::vector<int> supported_functions = {
+ SQL_API_SQLALLOCHANDLE, SQL_API_SQLBINDCOL, SQL_API_SQLGETDIAGFIELD,
+ SQL_API_SQLCANCEL, SQL_API_SQLCLOSECURSOR, SQL_API_SQLGETDIAGREC,
+ SQL_API_SQLCOLATTRIBUTE, SQL_API_SQLGETENVATTR, SQL_API_SQLCONNECT,
+ SQL_API_SQLGETINFO, SQL_API_SQLGETSTMTATTR, SQL_API_SQLDESCRIBECOL,
+ SQL_API_SQLGETTYPEINFO, SQL_API_SQLDISCONNECT, SQL_API_SQLNUMRESULTCOLS,
+ SQL_API_SQLPREPARE, SQL_API_SQLEXECDIRECT, SQL_API_SQLEXECUTE,
SQL_API_SQLROWCOUNT,
+ SQL_API_SQLFETCH, SQL_API_SQLSETCONNECTATTR, SQL_API_SQLFETCHSCROLL,
+ SQL_API_SQLFREEHANDLE, SQL_API_SQLFREESTMT, SQL_API_SQLGETCONNECTATTR,
+ SQL_API_SQLSETENVATTR, SQL_API_SQLSETSTMTATTR, SQL_API_SQLGETDATA,
+ SQL_API_SQLCOLUMNS, SQL_API_SQLTABLES, SQL_API_SQLNATIVESQL,
+ SQL_API_SQLDRIVERCONNECT, SQL_API_SQLMORERESULTS, SQL_API_SQLPRIMARYKEYS,
+ SQL_API_SQLFOREIGNKEYS,
+
+ // ODBC 2.0 APIs
+ SQL_API_SQLSETSTMTOPTION, SQL_API_SQLGETSTMTOPTION,
SQL_API_SQLSETCONNECTOPTION,
+ SQL_API_SQLGETCONNECTOPTION, SQL_API_SQLALLOCCONNECT,
SQL_API_SQLALLOCENV,
+ SQL_API_SQLALLOCSTMT, SQL_API_SQLFREEENV, SQL_API_SQLFREECONNECT,
+
+ // Driver Manager APIs
+ SQL_API_SQLGETFUNCTIONS, SQL_API_SQLDRIVERS, SQL_API_SQLDATASOURCES};
+ const std::vector<int> unsupported_functions = {
+ SQL_API_SQLPUTDATA, SQL_API_SQLGETDESCFIELD,
SQL_API_SQLGETDESCREC,
+ SQL_API_SQLCOPYDESC, SQL_API_SQLPARAMDATA,
SQL_API_SQLENDTRAN,
+ SQL_API_SQLSETCURSORNAME, SQL_API_SQLSETDESCFIELD,
SQL_API_SQLSETDESCREC,
+ SQL_API_SQLGETCURSORNAME, SQL_API_SQLSTATISTICS,
SQL_API_SQLSPECIALCOLUMNS,
+ SQL_API_SQLBINDPARAMETER, SQL_API_SQLBROWSECONNECT,
SQL_API_SQLNUMPARAMS,
+ SQL_API_SQLBULKOPERATIONS, SQL_API_SQLCOLUMNPRIVILEGES,
SQL_API_SQLPROCEDURECOLUMNS,
+ SQL_API_SQLDESCRIBEPARAM, SQL_API_SQLPROCEDURES,
SQL_API_SQLSETPOS,
+ SQL_API_SQLTABLEPRIVILEGES};
+
+ ASSERT_EQ(SQL_SUCCESS,
+ SQLGetFunctions(this->conn, SQL_API_ODBC3_ALL_FUNCTIONS,
api_exists));
+
+ for (int api : supported_functions) {
+ EXPECT_EQ(SQL_TRUE, SQL_FUNC_EXISTS(api_exists, api));
+ }
+
+ for (int api : unsupported_functions) {
+ EXPECT_EQ(SQL_FALSE, SQL_FUNC_EXISTS(api_exists, api));
+ }
+}
+
+TYPED_TEST(GetFunctionsOdbcV2Test, TestSQLGetFunctionsAllFunctionsODBCVer2) {
+ // Verify driver manager return values for SQLGetFunctions
+
+ // ODBC 2.0 SQLGetFunctions returns 100 elements according to spec
+ SQLUSMALLINT api_exists[100];
+ const std::vector<int> supported_functions = {
+ SQL_API_SQLCONNECT, SQL_API_SQLGETINFO, SQL_API_SQLDESCRIBECOL,
+ SQL_API_SQLGETTYPEINFO, SQL_API_SQLDISCONNECT, SQL_API_SQLNUMRESULTCOLS,
+ SQL_API_SQLPREPARE, SQL_API_SQLEXECDIRECT, SQL_API_SQLEXECUTE,
SQL_API_SQLROWCOUNT,
+ SQL_API_SQLFETCH, SQL_API_SQLFREESTMT, SQL_API_SQLGETDATA,
SQL_API_SQLCOLUMNS,
+ SQL_API_SQLTABLES, SQL_API_SQLNATIVESQL, SQL_API_SQLDRIVERCONNECT,
+ SQL_API_SQLMORERESULTS, SQL_API_SQLSETSTMTOPTION,
SQL_API_SQLGETSTMTOPTION,
+ SQL_API_SQLSETCONNECTOPTION, SQL_API_SQLGETCONNECTOPTION,
SQL_API_SQLALLOCCONNECT,
+ SQL_API_SQLALLOCENV, SQL_API_SQLALLOCSTMT, SQL_API_SQLFREEENV,
+ SQL_API_SQLFREECONNECT, SQL_API_SQLPRIMARYKEYS, SQL_API_SQLFOREIGNKEYS,
+
+ // Driver Manager APIs
+ SQL_API_SQLGETFUNCTIONS, SQL_API_SQLDRIVERS, SQL_API_SQLDATASOURCES};
+ const std::vector<int> unsupported_functions = {
+ SQL_API_SQLPUTDATA, SQL_API_SQLPARAMDATA,
SQL_API_SQLSETCURSORNAME,
+ SQL_API_SQLGETCURSORNAME, SQL_API_SQLSTATISTICS,
SQL_API_SQLSPECIALCOLUMNS,
+ SQL_API_SQLBINDPARAMETER, SQL_API_SQLBROWSECONNECT,
SQL_API_SQLNUMPARAMS,
+ SQL_API_SQLBULKOPERATIONS, SQL_API_SQLCOLUMNPRIVILEGES,
SQL_API_SQLPROCEDURECOLUMNS,
+ SQL_API_SQLDESCRIBEPARAM, SQL_API_SQLPROCEDURES,
SQL_API_SQLSETPOS,
+ SQL_API_SQLTABLEPRIVILEGES};
+ ASSERT_EQ(SQL_SUCCESS, SQLGetFunctions(this->conn, SQL_API_ALL_FUNCTIONS,
api_exists));
+
+ for (int api : supported_functions) {
+ EXPECT_EQ(SQL_TRUE, api_exists[api]);
+ }
+
+ for (int api : unsupported_functions) {
+ EXPECT_EQ(SQL_FALSE, api_exists[api]);
+ }
+}
+
+TYPED_TEST(GetFunctionsTest, TestSQLGetFunctionsSupportedSingleAPI) {
+ const std::vector<SQLUSMALLINT> supported_functions = {
+ SQL_API_SQLALLOCHANDLE, SQL_API_SQLBINDCOL, SQL_API_SQLGETDIAGFIELD,
+ SQL_API_SQLCANCEL, SQL_API_SQLCLOSECURSOR, SQL_API_SQLGETDIAGREC,
+ SQL_API_SQLCOLATTRIBUTE, SQL_API_SQLGETENVATTR, SQL_API_SQLCONNECT,
+ SQL_API_SQLGETINFO, SQL_API_SQLGETSTMTATTR, SQL_API_SQLDESCRIBECOL,
+ SQL_API_SQLGETTYPEINFO, SQL_API_SQLDISCONNECT, SQL_API_SQLNUMRESULTCOLS,
+ SQL_API_SQLPREPARE, SQL_API_SQLEXECDIRECT, SQL_API_SQLEXECUTE,
SQL_API_SQLROWCOUNT,
+ SQL_API_SQLFETCH, SQL_API_SQLSETCONNECTATTR, SQL_API_SQLFETCHSCROLL,
+ SQL_API_SQLFREEHANDLE, SQL_API_SQLFREESTMT, SQL_API_SQLGETCONNECTATTR,
+ SQL_API_SQLSETENVATTR, SQL_API_SQLSETSTMTATTR, SQL_API_SQLGETDATA,
+ SQL_API_SQLCOLUMNS, SQL_API_SQLTABLES, SQL_API_SQLNATIVESQL,
+ SQL_API_SQLDRIVERCONNECT, SQL_API_SQLMORERESULTS, SQL_API_SQLPRIMARYKEYS,
+ SQL_API_SQLFOREIGNKEYS,
+
+ // ODBC 2.0 APIs
+ SQL_API_SQLSETSTMTOPTION, SQL_API_SQLGETSTMTOPTION,
SQL_API_SQLSETCONNECTOPTION,
+ SQL_API_SQLGETCONNECTOPTION, SQL_API_SQLALLOCCONNECT,
SQL_API_SQLALLOCENV,
+ SQL_API_SQLALLOCSTMT, SQL_API_SQLFREEENV, SQL_API_SQLFREECONNECT,
+
+ // Driver Manager APIs
+ SQL_API_SQLGETFUNCTIONS, SQL_API_SQLDRIVERS, SQL_API_SQLDATASOURCES};
+ SQLUSMALLINT api_exists;
+ for (SQLUSMALLINT api : supported_functions) {
+ ASSERT_EQ(SQL_SUCCESS, SQLGetFunctions(this->conn, api, &api_exists));
+
+ EXPECT_EQ(SQL_TRUE, api_exists);
+
+ api_exists = -1;
+ }
+}
+
+TYPED_TEST(GetFunctionsTest, TestSQLGetFunctionsUnsupportedSingleAPI) {
+ const std::vector<SQLUSMALLINT> unsupported_functions = {
+ SQL_API_SQLPUTDATA, SQL_API_SQLGETDESCFIELD,
SQL_API_SQLGETDESCREC,
+ SQL_API_SQLCOPYDESC, SQL_API_SQLPARAMDATA,
SQL_API_SQLENDTRAN,
+ SQL_API_SQLSETCURSORNAME, SQL_API_SQLSETDESCFIELD,
SQL_API_SQLSETDESCREC,
+ SQL_API_SQLGETCURSORNAME, SQL_API_SQLSTATISTICS,
SQL_API_SQLSPECIALCOLUMNS,
+ SQL_API_SQLBINDPARAMETER, SQL_API_SQLBROWSECONNECT,
SQL_API_SQLNUMPARAMS,
+ SQL_API_SQLBULKOPERATIONS, SQL_API_SQLCOLUMNPRIVILEGES,
SQL_API_SQLPROCEDURECOLUMNS,
+ SQL_API_SQLDESCRIBEPARAM, SQL_API_SQLPROCEDURES,
SQL_API_SQLSETPOS,
+ SQL_API_SQLTABLEPRIVILEGES};
+ SQLUSMALLINT api_exists;
+ for (SQLUSMALLINT api : unsupported_functions) {
+ ASSERT_EQ(SQL_SUCCESS, SQLGetFunctions(this->conn, api, &api_exists));
+
+ EXPECT_EQ(SQL_FALSE, api_exists);
+
+ api_exists = -1;
+ }
+}
+
+TYPED_TEST(GetFunctionsOdbcV2Test,
TestSQLGetFunctionsSupportedSingleAPIODBCVer2) {
+ const std::vector<SQLUSMALLINT> supported_functions = {
+ SQL_API_SQLCONNECT, SQL_API_SQLGETINFO, SQL_API_SQLDESCRIBECOL,
+ SQL_API_SQLGETTYPEINFO, SQL_API_SQLDISCONNECT, SQL_API_SQLNUMRESULTCOLS,
+ SQL_API_SQLPREPARE, SQL_API_SQLEXECDIRECT, SQL_API_SQLEXECUTE,
SQL_API_SQLROWCOUNT,
+ SQL_API_SQLFETCH, SQL_API_SQLFREESTMT, SQL_API_SQLGETDATA,
SQL_API_SQLCOLUMNS,
+ SQL_API_SQLTABLES, SQL_API_SQLNATIVESQL, SQL_API_SQLDRIVERCONNECT,
+ SQL_API_SQLMORERESULTS, SQL_API_SQLSETSTMTOPTION,
SQL_API_SQLGETSTMTOPTION,
+ SQL_API_SQLSETCONNECTOPTION, SQL_API_SQLGETCONNECTOPTION,
SQL_API_SQLALLOCCONNECT,
+ SQL_API_SQLALLOCENV, SQL_API_SQLALLOCSTMT, SQL_API_SQLFREEENV,
+ SQL_API_SQLFREECONNECT, SQL_API_SQLPRIMARYKEYS, SQL_API_SQLFOREIGNKEYS,
+
+ // Driver Manager APIs
+ SQL_API_SQLGETFUNCTIONS, SQL_API_SQLDRIVERS, SQL_API_SQLDATASOURCES};
+ SQLUSMALLINT api_exists;
+ for (SQLUSMALLINT api : supported_functions) {
+ ASSERT_EQ(SQL_SUCCESS, SQLGetFunctions(this->conn, api, &api_exists));
+
+ EXPECT_EQ(SQL_TRUE, api_exists);
+
+ api_exists = -1;
+ }
+}
+
+TYPED_TEST(GetFunctionsOdbcV2Test,
TestSQLGetFunctionsUnsupportedSingleAPIODBCVer2) {
+ const std::vector<SQLUSMALLINT> unsupported_functions = {
+ SQL_API_SQLPUTDATA, SQL_API_SQLPARAMDATA,
SQL_API_SQLSETCURSORNAME,
+ SQL_API_SQLGETCURSORNAME, SQL_API_SQLSTATISTICS,
SQL_API_SQLSPECIALCOLUMNS,
+ SQL_API_SQLBINDPARAMETER, SQL_API_SQLBROWSECONNECT,
SQL_API_SQLNUMPARAMS,
+ SQL_API_SQLBULKOPERATIONS, SQL_API_SQLCOLUMNPRIVILEGES,
SQL_API_SQLPROCEDURECOLUMNS,
+ SQL_API_SQLDESCRIBEPARAM, SQL_API_SQLPROCEDURES,
SQL_API_SQLSETPOS,
+ SQL_API_SQLTABLEPRIVILEGES};
+ SQLUSMALLINT api_exists;
+ for (SQLUSMALLINT api : unsupported_functions) {
+ ASSERT_EQ(SQL_SUCCESS, SQLGetFunctions(this->conn, api, &api_exists));
+
+ EXPECT_EQ(SQL_FALSE, api_exists);
+
+ api_exists = -1;
+ }
+}
+
+} // namespace arrow::flight::sql::odbc