Skip to content

Honour SQL_ATTR_PARAM_OPERATION_PTR in parameter-array execution - #310

Open
fdcastel wants to merge 5 commits into
FirebirdSQL:masterfrom
fdcastel:fix/param-operation-ptr
Open

Honour SQL_ATTR_PARAM_OPERATION_PTR in parameter-array execution#310
fdcastel wants to merge 5 commits into
FirebirdSQL:masterfrom
fdcastel:fix/param-operation-ptr

Conversation

@fdcastel

@fdcastel fdcastel commented Sep 7, 2026

Copy link
Copy Markdown
Member

Builds on #308: its three commits show here until it merges. This PR is the last two commits.

The problem

SQL_ATTR_PARAM_OPERATION_PTR was accepted and stored (the APD's SQL_DESC_ARRAY_STATUS_PTR) but executeStatementParamArray never read it. A set marked SQL_PARAM_IGNORE was executed like any other: five sets with two ignored gave five rows, five SQL_PARAM_SUCCESS and a processed count of 5. An application that uses the operation array to skip rows had no way to know.

The fix

The loop skips a set whose operation element is SQL_PARAM_IGNORE, leaves its status at SQL_PARAM_UNUSED and does not count it. The status array is filled with SQL_PARAM_UNUSED before the loop and addressed by set number instead of through a moving pointer, and the processed count is kept per set instead of written once at the end, so after an error it holds the number of sets reached, including the failed one, as the specification describes.

Tests

ParamOperationPtrSkipRows (column-wise, sets 2 and 4 ignored) and RowWiseWithOperationPtr (row-wise, set 2 ignored) were already in the suite, skipped. Against the #308 driver both fail and the other 17 array cases pass. With this branch the array suite is 19 of 19 on Firebird 5, nothing skipped. Full suite, CHARSET=UTF8 and NONE: 390 ran, 237 passed, 153 skipped, 0 failed.

Probe (ctypes, Windows x64, Firebird 5.0.3, Microsoft driver manager), five column-wise sets with sets 2 and 4 ignored:

#308 this branch
rows stored 5 3
processed 5 3
status OK OK OK OK OK OK UNUSED OK UNUSED OK

Row-wise with one ignored set behaves the same way.

Still open

Eleven ArrayBindingTest cases were skipped citing a crash in the
column-wise indicator offset. That crash was fixed in 0a7cc1f (SQLINTEGER
to SQLLEN), so the skips come out. ParamOperationPtrSkipRows stays skipped
because SQL_ATTR_PARAM_OPERATION_PTR is still not honoured, and the
reactivated cases get the Firebird 6 guard the row-wise ones already have.

Two new cases bind fixed-length C types with BufferLength = 0, the usage
the ODBC specification describes for those types: one with the shape
reported in FirebirdSQL#299 (INTEGER and BIGINT with a NULL in the third parameter
set), one across DOUBLE, DATE and TIMESTAMP.
…h is 0

SQLBindParameter stores BufferLength as the element stride of a
column-wise parameter array. The ODBC specification ignores BufferLength
for fixed-length C types and applications pass 0 there, so every
parameter set read element 0: the driver inserted N rows carrying the
first set's values and reported SQL_SUCCESS.

bindInputOutputParam now falls back to the C type size when the stride is
0, the way bindOutputColumn already does for SQLBindCol. getConciseSize
gains SQL_C_GUID, for which it returned the type code (-11) and would have
produced a negative stride.

Character and binary C types keep BufferLength as their stride, so string
arrays behave as before.

Fixes FirebirdSQL#299
…fter SQLPrepare

The executor is chosen at prepare time from the paramset size in force at
that moment. An application that prepares first and sets
SQL_ATTR_PARAMSET_SIZE afterwards, which the specification allows and which
pyodbc's fast_executemany does, got a single execution of the first
parameter set, reported as success.

sqlExecute and sqlExecDirect now switch to executeStatementParamArray when
the paramset size is greater than 1 at execute time.
ParamOperationPtrSkipRows and RowWiseWithOperationPtr were skipped because
the driver does not honour the operation array. Both get the Firebird 6
guard the other array cases carry and run from here on.
The operation array was stored in the APD (SQL_DESC_ARRAY_STATUS_PTR) but
executeStatementParamArray never read it, so a set marked SQL_PARAM_IGNORE
was executed like any other and an application had no way to skip a row
short of rebuilding its arrays.

The loop now skips ignored sets, leaves their status at SQL_PARAM_UNUSED
and does not count them in SQL_ATTR_PARAMS_PROCESSED_PTR. The status array
is filled with SQL_PARAM_UNUSED before the loop, so sets that were never
reached read as unused, and status elements are addressed by set number
instead of through a moving pointer. The processed count is kept per set
instead of being written once after the loop, so it includes a failed set
as the specification describes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant