Skip to content

Commit 83b5b7b

Browse files
alinaliBQrscales
authored andcommitted
Extract SQLTables implementation
Co-Authored-By: rscales <[email protected]>
1 parent 934554d commit 83b5b7b

File tree

5 files changed

+623
-2
lines changed

5 files changed

+623
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,24 @@ SQLRETURN SQLTables(SQLHSTMT stmt, SQLWCHAR* catalog_name,
915915
<< ", table_name_length: " << table_name_length
916916
<< ", table_type: " << static_cast<const void*>(table_type)
917917
<< ", table_type_length: " << table_type_length;
918-
// GH-47719 TODO: Implement SQLTables
919-
return SQL_INVALID_HANDLE;
918+
919+
using ODBC::ODBCStatement;
920+
using ODBC::SqlWcharToString;
921+
922+
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
923+
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);
924+
925+
std::string catalog = SqlWcharToString(catalog_name, catalog_name_length);
926+
std::string schema = SqlWcharToString(schema_name, schema_name_length);
927+
std::string table = SqlWcharToString(table_name, table_name_length);
928+
std::string type = SqlWcharToString(table_type, table_type_length);
929+
930+
statement->GetTables(catalog_name ? &catalog : nullptr,
931+
schema_name ? &schema : nullptr, table_name ? &table : nullptr,
932+
table_type ? &type : nullptr);
933+
934+
return SQL_SUCCESS;
935+
});
920936
}
921937

922938
SQLRETURN SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalog_name,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ add_arrow_test(flight_sql_odbc_test
3535
odbc_test_suite.cc
3636
odbc_test_suite.h
3737
connection_test.cc
38+
tables_test.cc
3839
# Enable Protobuf cleanup after test execution
3940
# GH-46889: move protobuf_test_util to a more common location
4041
../../../../engine/substrait/protobuf_test_util.cc

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,22 @@ bool WriteDSN(Connection::ConnPropertyMap properties) {
440440
}
441441
#endif
442442

443+
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id) {
444+
SQLWCHAR buf[1024];
445+
SQLLEN len_indicator = 0;
446+
447+
EXPECT_EQ(SQL_SUCCESS,
448+
SQLGetData(stmt, col_id, SQL_C_WCHAR, buf, sizeof(buf), &len_indicator));
449+
450+
if (len_indicator == SQL_NULL_DATA) {
451+
return L"";
452+
}
453+
454+
// indicator is in bytes, so convert to character count
455+
size_t char_count = static_cast<size_t>(len_indicator) / ODBC::GetSqlWCharSize();
456+
return std::wstring(buf, buf + char_count);
457+
}
458+
443459
std::wstring ConvertToWString(const std::vector<SQLWCHAR>& str_val, SQLSMALLINT str_len) {
444460
std::wstring attr_str;
445461
if (str_len == 0) {

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ bool WriteDSN(std::string connection_str);
217217
/// \return true on success
218218
bool WriteDSN(Connection::ConnPropertyMap properties);
219219

220+
/// \brief Get wide string column.
221+
/// \param[in] stmt Statement.
222+
/// \param[in] col_id Column ID to check.
223+
/// \return wstring
224+
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id);
225+
220226
/// \brief Check wide char vector and convert into wstring
221227
/// \param[in] str_val Vector of SQLWCHAR.
222228
/// \param[in] str_len length of string, in bytes.

0 commit comments

Comments
 (0)