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
14 changes: 5 additions & 9 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,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
28 changes: 26 additions & 2 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Was there a method that you need to run to notify that binding changes have occurred (I forget).

@alinaliBQ alinaliBQ Jul 16, 2025

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 think not. The driver sets m_hasBindingsChanged to true after setting SQL_DESC_COUNT(code), so this boolean would indicate that binding has changed. The driver also sets m_hasBindingsChanged to true as part of underlying SQLBindCol code. So no method would need to be run.

There is method ODBCDescriptor::NotifyBindingsHaveChanged (code) that does the same thing to set m_hasBindingsChanged to true, maybe this is the method that you were thinking of? This method is called as part of ODBCStatement::closeCursor

return SQL_SUCCESS;
});
}

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

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
2 changes: 2 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,8 @@ 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 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
Loading
Loading