Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/src/arrow/flight/sql/odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_arrow_lib(arrow_flight_sql_odbc
SHARED_INSTALL_INTERFACE_LIBS ArrowFlight::arrow_flight_sql_shared
STATIC_LINK_LIBS arrow_flight_sql_static
STATIC_INSTALL_INTERFACE_LIBS ArrowFlight::arrow_flight_sql_static
SHARED_PRIVATE_LINK_LIBS ODBC::ODBC)
SHARED_PRIVATE_LINK_LIBS ODBC::ODBC odbcabstraction arrow_odbc_spi_impl)

foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES})
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING)
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ SQLRETURN SQL_API SQLAllocEnv(SQLHENV* env) {
return arrow::SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, env);
}

SQLRETURN SQL_API SQLFreeEnv(SQLHENV env) {
return arrow::SQLFreeHandle(SQL_HANDLE_ENV, env);
}

SQLRETURN SQLFreeHandle(SQLSMALLINT type, SQLHANDLE handle) {
return arrow::SQLFreeHandle(type, handle);
}

SQLRETURN SQL_API SQLDriverConnect(SQLHDBC conn, SQLHWND windowHandle,
SQLWCHAR* inConnectionString,
SQLSMALLINT inConnectionStringLen,
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ target_include_directories(arrow_odbc_spi_impl PUBLIC ${CMAKE_CURRENT_LIST_DIR})

find_package(ArrowFlightSql)

target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction
arrow_flight_sql_static)
target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction arrow_flight_sql_shared)

if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "/MD")
Expand Down
61 changes: 51 additions & 10 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
// under the License.


#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h"
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h>
#include <arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h>

// odbc_api includes windows.h, which needs to be put behind winsock2.h.
// odbc_environment.h includes winsock2.h
#include "arrow/flight/sql/odbc/odbc_api.h"
#include <arrow/flight/sql/odbc/odbc_api.h>

namespace arrow
{
Expand All @@ -30,25 +31,65 @@ namespace arrow

switch (type)
{
case SQL_HANDLE_ENV:

// TODO: uncomment below code after flightsqlodbc is fixed
// using ODBCEnvironment;
// *result = reinterpret_cast< SQLHENV >(new ODBCEnvironment());

// return SQL_SUCCESS
case SQL_HANDLE_ENV: {
using ODBC::ODBCEnvironment;
using driver::flight_sql::FlightSqlDriver;

std::shared_ptr<FlightSqlDriver> odbc_driver = std::make_shared<FlightSqlDriver>();
*result = reinterpret_cast<SQLHENV>(new ODBCEnvironment(odbc_driver));

return SQL_SUCCESS;
}

case SQL_HANDLE_DBC: {
return SQL_INVALID_HANDLE;
}

case SQL_HANDLE_STMT: {
return SQL_INVALID_HANDLE;
}

default:
break;
}

return SQL_ERROR;
}

SQLRETURN SQLFreeHandle(SQLSMALLINT type, SQLHANDLE handle)
{
switch (type) {
case SQL_HANDLE_ENV: {
using ODBC::ODBCEnvironment;

ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(handle);

if (!environment) {
return SQL_INVALID_HANDLE;
}

delete environment;

return SQL_SUCCESS;
}

case SQL_HANDLE_DBC:
return SQL_INVALID_HANDLE;

case SQL_HANDLE_STMT:
return SQL_INVALID_HANDLE;

case SQL_HANDLE_DESC:
return SQL_INVALID_HANDLE;

default:
break;
}

return SQL_ERROR;
}
} // namespace arrow




} // namespace arrow
5 changes: 4 additions & 1 deletion cpp/src/arrow/flight/sql/odbc/odbc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@

namespace arrow
{
SQLRETURN SQLAllocEnv(SQLHENV* env);
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result);
} //arrow
SQLRETURN SQLFreeEnv(SQLHENV env);
SQLRETURN SQLFreeHandle(SQLSMALLINT type, SQLHANDLE handle);
} //arrow
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ const boost::xpressive::sregex CONNECTION_STR_REGEX(
// entries in the properties.
void loadPropertiesFromDSN(const std::string& dsn,
Connection::ConnPropertyMap& properties) {
// TODO - fix build errors with configuration window
/*
const size_t BUFFER_SIZE = 1024 * 10;
std::vector<char> outputBuffer;
outputBuffer.resize(BUFFER_SIZE, '\0');
SQLSetConfigMode(ODBC_BOTH_DSN);

SQLGetPrivateProfileString(dsn.c_str(), NULL, "", &outputBuffer[0], BUFFER_SIZE,
"odbc.ini");

Expand All @@ -81,14 +84,17 @@ void loadPropertiesFromDSN(const std::string& dsn,
for (auto& key : keys) {
outputBuffer.clear();
outputBuffer.resize(BUFFER_SIZE, '\0');

SQLGetPrivateProfileString(dsn.c_str(), key.c_str(), "", &outputBuffer[0],
BUFFER_SIZE, "odbc.ini");

std::string value = std::string(&outputBuffer[0]);
auto propIter = properties.find(key);
if (propIter == properties.end()) {
properties.emplace(std::make_pair(std::move(key), std::move(value)));
}
}
*/
}

} // namespace
Expand Down
39 changes: 38 additions & 1 deletion cpp/src/arrow/flight/sql/odbc/tests/connection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace flight {
namespace odbc {
namespace integration_tests {

TEST(connection_test, TestSQLAllocHandle) {
TEST(SQLAllocHandle, TestSQLAllocHandleEnv) {

// ODBC Environment
SQLHENV env;
Expand All @@ -40,6 +40,43 @@ TEST(connection_test, TestSQLAllocHandle) {
EXPECT_TRUE(env != NULL);
}

TEST(SQLAllocEnv, TestSQLAllocEnv) {

// ODBC Environment
SQLHENV env;

// Allocate an environment handle
SQLRETURN return_value = SQLAllocEnv(&env);

EXPECT_TRUE(return_value == SQL_SUCCESS);
}

TEST(SQLFreeHandle, TestSQLFreeHandleEnv) {
// ODBC Environment
SQLHENV env;

// Allocate an environment handle
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);

// Free an environment handle
SQLRETURN return_value = SQLFreeHandle(SQL_HANDLE_ENV, env);

EXPECT_TRUE(return_value == SQL_SUCCESS);
}

TEST(SQLFreeEnv, TestSQLFreeEnv) {
// ODBC Environment
SQLHENV env;

// Allocate an environment handle
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);

// Free an environment handle
SQLRETURN return_value = SQLFreeEnv(env);

EXPECT_TRUE(return_value == SQL_SUCCESS);
}

} // namespace integration_tests
} // namespace odbc
} // namespace flight
Expand Down
Loading