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
13 changes: 3 additions & 10 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,9 @@ SQLRETURN SQL_API SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength, SQLWCHAR* columnName,
SQLSMALLINT columnNameLength) {
LOG_DEBUG(
"SQLColumnsW called with stmt: {}, catalogName: {}, catalogNameLength: "
"{}, "
"schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}, "
"columnName: {}, "
"columnNameLength: {}",
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength, fmt::ptr(columnName),
columnNameLength);
return SQL_ERROR;
return arrow::SQLColumns(stmt, catalogName, catalogNameLength, schemaName,
schemaNameLength, tableName, tableNameLength, columnName,
columnNameLength);
}

SQLRETURN SQL_API SQLError(SQLHENV handleType, SQLHDBC handle, SQLHSTMT hstmt,
Expand Down
35 changes: 35 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1112,4 +1112,39 @@ SQLRETURN SQLRowCount(SQLHSTMT stmt, SQLLEN* rowCountPtr) {
return SQL_SUCCESS;
});
}

SQLRETURN SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName, SQLSMALLINT catalogNameLength,
SQLWCHAR* schemaName, SQLSMALLINT schemaNameLength,
SQLWCHAR* tableName, SQLSMALLINT tableNameLength,
SQLWCHAR* columnName, SQLSMALLINT columnNameLength) {
// GH-47159: Return NUM_PREC_RADIX based on whether COLUMN_SIZE contains number of
// digits or bits
LOG_DEBUG(
"SQLColumnsW called with stmt: {}, catalogName: {}, catalogNameLength: "
"{}, "
"schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}, "
"columnName: {}, "
"columnNameLength: {}",
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength, fmt::ptr(columnName),
columnNameLength);

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 column = SqlWcharToString(columnName, columnNameLength);

statement->GetColumns(catalogName ? &catalog : nullptr,
schemaName ? &schema : nullptr, tableName ? &table : nullptr,
columnName ? &column : nullptr);

return SQL_SUCCESS;
});
}
} // namespace arrow
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,4 +79,8 @@ 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 SQLColumns(SQLHSTMT stmt, SQLWCHAR* catalogName, SQLSMALLINT catalogNameLength,
SQLWCHAR* schemaName, SQLSMALLINT schemaNameLength,
SQLWCHAR* tableName, SQLSMALLINT tableNameLength,
SQLWCHAR* columnName, SQLSMALLINT columnNameLength);
} // namespace arrow
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 @@ -31,6 +31,7 @@ set(ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS

add_arrow_test(flight_sql_odbc_test
SOURCES
columns_test.cc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQLColumns is one of the functions that behaves differently in ODBC 2.x vs. ODBC 3.x and up. The SQL type it returns for datetime types changes depending on whether you're using ODBC 2 or 3. For example SQL_TIME=11 vs. SQL_TYPE_TIME=91 (or something similar to this).

Also the column names differ in 2 vs. 3:
TABLE_QUALIFIER in 2 and TABLE_CAT in 3.

This is also the case for SQLTables.

Please add a test for ODBC 2.x

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the column names difference, we will add a test as part of SQLDescribeCol implementation in milestone 3. Yes the ODBC2 vs. 3 is pretty important, I remember the macOS Excel (which uses ODBC2) breaking and not getting database names because a driver I worked on before was returning TABLE_CAT as column name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look for a way to test time types with remote server

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the diff on odbc 2 and odbc 3:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the test for different data type return value for SQLColumns, and added todo comment for SQLDescribeCol tests

connection_attr_test.cc
connection_info_test.cc
statement_attr_test.cc
Expand Down
Loading
Loading