Skip to content

Enhance sqlite3 to avoid implicit creation? #90560

Description

@nedbat
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']

    Activity

    1. nedbat commented on Jan 16, 2022

      @nedbat
      MemberAuthor

      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?

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jan 16, 2022
    3. added
      3.11only security fixes
      type-featureA feature request or enhancement
      on Jan 16, 2022
    4. ericvsmith commented on Jan 16, 2022

      @ericvsmith
      Member

      I agree that would be a useful option.

    5. erlend-aasland commented on Jan 17, 2022

      @erlend-aasland
      Contributor

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

          cx = sqlite3.connect("file:test.db?mode=rw", uri=True)
    6. erlend-aasland commented on Jan 17, 2022

      @erlend-aasland
      Contributor

      See also bpo-24887.

    7. erlend-aasland commented on Jan 17, 2022

      @erlend-aasland
      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.

    8. erlend-aasland commented on Jan 17, 2022

      @erlend-aasland
      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.

    9. nedbat commented on Jan 17, 2022

      @nedbat
      MemberAuthor

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

    10. erlend-aasland commented on Jan 17, 2022

      @erlend-aasland
      Contributor

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

    11. erlend-aasland commented on Jan 18, 2022

      @erlend-aasland
      Contributor

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

    12. ericvsmith commented on Jan 18, 2022

      @ericvsmith
      Member

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

    13. nedbat commented on Jan 18, 2022

      @nedbat
      MemberAuthor

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

    14. erlend-aasland commented on Jan 18, 2022

      @erlend-aasland
      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).

    15. ericvsmith commented on Jan 18, 2022

      @ericvsmith
      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

    16. ericvsmith commented on Jan 18, 2022

      @ericvsmith
      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

    17. erlend-aasland commented on Jan 18, 2022

      @erlend-aasland
      Contributor

      Closing this. Thanks, Ned and Eric!

    18. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-sqlite3type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions