ibmdb / python-ibmdb

Automatically exported from code.google.com/p/ibm-db
Apache License 2.0
308 stars 192 forks source link

Python ibm_db result set fetch Enhancement: #960

Open Manojkumarbyibm opened 3 months ago

Manojkumarbyibm commented 3 months ago

Problem Statement:

While fetching data from executed query result . Currently ibm_db supports fetch_row, fetch_tuple, fetch_both, fetch_assoc.All these functions fetches one row at a time. It needs to be looped (while, for) to fetch more than one row, till end of result.Looping will decrease then performance of fetch and developer needs to code additional steps (i.e, looping) for achieving multiple row fetch .

fetch_row:

    row = ibm_db.fetch_row(result)
    while ( row ):
        row = ibm_db.fetch_row(result)

fetch_tuple:

    row = ibm_db.fetch_tuple(result)
    while ( row ):
        row = ibm_db.fetch_tuple(result)

fetch_both:

    row = ibm_db.fetch_both(result)
    while ( row ):
        row = ibm_db.fetch_both(result)

fetch_assoc:

    row = ibm_db.fetch_assoc(result)
    while ( row ):
        row = ibm_db.fetch_assoc(result)

Enhancement Request:

Python DB API (ibm_db_dbi) supports fetchall and fetchmany to retrieve rows from a database table. It provides greater flexiblity to end user on how many rows needs to be fetched at a time without need of looping. Since looping is eliminated, it will significantly increases fetch performance and developer can skip additional coding steps (i.e, looping) for achieving multiple row fetch .

1) fetchall():

fetches all the rows of a query result. It returns all the rows as a list of tuples. An empty list is returned if there is no record to fetch.

2) fetchmany(size):

returns the number of rows specified by size argument. When called repeatedly, this method fetches the next set of rows of a query result and returns a list of tuples.If no more rows are available, it returns an empty list.

Kindly please consider enhancing ibm_db to support fetchall and fetchmany functions, as it provides greater flexibility to end user.

bchoudhary6415 commented 3 months ago

Hello @Manojkumarbyibm Thank you for pointing it out. We will work on it and give support to the suggested APIs.

readytheory commented 3 months ago

Hi @Manojkumarbyibm

There is ibm-dbi that implements dbapi 2.0. The implementation is file ibm_db_dbi.py.

Manojkumarbyibm commented 2 months ago

Hi @readytheory

Having a similar feature in ibm_db , helps a lot and provides greater flexibility to end user.