Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
19 changes: 10 additions & 9 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ SQLRETURN SQL_API SQLExecDirect(SQLHSTMT stmt, SQLWCHAR* queryText,

SQLRETURN SQL_API SQLFetch(SQLHSTMT stmt) { return arrow::SQLFetch(stmt); }

SQLRETURN SQL_API SQLFetchScroll(SQLHSTMT stmt, SQLSMALLINT fetchOrientation,
SQLLEN fetchOffset) {
return arrow::SQLFetchScroll(stmt, fetchOrientation, fetchOffset);
}

SQLRETURN SQL_API SQLGetData(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType,
SQLPOINTER dataPtr, SQLLEN bufferLength,
SQLLEN* indicatorPtr) {
Expand All @@ -150,15 +155,11 @@ SQLRETURN SQL_API SQLPrepare(SQLHSTMT stmt, SQLWCHAR* queryText, SQLINTEGER text

SQLRETURN SQL_API SQLExecute(SQLHSTMT stmt) { return arrow::SQLExecute(stmt); }

SQLRETURN SQL_API SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT columnNumber,
SQLSMALLINT targetType, SQLPOINTER targetValuePtr,
SQLLEN bufferLength, SQLLEN* strLen_or_IndPtr) {
LOG_DEBUG(
"SQLBindCol called with stmt: {}, columnNumber: {}, targetType: {}, "
"targetValuePtr: {}, bufferLength: {}, strLen_or_IndPtr: {}",
stmt, columnNumber, targetType, targetValuePtr, bufferLength,
fmt::ptr(strLen_or_IndPtr));
return SQL_ERROR;
SQLRETURN SQL_API SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType,
SQLPOINTER dataPtr, SQLLEN bufferLength,
SQLLEN* indicatorPtr) {
return arrow::SQLBindCol(stmt, recordNumber, cType, dataPtr, bufferLength,
indicatorPtr);
}

SQLRETURN SQL_API SQLCancel(SQLHSTMT stmt) {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc.def
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ EXPORTS
SQLExecDirectW
SQLExecute
SQLFetch
SQLFetchScroll
SQLForeignKeysW
SQLFreeEnv
SQLFreeConnect
Expand Down
57 changes: 54 additions & 3 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,16 @@ SQLRETURN SQLFreeStmt(SQLHSTMT handle, SQLUSMALLINT option) {
return SQLFreeHandle(SQL_HANDLE_STMT, handle);
}

// TODO Implement SQLBindCol
case SQL_UNBIND: {
return SQL_SUCCESS;
using ODBC::ODBCDescriptor;
using ODBC::ODBCStatement;
return ODBCStatement::ExecuteWithDiagnostics(handle, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(handle);
ODBCDescriptor* ard = statement->GetARD();
// Unbind columns
ard->SetHeaderField(SQL_DESC_COUNT, (void*)0, 0);
return SQL_SUCCESS;
});
}

// SQLBindParameter is not supported
Expand Down Expand Up @@ -976,6 +983,50 @@ SQLRETURN SQLFetch(SQLHSTMT stmt) {
});
}

SQLRETURN SQLFetchScroll(SQLHSTMT stmt, SQLSMALLINT fetchOrientation,
SQLLEN fetchOffset) {
LOG_DEBUG("SQLFetchScroll called with stmt: {}, fetchOrientation: {}, fetchOffset: {}",
stmt, fetchOrientation, fetchOffset);
using ODBC::ODBCDescriptor;
using ODBC::ODBCStatement;
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
if (fetchOrientation != SQL_FETCH_NEXT) {
throw DriverException("Optional feature not supported.", "HYC00");
}
// fetchOffset is ignored as only SQL_FETCH_NEXT is supported

ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);

// The SQL_ATTR_ROW_ARRAY_SIZE statement attribute specifies the number of rows in the
// rowset.
ODBCDescriptor* ard = statement->GetARD();
size_t rows = static_cast<size_t>(ard->GetArraySize());
if (statement->Fetch(rows)) {
return SQL_SUCCESS;
} else {
// Reached the end of rowset
return SQL_NO_DATA;
}
});
}

SQLRETURN SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType,
SQLPOINTER dataPtr, SQLLEN bufferLength, SQLLEN* indicatorPtr) {
LOG_DEBUG(
"SQLBindCol called with stmt: {}, recordNumber: {}, cType: {}, "
"dataPtr: {}, bufferLength: {}, strLen_or_IndPtr: {}",
stmt, recordNumber, cType, dataPtr, bufferLength, fmt::ptr(indicatorPtr));
using ODBC::ODBCDescriptor;
using ODBC::ODBCStatement;
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
// GH-47021: implement driver to return indicator value when data pointer is null
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);
ODBCDescriptor* ard = statement->GetARD();
ard->BindCol(recordNumber, cType, dataPtr, bufferLength, indicatorPtr);
return SQL_SUCCESS;
});
}

SQLRETURN SQLGetData(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType,
SQLPOINTER dataPtr, SQLLEN bufferLength, SQLLEN* indicatorPtr) {
// GH-46979: support SQL_C_GUID data type
Expand Down Expand Up @@ -1017,7 +1068,7 @@ SQLRETURN SQLNumResultCols(SQLHSTMT stmt, SQLSMALLINT* columnCountPtr) {
});
}

SQLRETURN SQL_API SQLRowCount(SQLHSTMT stmt, SQLLEN* rowCountPtr) {
SQLRETURN SQLRowCount(SQLHSTMT stmt, SQLLEN* rowCountPtr) {
LOG_DEBUG("SQLRowCount called with stmt: {}, columnCountPtr: {}", stmt,
fmt::ptr(rowCountPtr));
// TODO: write tests for SQLRowCount
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ SQLRETURN SQLExecDirect(SQLHSTMT stmt, SQLWCHAR* queryText, SQLINTEGER textLengt
SQLRETURN SQLPrepare(SQLHSTMT stmt, SQLWCHAR* queryText, SQLINTEGER textLength);
SQLRETURN SQLExecute(SQLHSTMT stmt);
SQLRETURN SQLFetch(SQLHSTMT stmt);
SQLRETURN SQLFetchScroll(SQLHSTMT stmt, SQLSMALLINT fetchOrientation, SQLLEN fetchOffset);
SQLRETURN SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType,
SQLPOINTER dataPtr, SQLLEN bufferLength, SQLLEN* indicatorPtr);
SQLRETURN SQLGetData(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLINT cType,
SQLPOINTER dataPtr, SQLLEN bufferLength, SQLLEN* indicatorPtr);
SQLRETURN SQLMoreResults(SQLHSTMT stmt);
Expand Down
1 change: 1 addition & 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 @@ -167,6 +167,7 @@ static constexpr std::string_view error_state_HY010 = "HY010";
static constexpr std::string_view error_state_HY024 = "HY024";
static constexpr std::string_view error_state_HY092 = "HY092";
static constexpr std::string_view error_state_HYC00 = "HYC00";
static constexpr std::string_view error_state_HY106 = "HY106";
static constexpr std::string_view error_state_HY114 = "HY114";
static constexpr std::string_view error_state_HY017 = "HY017";
static constexpr std::string_view error_state_HY118 = "HY118";
Expand Down
Loading