Skip to content
Merged
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
20 changes: 18 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1177,8 +1177,24 @@ SQLRETURN SQLTables(SQLHSTMT stmt, SQLWCHAR* catalog_name,
<< ", table_name_length: " << table_name_length
<< ", table_type: " << static_cast<const void*>(table_type)
<< ", table_type_length: " << table_type_length;
// GH-47719 TODO: Implement SQLTables
return SQL_INVALID_HANDLE;

using ODBC::ODBCStatement;
using ODBC::SqlWcharToString;

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

std::string catalog = SqlWcharToString(catalog_name, catalog_name_length);
std::string schema = SqlWcharToString(schema_name, schema_name_length);
std::string table = SqlWcharToString(table_name, table_name_length);
std::string type = SqlWcharToString(table_type, table_type_length);

statement->GetTables(catalog_name ? &catalog : nullptr,
schema_name ? &schema : nullptr, table_name ? &table : nullptr,
table_type ? &type : nullptr);

return SQL_SUCCESS;
});
}

SQLRETURN SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalog_name,
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 @@ -40,6 +40,7 @@ add_arrow_test(flight_sql_odbc_test
errors_test.cc
statement_attr_test.cc
statement_test.cc
tables_test.cc
# Enable Protobuf cleanup after test execution
# GH-46889: move protobuf_test_util to a more common location
../../../../engine/substrait/protobuf_test_util.cc
Expand Down
16 changes: 16 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,22 @@ bool WriteDSN(Connection::ConnPropertyMap properties) {
}
#endif

std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id) {
SQLWCHAR buf[1024];
SQLLEN len_indicator = 0;

EXPECT_EQ(SQL_SUCCESS,
SQLGetData(stmt, col_id, SQL_C_WCHAR, buf, sizeof(buf), &len_indicator));

if (len_indicator == SQL_NULL_DATA) {
return L"";
}

// indicator is in bytes, so convert to character count
size_t char_count = static_cast<size_t>(len_indicator) / GetSqlWCharSize();
return std::wstring(buf, buf + char_count);
}

std::wstring ConvertToWString(const std::vector<SQLWCHAR>& str_val, SQLSMALLINT str_len) {
std::wstring attr_str;
if (str_len == 0) {
Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ bool WriteDSN(std::string connection_str);
/// \return true on success
bool WriteDSN(Connection::ConnPropertyMap properties);

/// \brief Get wide string column.
/// \param[in] stmt Statement.
/// \param[in] col_id Column ID to check.
/// \return wstring
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id);

/// \brief Check wide char vector and convert into wstring
/// \param[in] str_val Vector of SQLWCHAR.
/// \param[in] str_len length of string, in bytes.
Expand Down
Loading
Loading