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

prepared statements in sqlite3 module #57202

Closed
MayurAngelaPatel-Lam mannequin opened this issue Sep 16, 2011 · 4 comments
Closed

prepared statements in sqlite3 module #57202

MayurAngelaPatel-Lam mannequin opened this issue Sep 16, 2011 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@MayurAngelaPatel-Lam
Copy link
Mannequin

MayurAngelaPatel-Lam mannequin commented Sep 16, 2011

BPO 12993
Files
  • unnamed
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-03.21:06:19.366>
    created_at = <Date 2011-09-16.12:34:19.128>
    labels = ['type-feature', 'library']
    title = 'prepared statements in sqlite3 module'
    updated_at = <Date 2012-02-03.21:06:19.366>
    user = 'https://bugs.python.org/MayurAngelaPatel-Lam'

    bugs.python.org fields:

    activity = <Date 2012-02-03.21:06:19.366>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-03.21:06:19.366>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2011-09-16.12:34:19.128>
    creator = 'Mayur.&.Angela.Patel-Lam'
    dependencies = []
    files = ['23207']
    hgrepos = []
    issue_num = 12993
    keywords = []
    message_count = 4.0
    messages = ['144129', '144221', '144341', '152553']
    nosy_count = 3.0
    nosy_names = ['ghaering', 'poq', 'Mayur.&.Angela.Patel-Lam']
    pr_nums = []
    priority = 'normal'
    resolution = 'works for me'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12993'
    versions = []

    @MayurAngelaPatel-Lam
    Copy link
    Mannequin Author

    MayurAngelaPatel-Lam mannequin commented Sep 16, 2011

    The sqlite3 module is wonderful, but the one advantage that C/C++ coders have using that system is the ability to use precompiled/prepared SQL statements. Some SQL databases like Postgresql allow you to precompile statements using special SQL statements (e.g. PREPARE), so there is no need to change the python DBI for those database systems. But unfortunately, sqlite3 only offers a C/C++ function, which returns a handle to the prepared statement. I have sought a way to call this from the python DBI, but I simply don't think it's exposed.

    Since my application interleaves several SQL commands, depending on the results of the last iteration, I can't immediately use executemany() to obtain maximum performance on my code. Precompiled statements offer me the best opportunity to optimize. I can prepare the 2 or 3 most expensive queries in my loop and call them in whatever order I need. There are some estimates that prepared statements can accelerate complex queries by an order of magnitude, as the parser and optimizers don't need to come into play for every call.

    Would you consider an extension to the sqlite3 DBI to expose prepared statements? Thanks.

    @MayurAngelaPatel-Lam MayurAngelaPatel-Lam mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 16, 2011
    @poq
    Copy link
    Mannequin

    poq mannequin commented Sep 17, 2011

    The sqlite3 module already uses prepared statements. Quoting from the documentation:

    "The sqlite3 module internally uses a statement cache to avoid SQL parsing overhead. If you want to explicitly set the number of statements that are cached for the connection, you can set the cached_statements parameter. The currently implemented default is to cache 100 statements."

    @MayurAngelaPatel-Lam
    Copy link
    Mannequin Author

    MayurAngelaPatel-Lam mannequin commented Sep 20, 2011

    Okay, I missed that in the documentation. I was looking for a handle to a
    prepared statement. I suppose it's hashing on the text of the SQL statement
    to determine equivalence?

    I'm willing to retract the request. I need to restructure my code a little
    bit to take advantage of this feature.

    On Sat, Sep 17, 2011 at 5:47 PM, poq <report@bugs.python.org> wrote:

    poq <poq@gmx.com> added the comment:

    The sqlite3 module already uses prepared statements. Quoting from the
    documentation:

    "The sqlite3 module internally uses a statement cache to avoid SQL parsing
    overhead. If you want to explicitly set the number of statements that are
    cached for the connection, you can set the cached_statements parameter. The
    currently implemented default is to cache 100 statements."

    ----------
    nosy: +poq


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue12993\>


    @poq
    Copy link
    Mannequin

    poq mannequin commented Feb 3, 2012

    This can be closed.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant