Skip to content

Commit c5ecd8e

Browse files
committed
Extract Implementation for SQLGetConnectAttr and SQLSetConnectAttr
1 parent 7a38744 commit c5ecd8e

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,33 @@ SQLRETURN SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attribute, SQLPOINTER value
118118
<< ", attribute: " << attribute << ", value_ptr: " << value_ptr
119119
<< ", buffer_length: " << buffer_length << ", string_length_ptr: "
120120
<< static_cast<const void*>(string_length_ptr);
121-
// GH-47708 TODO: Implement SQLGetConnectAttr
122-
return SQL_INVALID_HANDLE;
121+
122+
using arrow::flight::sql::odbc::Connection;
123+
using ODBC::ODBCConnection;
124+
125+
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
126+
const bool is_unicode = true;
127+
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
128+
return connection->GetConnectAttr(attribute, value_ptr, buffer_length,
129+
string_length_ptr, is_unicode);
130+
});
123131
}
124132

125133
SQLRETURN SQLSetConnectAttr(SQLHDBC conn, SQLINTEGER attr, SQLPOINTER value_ptr,
126134
SQLINTEGER value_len) {
127135
ARROW_LOG(DEBUG) << "SQLSetConnectAttrW called with conn: " << conn
128136
<< ", attr: " << attr << ", value_ptr: " << value_ptr
129137
<< ", value_len: " << value_len;
130-
// GH-47708 TODO: Implement SQLSetConnectAttr
131-
return SQL_INVALID_HANDLE;
138+
139+
using arrow::flight::sql::odbc::Connection;
140+
using ODBC::ODBCConnection;
141+
142+
return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
143+
const bool is_unicode = true;
144+
ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
145+
connection->SetConnectAttr(attr, value_ptr, value_len, is_unicode);
146+
return SQL_SUCCESS;
147+
});
132148
}
133149

134150
SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND window_handle,

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
@@ -578,58 +578,58 @@ void ODBCConnection::SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
578578
}
579579
}
580580

581-
void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
582-
SQLINTEGER buffer_length, SQLINTEGER* output_length,
583-
bool is_unicode) {
581+
SQLRETURN ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
582+
SQLINTEGER buffer_length,
583+
SQLINTEGER* output_length, bool is_unicode) {
584584
boost::optional<Connection::Attribute> spi_attribute;
585585

586586
switch (attribute) {
587587
// Internal connection attributes
588-
#ifdef SQL_ATR_ASYNC_DBC_EVENT
588+
#ifdef SQL_ATTR_ASYNC_DBC_EVENT
589589
case SQL_ATTR_ASYNC_DBC_EVENT:
590590
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
591-
return;
591+
return SQL_SUCCESS;
592592
#endif
593593
#ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
594594
case SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE:
595595
GetAttribute(static_cast<SQLUINTEGER>(SQL_ASYNC_DBC_ENABLE_OFF), value,
596596
buffer_length, output_length);
597-
return;
597+
return SQL_SUCCESS;
598598
#endif
599-
#ifdef SQL_ATTR_ASYNC_PCALLBACK
599+
#ifdef SQL_ATTR_ASYNC_DBC_PCALLBACK
600600
case SQL_ATTR_ASYNC_DBC_PCALLBACK:
601601
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
602-
return;
602+
return SQL_SUCCESS;
603603
#endif
604604
#ifdef SQL_ATTR_ASYNC_DBC_PCONTEXT
605605
case SQL_ATTR_ASYNC_DBC_PCONTEXT:
606606
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
607-
return;
607+
return SQL_SUCCESS;
608608
#endif
609609
case SQL_ATTR_ASYNC_ENABLE:
610610
GetAttribute(static_cast<SQLULEN>(SQL_ASYNC_ENABLE_OFF), value, buffer_length,
611611
output_length);
612-
return;
612+
return SQL_SUCCESS;
613613
case SQL_ATTR_AUTO_IPD:
614614
GetAttribute(static_cast<SQLUINTEGER>(SQL_FALSE), value, buffer_length,
615615
output_length);
616-
return;
616+
return SQL_SUCCESS;
617617
case SQL_ATTR_AUTOCOMMIT:
618618
GetAttribute(static_cast<SQLUINTEGER>(SQL_AUTOCOMMIT_ON), value, buffer_length,
619619
output_length);
620-
return;
620+
return SQL_SUCCESS;
621621
#ifdef SQL_ATTR_DBC_INFO_TOKEN
622622
case SQL_ATTR_DBC_INFO_TOKEN:
623623
throw DriverException("Cannot read set-only attribute", "HY092");
624624
#endif
625625
case SQL_ATTR_ENLIST_IN_DTC:
626626
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
627-
return;
627+
return SQL_SUCCESS;
628628
case SQL_ATTR_ODBC_CURSORS: // DM-only.
629629
throw DriverException("Invalid attribute", "HY092");
630630
case SQL_ATTR_QUIET_MODE:
631631
GetAttribute(static_cast<SQLPOINTER>(NULL), value, buffer_length, output_length);
632-
return;
632+
return SQL_SUCCESS;
633633
case SQL_ATTR_TRACE: // DM-only
634634
throw DriverException("Invalid attribute", "HY092");
635635
case SQL_ATTR_TRACEFILE:
@@ -639,17 +639,16 @@ void ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
639639
case SQL_ATTR_TRANSLATE_OPTION:
640640
throw DriverException("Optional feature not supported.", "HYC00");
641641
case SQL_ATTR_TXN_ISOLATION:
642-
throw DriverException("Optional feature not supported.", "HCY00");
642+
throw DriverException("Optional feature not supported.", "HYC00");
643643

644644
case SQL_ATTR_CURRENT_CATALOG: {
645645
const auto& catalog = spi_connection_->GetAttribute(Connection::CURRENT_CATALOG);
646646
if (!catalog) {
647647
throw DriverException("Optional feature not supported.", "HYC00");
648648
}
649649
const std::string& info_value = boost::get<std::string>(*catalog);
650-
GetStringAttribute(is_unicode, info_value, true, value, buffer_length,
651-
output_length, GetDiagnostics());
652-
return;
650+
return GetStringAttribute(is_unicode, info_value, true, value, buffer_length,
651+
output_length, GetDiagnostics());
653652
}
654653

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

679678
GetAttribute(static_cast<SQLUINTEGER>(boost::get<uint32_t>(*spi_attribute)), value,
680679
buffer_length, output_length);
680+
return SQL_SUCCESS;
681681
}
682682

683683
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
@@ -56,8 +56,9 @@ class ODBCConnection : public ODBCHandle<ODBCConnection> {
5656
SQLSMALLINT* output_length, bool is_unicode);
5757
void SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER string_length,
5858
bool isUnicode);
59-
void GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER buffer_length,
60-
SQLINTEGER* output_length, bool is_unicode);
59+
SQLRETURN GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
60+
SQLINTEGER buffer_length, SQLINTEGER* output_length,
61+
bool is_unicode);
6162

6263
~ODBCConnection() = default;
6364

0 commit comments

Comments
 (0)