Repository navigation
Enhance sqlite3 to avoid implicit creation? #90560
Description
Activity
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?
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Jan 16, 2022 - added3.11only security fixesonly security fixestype-featureA feature request or enhancementA feature request or enhancement
on Jan 16, 2022 I agree that would be a useful option.
FYI, you can already do this using the URI option:
cx = sqlite3.connect("file:test.db?mode=rw", uri=True)
See also bpo-24887.
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.
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.
@erlend: thanks for the URI tip, I missed that as a possibility in the SQLite docs.
I guess we could do more to promote that trick in the docs. It’s quite useful.
I created #74845 in order to try to enhance the docs. Ned and Eric, would you mind taking a look at the PR?
BTW, I'm fine with this being closed, since the functionality I wanted is available and documented.
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).
Closing this. Thanks, Ned and Eric!
sqlite3docs #30660sqlite3docs (GH-30660) #30661sqlite3docs (GH-30660) #30662Note: 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:
bugs.python.org fields: