Skip to content
Draft
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
24 changes: 20 additions & 4 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,33 @@ SQLRETURN SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attribute, SQLPOINTER value
<< ", attribute: " << attribute << ", value_ptr: " << value_ptr
<< ", buffer_length: " << buffer_length << ", string_length_ptr: "
<< static_cast<const void*>(string_length_ptr);
// GH-47708 TODO: Implement SQLGetConnectAttr
return SQL_INVALID_HANDLE;

using arrow::flight::sql::odbc::Connection;
using ODBC::ODBCConnection;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
const bool is_unicode = true;
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
return connection->GetConnectAttr(attribute, value_ptr, buffer_length,
string_length_ptr, is_unicode);
});
}

SQLRETURN SQLSetConnectAttr(SQLHDBC conn, SQLINTEGER attr, SQLPOINTER value_ptr,
SQLINTEGER value_len) {
ARROW_LOG(DEBUG) << "SQLSetConnectAttrW called with conn: " << conn
<< ", attr: " << attr << ", value_ptr: " << value_ptr
<< ", value_len: " << value_len;
// GH-47708 TODO: Implement SQLSetConnectAttr
return SQL_INVALID_HANDLE;

using arrow::flight::sql::odbc::Connection;
using ODBC::ODBCConnection;

return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
const bool is_unicode = true;
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
connection->SetConnectAttr(attr, value_ptr, value_len, is_unicode);
return SQL_SUCCESS;
});
}

SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND window_handle,
Expand Down
36 changes: 18 additions & 18 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -578,58 +578,58 @@ void ODBCConnection::SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
}
}

void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
SQLINTEGER buffer_length, SQLINTEGER* output_length,
bool is_unicode) {
SQLRETURN ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
SQLINTEGER buffer_length,
SQLINTEGER* output_length, bool is_unicode) {
boost::optional<Connection::Attribute> spi_attribute;

switch (attribute) {
// Internal connection attributes
#ifdef SQL_ATR_ASYNC_DBC_EVENT
#ifdef SQL_ATTR_ASYNC_DBC_EVENT
case SQL_ATTR_ASYNC_DBC_EVENT:
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
return;
return SQL_SUCCESS;
#endif
#ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
case SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE:
GetAttribute(static_cast<SQLUINTEGER>(SQL_ASYNC_DBC_ENABLE_OFF), value,
buffer_length, output_length);
return;
return SQL_SUCCESS;
#endif
#ifdef SQL_ATTR_ASYNC_PCALLBACK
#ifdef SQL_ATTR_ASYNC_DBC_PCALLBACK
case SQL_ATTR_ASYNC_DBC_PCALLBACK:
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
return;
return SQL_SUCCESS;
#endif
#ifdef SQL_ATTR_ASYNC_DBC_PCONTEXT
case SQL_ATTR_ASYNC_DBC_PCONTEXT:
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
return;
return SQL_SUCCESS;
#endif
case SQL_ATTR_ASYNC_ENABLE:
GetAttribute(static_cast<SQLULEN>(SQL_ASYNC_ENABLE_OFF), value, buffer_length,
output_length);
return;
return SQL_SUCCESS;
case SQL_ATTR_AUTO_IPD:
GetAttribute(static_cast<SQLUINTEGER>(SQL_FALSE), value, buffer_length,
output_length);
return;
return SQL_SUCCESS;
case SQL_ATTR_AUTOCOMMIT:
GetAttribute(static_cast<SQLUINTEGER>(SQL_AUTOCOMMIT_ON), value, buffer_length,
output_length);
return;
return SQL_SUCCESS;
#ifdef SQL_ATTR_DBC_INFO_TOKEN
case SQL_ATTR_DBC_INFO_TOKEN:
throw DriverException("Cannot read set-only attribute", "HY092");
#endif
case SQL_ATTR_ENLIST_IN_DTC:
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
return;
return SQL_SUCCESS;
case SQL_ATTR_ODBC_CURSORS: // DM-only.
throw DriverException("Invalid attribute", "HY092");
case SQL_ATTR_QUIET_MODE:
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
return;
return SQL_SUCCESS;
case SQL_ATTR_TRACE: // DM-only
throw DriverException("Invalid attribute", "HY092");
case SQL_ATTR_TRACEFILE:
Expand All @@ -639,17 +639,16 @@ void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
case SQL_ATTR_TRANSLATE_OPTION:
throw DriverException("Optional feature not supported.", "HYC00");
case SQL_ATTR_TXN_ISOLATION:
throw DriverException("Optional feature not supported.", "HCY00");
throw DriverException("Optional feature not supported.", "HYC00");

case SQL_ATTR_CURRENT_CATALOG: {
const auto& catalog = spi_connection_->GetAttribute(Connection::CURRENT_CATALOG);
if (!catalog) {
throw DriverException("Optional feature not supported.", "HYC00");
}
const std::string& info_value = boost::get<std::string>(*catalog);
GetStringAttribute(is_unicode, info_value, true, value, buffer_length,
output_length, GetDiagnostics());
return;
return GetStringAttribute(is_unicode, info_value, true, value, buffer_length,
output_length, GetDiagnostics());
}

// These all are uint32_t attributes.
Expand Down Expand Up @@ -678,6 +677,7 @@ void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,

GetAttribute(static_cast<SQLUINTEGER>(boost::get<uint32_t>(*spi_attribute)), value,
buffer_length, output_length);
return SQL_SUCCESS;
}

void ODBCConnection::Disconnect() {
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class ODBCConnection : public ODBCHandle<ODBCConnection> {
SQLSMALLINT* output_length, bool is_unicode);
void SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER string_length,
bool isUnicode);
void GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER buffer_length,
SQLINTEGER* output_length, bool is_unicode);
SQLRETURN GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
SQLINTEGER buffer_length, SQLINTEGER* output_length,
bool is_unicode);

~ODBCConnection() = default;

Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_arrow_test(flight_sql_odbc_test
SOURCES
odbc_test_suite.cc
odbc_test_suite.h
connection_attr_test.cc
connection_test.cc
# Enable Protobuf cleanup after test execution
# GH-46889: move protobuf_test_util to a more common location
Expand Down
Loading
Loading