Add SQLFetchScroll support for fetchall() and fetchmany() - Fixes #1012#1059
Merged
bimalkjha merged 1 commit intoibmdb:masterfrom May 7, 2026
Merged
Conversation
…() APIs Signed-off-by: Balram Choudhary <bchoudhary@rocketsoftware.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added rowset-based fetching using
SQLFetchScroll(SQL_FETCH_NEXT)foribm_db.fetchall()andibm_db.fetchmany()APIs. This replaces the previous row-by-rowSQLFetch()approach, improving performance by fetching multiple rows per ODBC/CLI call using array-bound column buffers.Fixes #1012
What's New
APIs to support SQLFetchScroll
ibm_db.fetchall(stmt)— Fetches all remaining rows from the result set as a list of tuples.ibm_db.fetchmany(stmt, size)— Fetches up tosizerows from the result set as a list of tuples.Both APIs also work through the DBI layer:
cursor.fetchall()andcursor.fetchmany(size).SQL_ATTR_ROW_ARRAY_SIZE Support
A new statement attribute
SQL_ATTR_ROW_ARRAY_SIZEcontrols how many rows are fetched perSQLFetchScrollcall (i.e., the rowset size).10001ibm_db.set_option(stmt, {ibm_db.SQL_ATTR_ROW_ARRAY_SIZE: N}, 0)ibm_db.get_option(stmt, ibm_db.SQL_ATTR_ROW_ARRAY_SIZE, 0)How it works:
SQL_ATTR_ROW_ARRAY_SIZEtells the ODBC driver how many rows to fetch in a singleSQLFetchScrollcall.Nrows, then fetchesNrows at once into those buffers.Example:
ibmdb_tests.py Fix
Fixed ValueError: Empty module name that occurred when running test files with SINGLE_PYTHON_TEST environment variable set to blank/empty. The load_tests() function now filters out empty module names before attempting import:
tests = [ t for t in tests if t ] # Filter out any empty module names
Note: LOB Column Handling
When any column in the result set is a LOB type (BLOB, CLOB, DBCLOB, XML), the fetch automatically falls back to single-row SQLFetch() + SQLGetData(). This is because:
LOB columns cannot be array-bound with SQLBindCol()
SQLGetData() is required for LOB data retrieval and only works on the current row
This fallback is transparent to the user — fetchall() and fetchmany() return the same results regardless of whether the table contains LOB columns.