Skip to content

Commit 4a2f695

Browse files
alinaliBQjusting-bqrscales
committed
Extract SQLTables implementation
Co-authored-by: justing-bq <[email protected]> Co-authored-by: alinalibq <[email protected]> Co-Authored-By: rscales <[email protected]>
1 parent 19650fe commit 4a2f695

File tree

5 files changed

+530
-2
lines changed

5 files changed

+530
-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
@@ -1174,8 +1174,24 @@ SQLRETURN SQLTables(SQLHSTMT stmt, SQLWCHAR* catalog_name,
11741174
<< ", table_name_length: " << table_name_length
11751175
<< ", table_type: " << static_cast<const void*>(table_type)
11761176
<< ", table_type_length: " << table_type_length;
1177-
// GH-47719 TODO: Implement SQLTables
1178-
return SQL_INVALID_HANDLE;
1177+
1178+
using ODBC::ODBCStatement;
1179+
using ODBC::SqlWcharToString;
1180+
1181+
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
1182+
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);
1183+
1184+
std::string catalog = SqlWcharToString(catalog_name, catalog_name_length);
1185+
std::string schema = SqlWcharToString(schema_name, schema_name_length);
1186+
std::string table = SqlWcharToString(table_name, table_name_length);
1187+
std::string type = SqlWcharToString(table_type, table_type_length);
1188+
1189+
statement->GetTables(catalog_name ? &catalog : nullptr,
1190+
schema_name ? &schema : nullptr, table_name ? &table : nullptr,
1191+
table_type ? &type : nullptr);
1192+
1193+
return SQL_SUCCESS;
1194+
});
11791195
}
11801196

11811197
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
@@ -38,6 +38,7 @@ add_arrow_test(flight_sql_odbc_test
3838
connection_test.cc
3939
statement_attr_test.cc
4040
statement_test.cc
41+
tables_test.cc
4142
# Enable Protobuf cleanup after test execution
4243
# GH-46889: move protobuf_test_util to a more common location
4344
../../../../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
@@ -483,6 +483,22 @@ bool WriteDSN(Connection::ConnPropertyMap properties) {
483483
}
484484
#endif
485485

486+
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id) {
487+
SQLWCHAR buf[1024];
488+
SQLLEN len_indicator = 0;
489+
490+
EXPECT_EQ(SQL_SUCCESS,
491+
SQLGetData(stmt, col_id, SQL_C_WCHAR, buf, sizeof(buf), &len_indicator));
492+
493+
if (len_indicator == SQL_NULL_DATA) {
494+
return L"";
495+
}
496+
497+
// indicator is in bytes, so convert to character count
498+
size_t char_count = static_cast<size_t>(len_indicator) / GetSqlWCharSize();
499+
return std::wstring(buf, buf + char_count);
500+
}
501+
486502
std::wstring ConvertToWString(const std::vector<SQLWCHAR>& str_val, SQLSMALLINT str_len) {
487503
std::wstring attr_str;
488504
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
@@ -250,6 +250,12 @@ bool WriteDSN(std::string connection_str);
250250
/// \return true on success
251251
bool WriteDSN(Connection::ConnPropertyMap properties);
252252

253+
/// \brief Get wide string column.
254+
/// \param[in] stmt Statement.
255+
/// \param[in] col_id Column ID to check.
256+
/// \return wstring
257+
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id);
258+
253259
/// \brief Check wide char vector and convert into wstring
254260
/// \param[in] str_val Vector of SQLWCHAR.
255261
/// \param[in] str_len length of string, in bytes.

0 commit comments

Comments
 (0)