Skip to content
Open
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
4 changes: 2 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ void ODBCConnection::SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
case SQL_ATTR_CURRENT_CATALOG: {
std::string catalog;
if (is_unicode) {
SetAttributeUTF8(value, string_length, catalog);
} else {
SetAttributeSQLWCHAR(value, string_length, catalog);
} else {
SetAttributeUTF8(value, string_length, catalog);
}
if (!spi_connection_->SetAttribute(Connection::CURRENT_CATALOG, catalog)) {
throw DriverException("Option value changed.", "01S02");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void ODBCDescriptor::SetField(SQLSMALLINT record_number, SQLSMALLINT field_ident
has_bindings_changed_ = true;
break;
case SQL_DESC_NAME:
SetAttributeUTF8(value, buffer_length, record.name);
SetAttributeSQLWCHAR(value, buffer_length, record.name);
has_bindings_changed_ = true;
break;
case SQL_DESC_OCTET_LENGTH:
Expand Down
19 changes: 19 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/connection_attr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,23 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrPacketSizeValid) {
#endif
}

// A multi-character catalog set through the wide entry point must round-trip
// intact.
TYPED_TEST(ConnectionAttributeTest, TestSQLSetGetConnectAttrCurrentCatalogWide) {
ASSIGN_SQLWCHAR_ARR_AND_LEN(catalog, L"my_catalog");

ASSERT_EQ(SQL_SUCCESS, SQLSetConnectAttr(this->conn, SQL_ATTR_CURRENT_CATALOG, catalog,
catalog_len * GetSqlWCharSize()));

SQLWCHAR out_str[kOdbcBufferSize];
SQLINTEGER out_str_len;
ASSERT_EQ(SQL_SUCCESS, SQLGetConnectAttr(this->conn, SQL_ATTR_CURRENT_CATALOG, out_str,
kOdbcBufferSize, &out_str_len));
// SQLGetConnectAttr returns the length in bytes; convert to characters.
out_str_len /= GetSqlWCharSize();
std::string out_catalog =
ODBC::SqlWcharToString(out_str, static_cast<SQLSMALLINT>(out_str_len));
EXPECT_EQ("my_catalog", out_catalog);
}

} // namespace arrow::flight::sql::odbc
Loading