Transaction Processing: Retrieving Query Results. Read Part 1 here and Part 2 here.
By Roger Sanders
Editor's Note: This article is excerpted from chapter 6 of QuickStart Guide to Db2 Development with Python, by Roger Sanders.
When an SQL statement other than the SELECTstatement is executed, the only additional processing that might be performed is a check of the return code produced to verify the statement executed as expected. Or, a check to determine how many rows were affected by the operation. However, when a SELECTstatement (i.e., a query) is executed, any results that might have been produced will typically need to be retrieved and processed. With the ibm_db library, all the query results produced can be copied to a dictionary, tuple, or both (by calling the ibm_db.fetch_assoc(), ibm_db.fetch_tuple(), or ibm_db.fetch_both() API).Alternately,theibm_db.fetch_row()API can be used to advance the cursor to the next row (or move the cursor to a specific row) in a result set, and the ibm_db.result()API can be used to copy data from individual columns in that row to application variables.