Skip to content

Commit 16ceade

Browse files
authored
apacheGH-47516: [C++][FlightRPC] Initial ODBC driver framework (apache#47517)
### Rationale for this change Add initial framework for building an ODBC driver dll ### What changes are included in this PR? - initial Flight SQL ODBC framework ### Are these changes tested? - Yes, on local Windows environment ### Are there any user-facing changes? - None * PR is extracted from PR apache#46099 * GitHub Issue: apache#47516 Authored-by: Alina (Xi) Li <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent eb9d519 commit 16ceade

File tree

9 files changed

+344
-7
lines changed

9 files changed

+344
-7
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# This config sets the following variables in your project::
19+
#
20+
# ArrowFlightSqlOdbc_FOUND - true if Arrow Flight SQL ODBC found on the system
21+
#
22+
# This config sets the following targets in your project::
23+
#
24+
# ArrowFlightSqlOdbc::arrow_flight_sql_odbc_shared - for linked as shared library if shared library is built
25+
# ArrowFlightSqlOdbc::arrow_flight_sql_odbc_static - for linked as static library if static library is built
26+
27+
@PACKAGE_INIT@
28+
29+
include(CMakeFindDependencyMacro)
30+
find_dependency(ArrowFlightSql)
31+
32+
include("${CMAKE_CURRENT_LIST_DIR}/ArrowFlightSqlOdbcTargets.cmake")
33+
34+
arrow_keep_backward_compatibility(ArrowFlightSqlOdbc arrow_flight_sql_odbc)
35+
36+
check_required_components(ArrowFlightSqlOdbc)
37+
38+
arrow_show_details(ArrowFlightSqlOdbc ARROW_FLIGHT_SQL_ODBC)

cpp/src/arrow/flight/sql/odbc/CMakeLists.txt

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,64 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
add_custom_target(arrow_flight_sql_odbc)
19-
2018
# Use C++ 20 for ODBC and its subdirectory
2119
# GH-44792: Arrow will switch to C++ 20
2220
set(CMAKE_CXX_STANDARD 20)
2321

22+
add_custom_target(arrow_flight_sql_odbc)
23+
24+
if(WIN32)
25+
if(MSVC_VERSION GREATER_EQUAL 1900)
26+
set(ODBCINST legacy_stdio_definitions odbccp32 shlwapi)
27+
elseif(MINGW)
28+
set(ODBCINST odbccp32 shlwapi)
29+
endif()
30+
elseif(APPLE)
31+
set(ODBCINST iodbcinst)
32+
else()
33+
set(ODBCINST odbcinst)
34+
endif()
35+
2436
add_subdirectory(flight_sql)
2537
add_subdirectory(odbcabstraction)
38+
39+
arrow_install_all_headers("arrow/flight/sql/odbc")
40+
41+
set(ARROW_FLIGHT_SQL_ODBC_SRCS entry_points.cc odbc_api.cc)
42+
43+
if(WIN32)
44+
list(APPEND ARROW_FLIGHT_SQL_ODBC_SRCS odbc.def)
45+
endif()
46+
47+
add_arrow_lib(arrow_flight_sql_odbc
48+
CMAKE_PACKAGE_NAME
49+
ArrowFlightSqlOdbc
50+
PKG_CONFIG_NAME
51+
arrow-flight-sql-odbc
52+
OUTPUTS
53+
ARROW_FLIGHT_SQL_ODBC_LIBRARIES
54+
SOURCES
55+
${ARROW_FLIGHT_SQL_ODBC_SRCS}
56+
DEPENDENCIES
57+
arrow_flight_sql
58+
DEFINITIONS
59+
FMT_HEADER_ONLY
60+
SHARED_LINK_FLAGS
61+
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
62+
SHARED_LINK_LIBS
63+
arrow_flight_sql_shared
64+
SHARED_INSTALL_INTERFACE_LIBS
65+
ArrowFlight::arrow_flight_sql_shared
66+
STATIC_LINK_LIBS
67+
arrow_flight_sql_static
68+
STATIC_INSTALL_INTERFACE_LIBS
69+
ArrowFlight::arrow_flight_sql_static
70+
SHARED_PRIVATE_LINK_LIBS
71+
ODBC::ODBC
72+
${ODBCINST}
73+
odbcabstraction
74+
arrow_odbc_spi_impl)
75+
76+
foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES})
77+
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING)
78+
endforeach()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
prefix=@CMAKE_INSTALL_PREFIX@
19+
includedir=@ARROW_PKG_CONFIG_INCLUDEDIR@
20+
libdir=@ARROW_PKG_CONFIG_LIBDIR@
21+
22+
Name: Apache Arrow Flight SQL ODBC
23+
Description: Apache Arrow Flight SQL ODBC extension
24+
Version: @ARROW_VERSION@
25+
Requires: arrow-flight-sql
26+
Libs: -L${libdir} -larrow_flight_sql_odbc
27+
Cflags.private: -DARROW_FLIGHT_SQL_ODBC_STATIC
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
// platform.h includes windows.h, so it needs to be included first
19+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
20+
21+
#include <sql.h>
22+
#include <sqlext.h>
23+
#include <sqltypes.h>
24+
#include <sqlucode.h>
25+
26+
#include "arrow/flight/sql/odbc/odbc_api_internal.h"
27+
#include "arrow/flight/sql/odbc/visibility.h"
28+
29+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_connection.h"
30+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_descriptor.h"
31+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h"
32+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_statement.h"
33+
34+
#include "arrow/util/logging.h"
35+
36+
SQLRETURN SQL_API SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
37+
return SQL_INVALID_HANDLE;
38+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; Licensed to the Apache Software Foundation (ASF) under one
2+
; or more contributor license agreements. See the NOTICE file
3+
; distributed with this work for additional information
4+
; regarding copyright ownership. The ASF licenses this file
5+
; to you under the Apache License, Version 2.0 (the
6+
; "License"); you may not use this file except in compliance
7+
; with the License. You may obtain a copy of the License at
8+
;
9+
; http://www.apache.org/licenses/LICENSE-2.0
10+
;
11+
; Unless required by applicable law or agreed to in writing,
12+
; software distributed under the License is distributed on an
13+
; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
; KIND, either express or implied. See the License for the
15+
; specific language governing permissions and limitations
16+
; under the License.
17+
18+
LIBRARY arrow_flight_sql_odbc
19+
EXPORTS
20+
; TODO: update to ConfigDSNW when driver has unicode implemented
21+
ConfigDSN
22+
SQLAllocConnect
23+
SQLAllocEnv
24+
SQLAllocHandle
25+
SQLAllocStmt
26+
SQLBindCol
27+
SQLCancel
28+
SQLCloseCursor
29+
SQLColAttributeW
30+
SQLColumnsW
31+
SQLConnectW
32+
SQLDescribeColW
33+
SQLDisconnect
34+
SQLDriverConnectW
35+
SQLExecDirectW
36+
SQLExecute
37+
SQLExtendedFetch
38+
SQLFetch
39+
SQLFetchScroll
40+
SQLForeignKeysW
41+
SQLFreeEnv
42+
SQLFreeConnect
43+
SQLFreeHandle
44+
SQLFreeStmt
45+
SQLGetConnectAttrW
46+
SQLGetData
47+
SQLGetDiagFieldW
48+
SQLGetDiagRecW
49+
SQLGetEnvAttr
50+
SQLGetInfoW
51+
SQLGetStmtAttrW
52+
SQLGetTypeInfoW
53+
SQLRowCount
54+
SQLMoreResults
55+
SQLNativeSqlW
56+
SQLNumResultCols
57+
SQLPrepareW
58+
SQLPrimaryKeysW
59+
SQLSetConnectAttrW
60+
SQLSetEnvAttr
61+
SQLSetStmtAttrW
62+
SQLTablesW
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
// flight_sql_connection.h needs to be included first due to conflicts with windows.h
19+
#include "arrow/flight/sql/odbc/flight_sql/flight_sql_connection.h"
20+
21+
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/config/configuration.h"
22+
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h"
23+
#include "arrow/flight/sql/odbc/odbc_api_internal.h"
24+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/diagnostics.h"
25+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/attribute_utils.h"
26+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/encoding_utils.h"
27+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_connection.h"
28+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_descriptor.h"
29+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h"
30+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_statement.h"
31+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/spi/connection.h"
32+
#include "arrow/util/logging.h"
33+
34+
namespace arrow::flight::sql::odbc {
35+
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
36+
ARROW_LOG(DEBUG) << "SQLAllocHandle called with type: " << type
37+
<< ", parent: " << parent
38+
<< ", result: " << static_cast<const void*>(result);
39+
40+
return SQL_INVALID_HANDLE;
41+
}
42+
43+
} // namespace arrow::flight::sql::odbc
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#pragma once
19+
20+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
21+
22+
#include <sql.h>
23+
#include <sqltypes.h>
24+
#include <sqlucode.h>
25+
26+
// \file odbc_api_internal.h
27+
//
28+
// Define internal ODBC API function headers.
29+
namespace arrow::flight::sql::odbc {
30+
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result);
31+
} // namespace arrow::flight::sql::odbc

