-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Comments
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? |
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. |
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! |
sqlite3
docs #30660sqlite3
docs (GH-30660) #30661sqlite3
docs (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:
The text was updated successfully, but these errors were encountered: