Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python ibm_db result set fetch Enhancement: #960

Open
Manojkumarbyibm opened this issue Aug 9, 2024 · 3 comments
Open

Python ibm_db result set fetch Enhancement: #960

Manojkumarbyibm opened this issue Aug 9, 2024 · 3 comments

Comments

@Manojkumarbyibm
Copy link

Manojkumarbyibm commented Aug 9, 2024

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.

  1. 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
Copy link
Contributor

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

@readytheory
Copy link

Hi @Manojkumarbyibm

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

@Manojkumarbyibm
Copy link
Author

Hi @readytheory

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

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

No branches or pull requests

3 participants