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
27 changes: 10 additions & 17 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ SQLRETURN SQL_API SQLColAttribute(SQLHSTMT stmt, SQLUSMALLINT columnNumber,
return SQL_ERROR;
}

SQLRETURN SQL_API SQLTables(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength, SQLWCHAR* tableType,
SQLSMALLINT tableTypeLength) {
return arrow::SQLTables(stmt, catalogName, catalogNameLength, schemaName,
schemaNameLength, tableName, tableNameLength, tableType,
tableTypeLength);
}

SQLRETURN SQL_API SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
Expand Down Expand Up @@ -282,20 +292,3 @@ SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT stmt, SQLINTEGER attribute, SQLPOINTER
SQLINTEGER stringLength) {
return arrow::SQLSetStmtAttr(stmt, attribute, valuePtr, stringLength);
}

SQLRETURN SQL_API SQLTables(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength, SQLWCHAR* tableType,
SQLSMALLINT tableTypeLength) {
LOG_DEBUG(
"SQLTablesW called with stmt: {}, catalogName: {}, catalogNameLength: "
"{}, "
"schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}, "
"tableType: {}, "
"tableTypeLength: {}",
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength, fmt::ptr(tableType),
tableTypeLength);
return SQL_ERROR;
}
31 changes: 31 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,37 @@ SQLRETURN SQLRowCount(SQLHSTMT stmt, SQLLEN* rowCountPtr) {
});
}

SQLRETURN SQLTables(SQLHSTMT stmt, SQLWCHAR* catalogName, SQLSMALLINT catalogNameLength,
SQLWCHAR* schemaName, SQLSMALLINT schemaNameLength,
SQLWCHAR* tableName, SQLSMALLINT tableNameLength, SQLWCHAR* tableType,
SQLSMALLINT tableTypeLength) {
LOG_DEBUG(
"SQLTables called with stmt: {}, catalogName: {}, catalogNameLength: "
"{}, "
"schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}, "
"tableType: {}, "
"tableTypeLength: {}",
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength, fmt::ptr(tableType),
tableTypeLength);
using ODBC::ODBCStatement;
using ODBC::SqlWcharToString;

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

std::string catalog = SqlWcharToString(catalogName, catalogNameLength);
std::string schema = SqlWcharToString(schemaName, schemaNameLength);
std::string table = SqlWcharToString(tableName, tableNameLength);
std::string type = SqlWcharToString(tableType, tableTypeLength);

statement->GetTables(catalogName ? &catalog : nullptr, schemaName ? &schema : nullptr,
tableName ? &table : nullptr, tableType ? &type : nullptr);

return SQL_SUCCESS;
});
}

SQLRETURN SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName, SQLSMALLINT catalogNameLength,
SQLWCHAR* schemaName, SQLSMALLINT schemaNameLength,
SQLWCHAR* tableName, SQLSMALLINT tableNameLength,
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ SQLRETURN SQLGetData(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType
SQLRETURN SQLMoreResults(SQLHSTMT stmt);
SQLRETURN SQLNumResultCols(SQLHSTMT stmt, SQLSMALLINT* columnCountPtr);
SQLRETURN SQLRowCount(SQLHSTMT stmt, SQLLEN* rowCountPtr);
SQLRETURN SQLTables(SQLHSTMT stmt, SQLWCHAR* catalogName, SQLSMALLINT catalogNameLength,
SQLWCHAR* schemaName, SQLSMALLINT schemaNameLength,
SQLWCHAR* tableName, SQLSMALLINT tableNameLength, SQLWCHAR* tableType,
SQLSMALLINT tableTypeLength);
SQLRETURN SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName, SQLSMALLINT catalogNameLength,
SQLWCHAR* schemaName, SQLSMALLINT schemaNameLength,
SQLWCHAR* tableName, SQLSMALLINT tableNameLength,
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 @@ -36,6 +36,7 @@ add_arrow_test(flight_sql_odbc_test
connection_info_test.cc
statement_attr_test.cc
statement_test.cc
tables_test.cc
# Connection test needs to be put last to resolve segfault issue
connection_test.cc
odbc_test_suite.cc
Expand Down
19 changes: 19 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 @@ -274,6 +274,19 @@ std::wstring FlightSQLODBCMockTestBase::getQueryAllDataTypes() {
return wsql;
}

void FlightSQLODBCMockTestBase::CreateTestTables() {
ASSERT_OK(server->ExecuteSql(R"(
CREATE TABLE TestTable (
id INTEGER PRIMARY KEY AUTOINCREMENT,
keyName varchar(100),
value int);

INSERT INTO TestTable (keyName, value) VALUES ('One', 1);
INSERT INTO TestTable (keyName, value) VALUES ('Two', 0);
INSERT INTO TestTable (keyName, value) VALUES ('Three', -1);
)"));
}

void FlightSQLODBCMockTestBase::CreateTableAllDataType() {
// Limitation on mock SQLite server:
// Only int64, float64, binary, and utf8 Arrow Types are supported by
Expand Down Expand Up @@ -454,4 +467,10 @@ void CheckSmallIntColumn(SQLHSTMT stmt, int colId, const SQLSMALLINT& expected)
EXPECT_EQ(buf, expected);
}

void ValidateFetch(SQLHSTMT stmt, SQLRETURN expectedReturn) {
SQLRETURN ret = SQLFetch(stmt);

EXPECT_EQ(ret, expectedReturn);
}

} // namespace arrow::flight::sql::odbc
8 changes: 8 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 @@ -125,6 +125,9 @@ class FlightSQLODBCMockTestBase : public FlightSQLODBCRemoteTestBase {
/// \brief Return a SQL query that selects all data types
std::wstring getQueryAllDataTypes() override;

Comment thread
rscales marked this conversation as resolved.
/// \brief Run a SQL query to create default table for table test cases
void CreateTestTables();

/// \brief run a SQL query to create a table with all data types
void CreateTableAllDataType();
/// \brief run a SQL query to create a table with unicode name
Expand Down Expand Up @@ -214,4 +217,9 @@ void CheckIntColumn(SQLHSTMT stmt, int colId, const SQLINTEGER& expected);
/// \param[in] colId Column ID to check.
/// \param[in] expected Expected value.
void CheckSmallIntColumn(SQLHSTMT stmt, int colId, const SQLSMALLINT& expected);

/// \brief Check sql return against expected.
/// \param[in] stmt Statement.
/// \param[in] expected Expected return.
void ValidateFetch(SQLHSTMT stmt, SQLRETURN expected);
} // namespace arrow::flight::sql::odbc
Loading
Loading