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

Enhance sqlite3 to avoid implicit creation? #90560

Closed
nedbat opened this issue Jan 16, 2022 · 15 comments
Closed

Enhance sqlite3 to avoid implicit creation? #90560

nedbat opened this issue Jan 16, 2022 · 15 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir topic-sqlite3 type-feature A feature request or enhancement

Comments

@nedbat
Copy link
Member

nedbat commented Jan 16, 2022

BPO 46402
Nosy @ericvsmith, @nedbat, @zware, @miss-islington, @erlend-aasland
PRs
  • bpo-46402: Promote SQLite URI tricks in sqlite3 docs #30660
  • [3.10] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) #30661
  • [3.9] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) #30662
  • [3.10] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) #30671
  • [3.9] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) #30672
  • 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 2022-01-18.22:15:01.743>
    created_at = <Date 2022-01-16.17:42:31.926>
    labels = ['type-feature', 'library', '3.11']
    title = 'Enhance sqlite3 to avoid implicit creation?'
    updated_at = <Date 2022-01-18.22:15:01.742>
    user = 'https://github.com/nedbat'

    bugs.python.org fields:

    activity = <Date 2022-01-18.22:15:01.742>
    actor = 'erlendaasland'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-18.22:15:01.743>
    closer = 'erlendaasland'
    components = ['Library (Lib)']
    creation = <Date 2022-01-16.17:42:31.926>
    creator = 'nedbat'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46402
    keywords = ['patch']
    message_count = 15.0
    messages = ['410704', '410724', '410779', '410780', '410781', '410783', '410790', '410793', '410851', '410857', '410892', '410895', '410902', '410903', '410906']
    nosy_count = 5.0
    nosy_names = ['eric.smith', 'nedbat', 'zach.ware', 'miss-islington', 'erlendaasland']
    pr_nums = ['30660', '30661', '30662', '30671', '30672']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue46402'
    versions = ['Python 3.11']

    @nedbat
    Copy link
    Member Author

    nedbat commented Jan 16, 2022

    The sqlite3 library implicitly creates the database if the requested file doesn't exist. I would like to be able to avoid that implicit creation. (Actually, it would be enough to know whether I had created the database, but the underlying SQLite library doesn't seem to indicate that.)

    The C code currently hard-codes the SQLite flag to create the database if it doesn't exist:

        rc = sqlite3_open_v2(database, &db,
                             SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
                             (uri ? SQLITE_OPEN_URI : 0), NULL);

    Could we make this an option, so the Python code could avoid implicit creation?

    @nedbat nedbat added stdlib Python modules in the Lib dir labels Jan 16, 2022
    @zware zware added 3.11 only security fixes type-feature A feature request or enhancement labels Jan 16, 2022
    @ericvsmith
    Copy link
    Member

    I agree that would be a useful option.

    @erlend-aasland
    Copy link
    Contributor

    FYI, you can already do this using the URI option:

        cx = sqlite3.connect("file:test.db?mode=rw", uri=True)

    @erlend-aasland
    Copy link
    Contributor

    See also bpo-24887.

    @erlend-aasland
    Copy link
    Contributor

    IMO, the URI "API" is not very pythonic; I have to look up the format every time I'm using it.

    OTOH, introducing flags, or keywords, for every option will add a lot of code.

    @erlend-aasland
    Copy link
    Contributor

    OTOH, implementing an API similar to apsw (adding a flags keyword) would make it easier for users to switch between that and the stdlib sqlite3.

    @nedbat
    Copy link
    Member Author

    nedbat commented Jan 17, 2022

    @erlend: thanks for the URI tip, I missed that as a possibility in the SQLite docs.

    @erlend-aasland
    Copy link
    Contributor

    I guess we could do more to promote that trick in the docs. It’s quite useful.

    @erlend-aasland
    Copy link
    Contributor

    I created #74845 in order to try to enhance the docs. Ned and Eric, would you mind taking a look at the PR?

    @ericvsmith
    Copy link
    Member

    New changeset bdf2ab1 by Erlend Egeberg Aasland in branch 'main':
    bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660)
    bdf2ab1

    @nedbat
    Copy link
    Member Author

    nedbat commented Jan 18, 2022

    BTW, I'm fine with this being closed, since the functionality I wanted is available and documented.

    @erlend-aasland
    Copy link
    Contributor

    BTW, I'm fine with this being closed, since the functionality I wanted is available and documented.

    Great. I was considering closing it as soon as the backports have landed (I had to manually fix them bco. make suspicious failures).

    @ericvsmith
    Copy link
    Member

    New changeset 01e6cbe by Erlend Egeberg Aasland in branch '3.10':
    [3.10] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) (GH-30671)
    01e6cbe

    @ericvsmith
    Copy link
    Member

    New changeset 0ae2257 by Erlend Egeberg Aasland in branch '3.9':
    [3.9] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) (bpo-30672)
    0ae2257

    @erlend-aasland
    Copy link
    Contributor

    Closing this. Thanks, Ned and Eric!

    @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
    3.11 only security fixes stdlib Python modules in the Lib dir topic-sqlite3 type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants