Skip to content

Commit 95cdc0c

Browse files
authored
GH-47708: [C++][FlightRPC] Connection Attribute Support for ODBC (#47772)
### Rationale for this change Add connection attribute support for ODBC driver. ### What changes are included in this PR? - Implementation of `SQLGetConnectAttr` and `SQLSetConnectAttr` to get and set connection attributes - Tests ### Are these changes tested? Tested on local MSVC ### Are there any user-facing changes? No * GitHub Issue: #47708 Authored-by: Alina (Xi) Li <[email protected]> Signed-off-by: David Li <[email protected]>
1 parent 91f6618 commit 95cdc0c

File tree

5 files changed

+395
-24
lines changed

5 files changed

+395
-24
lines changed

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,16 +714,23 @@ SQLRETURN SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attribute, SQLPOINTER value
714714
<< ", attribute: " << attribute << ", value_ptr: " << value_ptr
715715
<< ", buffer_length: " << buffer_length << ", string_length_ptr: "
716716
<< static_cast<const void*>(string_length_ptr);
717-
// GH-47708 TODO: Implement SQLGetConnectAttr
718-
return SQL_INVALID_HANDLE;
717+
718+
using ODBC::ODBCConnection;
719+
720+
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
721+
const bool is_unicode = true;
722+
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
723+
return connection->GetConnectAttr(attribute, value_ptr, buffer_length,
724+
string_length_ptr, is_unicode);
725+
});
719726
}
720727

721728
SQLRETURN SQLSetConnectAttr(SQLHDBC conn, SQLINTEGER attr, SQLPOINTER value_ptr,
722729
SQLINTEGER value_len) {
723730
ARROW_LOG(DEBUG) << "SQLSetConnectAttrW called with conn: " << conn
724731
<< ", attr: " << attr << ", value_ptr: " << value_ptr
725732
<< ", value_len: " << value_len;
726-
// GH-47708 TODO: Add tests for SQLSetConnectAttr
733+
727734
using ODBC::ODBCConnection;
728735

729736
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -528,58 +528,58 @@ void ODBCConnection::SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
528528
}
529529
}
530530

531-
void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
532-
SQLINTEGER buffer_length, SQLINTEGER* output_length,
533-
bool is_unicode) {
531+
SQLRETURN ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
532+
SQLINTEGER buffer_length,
533+
SQLINTEGER* output_length, bool is_unicode) {
534534
boost::optional<Connection::Attribute> spi_attribute;
535535

536536
switch (attribute) {
537537
// Internal connection attributes
538-
#ifdef SQL_ATR_ASYNC_DBC_EVENT
538+
#ifdef SQL_ATTR_ASYNC_DBC_EVENT
539539
case SQL_ATTR_ASYNC_DBC_EVENT:
540540
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
541-
return;
541+
return SQL_SUCCESS;
542542
#endif
543543
#ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
544544
case SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE:
545545
GetAttribute(static_cast<SQLUINTEGER>(SQL_ASYNC_DBC_ENABLE_OFF), value,
546546
buffer_length, output_length);
547-
return;
547+
return SQL_SUCCESS;
548548
#endif
549-
#ifdef SQL_ATTR_ASYNC_PCALLBACK
549+
#ifdef SQL_ATTR_ASYNC_DBC_PCALLBACK
550550
case SQL_ATTR_ASYNC_DBC_PCALLBACK:
551551
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
552-
return;
552+
return SQL_SUCCESS;
553553
#endif
554554
#ifdef SQL_ATTR_ASYNC_DBC_PCONTEXT
555555
case SQL_ATTR_ASYNC_DBC_PCONTEXT:
556556
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
557-
return;
557+
return SQL_SUCCESS;
558558
#endif
559559
case SQL_ATTR_ASYNC_ENABLE:
560560
GetAttribute(static_cast<SQLULEN>(SQL_ASYNC_ENABLE_OFF), value, buffer_length,
561561
output_length);
562-
return;
562+
return SQL_SUCCESS;
563563
case SQL_ATTR_AUTO_IPD:
564564
GetAttribute(static_cast<SQLUINTEGER>(SQL_FALSE), value, buffer_length,
565565
output_length);
566-
return;
566+
return SQL_SUCCESS;
567567
case SQL_ATTR_AUTOCOMMIT:
568568
GetAttribute(static_cast<SQLUINTEGER>(SQL_AUTOCOMMIT_ON), value, buffer_length,
569569
output_length);
570-
return;
570+
return SQL_SUCCESS;
571571
#ifdef SQL_ATTR_DBC_INFO_TOKEN
572572
case SQL_ATTR_DBC_INFO_TOKEN:
573573
throw DriverException("Cannot read set-only attribute", "HY092");
574574
#endif
575575
case SQL_ATTR_ENLIST_IN_DTC:
576576
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
577-
return;
577+
return SQL_SUCCESS;
578578
case SQL_ATTR_ODBC_CURSORS: // DM-only.
579579
throw DriverException("Invalid attribute", "HY092");
580580
case SQL_ATTR_QUIET_MODE:
581581
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
582-
return;
582+
return SQL_SUCCESS;
583583
case SQL_ATTR_TRACE: // DM-only
584584
throw DriverException("Invalid attribute", "HY092");
585585
case SQL_ATTR_TRACEFILE:
@@ -589,17 +589,16 @@ void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
589589
case SQL_ATTR_TRANSLATE_OPTION:
590590
throw DriverException("Optional feature not supported.", "HYC00");
591591
case SQL_ATTR_TXN_ISOLATION:
592-
throw DriverException("Optional feature not supported.", "HCY00");
592+
throw DriverException("Optional feature not supported.", "HYC00");
593593

594594
case SQL_ATTR_CURRENT_CATALOG: {
595595
const auto& catalog = spi_connection_->GetAttribute(Connection::CURRENT_CATALOG);
596596
if (!catalog) {
597597
throw DriverException("Optional feature not supported.", "HYC00");
598598
}
599599
const std::string& info_value = boost::get<std::string>(*catalog);
600-
GetStringAttribute(is_unicode, info_value, true, value, buffer_length,
601-
output_length, GetDiagnostics());
602-
return;
600+
return GetStringAttribute(is_unicode, info_value, true, value, buffer_length,
601+
output_length, GetDiagnostics());
603602
}
604603

605604
// These all are uint32_t attributes.
@@ -628,6 +627,7 @@ void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
628627

629628
GetAttribute(static_cast<SQLUINTEGER>(boost::get<uint32_t>(*spi_attribute)), value,
630629
buffer_length, output_length);
630+
return SQL_SUCCESS;
631631
}
632632

633633
void ODBCConnection::Disconnect() {

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ class ODBCConnection : public ODBCHandle<ODBCConnection> {
5757
SQLSMALLINT* output_length, bool is_unicode);
5858
void SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER string_length,
5959
bool isUnicode);
60-
void GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER buffer_length,
61-
SQLINTEGER* output_length, bool is_unicode);
60+
SQLRETURN GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
61+
SQLINTEGER buffer_length, SQLINTEGER* output_length,
62+
bool is_unicode);
6263

6364
~ODBCConnection() = default;
6465

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ add_arrow_test(flight_sql_odbc_test
3434
SOURCES
3535
odbc_test_suite.cc
3636
odbc_test_suite.h
37-
statement_attr_test.cc
37+
connection_attr_test.cc
3838
connection_test.cc
39+
statement_attr_test.cc
3940
# Enable Protobuf cleanup after test execution
4041
# GH-46889: move protobuf_test_util to a more common location
4142
../../../../engine/substrait/protobuf_test_util.cc

0 commit comments

Comments
 (0)