Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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
29 changes: 25 additions & 4 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,38 @@ SQLRETURN SQLGetStmtAttr(SQLHSTMT stmt, SQLINTEGER attribute, SQLPOINTER value_p
<< ", attribute: " << attribute << ", value_ptr: " << value_ptr
<< ", buffer_length: " << buffer_length << ", string_length_ptr: "
<< static_cast<const void*>(string_length_ptr);
// GH-47710 TODO: Implement SQLGetStmtAttr
return SQL_INVALID_HANDLE;

using ODBC::ODBCStatement;

return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);

bool is_unicode = true;

statement->GetStmtAttr(attribute, value_ptr, buffer_length, string_length_ptr,
is_unicode);

return SQL_SUCCESS;
});
}

SQLRETURN SQLSetStmtAttr(SQLHSTMT stmt, SQLINTEGER attribute, SQLPOINTER value_ptr,
SQLINTEGER string_length) {
ARROW_LOG(DEBUG) << "SQLSetStmtAttrW called with stmt: " << stmt
<< ", attribute: " << attribute << ", value_ptr: " << value_ptr
<< ", string_length: " << string_length;
// GH-47710 TODO: Implement SQLSetStmtAttr
return SQL_INVALID_HANDLE;

using ODBC::ODBCStatement;

return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);

bool is_unicode = true;

statement->SetStmtAttr(attribute, value_ptr, string_length, is_unicode);

return SQL_SUCCESS;
});
}

SQLRETURN SQLExecDirect(SQLHSTMT stmt, SQLWCHAR* query_text, SQLINTEGER text_length) {
Expand Down
18 changes: 17 additions & 1 deletion cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ void ODBCStatement::GetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER outpu
return;
case SQL_ATTR_PARAM_BIND_TYPE:
current_apd_->GetHeaderField(SQL_DESC_BIND_TYPE, output, buffer_size, str_len_ptr);
if (output) {
// Convert SQLINTEGER output to SQLULEN, since SQL_DESC_BIND_TYPE is SQLINTEGER
// and SQL_ATTR_PARAM_BIND_TYPE is SQLULEN
SQLINTEGER* output_int_ptr = reinterpret_cast<SQLINTEGER*>(output);
SQLINTEGER output_int = *output_int_ptr;
SQLULEN* typed_output = reinterpret_cast<SQLULEN*>(output);
*typed_output = static_cast<SQLULEN>(output_int);
}
return;
case SQL_ATTR_PARAM_OPERATION_PTR:
current_apd_->GetHeaderField(SQL_DESC_ARRAY_STATUS_PTR, output, buffer_size,
Expand All @@ -398,6 +406,14 @@ void ODBCStatement::GetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER outpu
return;
case SQL_ATTR_ROW_BIND_TYPE:
current_ard_->GetHeaderField(SQL_DESC_BIND_TYPE, output, buffer_size, str_len_ptr);
if (output) {
// Convert SQLINTEGER output to SQLULEN, since SQL_DESC_BIND_TYPE is SQLINTEGER
// and SQL_ATTR_ROW_BIND_TYPE is SQLULEN
SQLINTEGER* output_int_ptr = reinterpret_cast<SQLINTEGER*>(output);
SQLINTEGER output_int = *output_int_ptr;
SQLULEN* typed_output = reinterpret_cast<SQLULEN*>(output);
*typed_output = static_cast<SQLULEN>(output_int);
}
return;
case SQL_ATTR_ROW_OPERATION_PTR:
current_ard_->GetHeaderField(SQL_DESC_ARRAY_STATUS_PTR, output, buffer_size,
Expand Down Expand Up @@ -627,7 +643,7 @@ void ODBCStatement::SetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER value
CheckIfAttributeIsSetToOnlyValidValue(value, static_cast<SQLULEN>(SQL_UB_OFF));
return;
case SQL_ATTR_RETRIEVE_DATA:
CheckIfAttributeIsSetToOnlyValidValue(value, static_cast<SQLULEN>(SQL_TRUE));
CheckIfAttributeIsSetToOnlyValidValue(value, static_cast<SQLULEN>(SQL_RD_ON));
return;
case SQL_ROWSET_SIZE:
SetAttribute(value, rowset_size_);
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
statement_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