cpp/src/arrow/flight/sql/odbc/odbcabstraction/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
include_directories(include)
19-
20-
# Ensure fmt is loaded as header only
21-
add_compile_definitions(FMT_HEADER_ONLY)
18+
arrow_install_all_headers("arrow/flight/sql/odbc/odbcabstraction/include")
2219

2320
add_library(odbcabstraction
2421
include/odbcabstraction/calendar_utils.h
@@ -52,7 +49,7 @@ add_library(odbcabstraction
5249
odbc_impl/odbc_environment.cc
5350
odbc_impl/odbc_statement.cc)
5451
target_include_directories(odbcabstraction PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
55-
target_link_libraries(odbcabstraction PUBLIC ${ODBC_LIBRARIES} Boost::headers)
52+
target_link_libraries(odbcabstraction PUBLIC ODBC::ODBC Boost::headers)
5653

5754
set_target_properties(odbcabstraction
5855
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#pragma once
19+
20+
#if defined(_WIN32) || defined(__CYGWIN__)
21+
# if defined(_MSC_VER)
22+
# pragma warning(push)
23+
# pragma warning(disable : 4251)
24+
# else
25+
# pragma GCC diagnostic ignored "-Wattributes"
26+
# endif
27+
28+
# ifdef ARROW_FLIGHT_SQL_ODBC_STATIC
29+
# define ARROW_FLIGHT_SQL_ODBC_EXPORT
30+
# elif defined(ARROW_FLIGHT_SQL_ODBC_EXPORTING)
31+
# define ARROW_FLIGHT_SQL_ODBC_EXPORT __declspec(dllexport)
32+
# else
33+
# define ARROW_FLIGHT_SQL_ODBC_EXPORT __declspec(dllimport)
34+
# endif
35+
36+
# define ARROW_FLIGHT_SQL_ODBC_NO_EXPORT
37+
#else // Not Windows
38+
# ifndef ARROW_FLIGHT_SQL_ODBC_EXPORT
39+
# define ARROW_FLIGHT_SQL_ODBC_EXPORT __attribute__((visibility("default")))
40+
# endif
41+
# ifndef ARROW_FLIGHT_SQL_ODBC_NO_EXPORT
42+
# define ARROW_FLIGHT_SQL_ODBC_NO_EXPORT __attribute__((visibility("hidden")))
43+
# endif
44+
#endif // Non-Windows
45+
46+
#if defined(_MSC_VER)
47+
# pragma warning(pop)
48+
#endif

0 commit comments

Comments
 (0)