[3.10] bpo-46402: Promote SQLite URI tricks in sqlite3 docs (GH-30660) (GH-30671)

* bpo-46402: Promote SQLite URI tricks in `sqlite3` docs (GH-30660)

Provide some examples of URI parameters in sqlite connect().

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
(cherry picked from commit bdf2ab1887)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>

* Update suspicious rules
This commit is contained in:
Erlend Egeberg Aasland 2022-01-18 22:57:33 +01:00 committed by GitHub
parent 4449a1694a
commit 01e6cbefd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View file

@ -255,14 +255,28 @@ Module functions and constants
for the connection, you can set the *cached_statements* parameter. The currently
implemented default is to cache 100 statements.
If *uri* is true, *database* is interpreted as a URI. This allows you
to specify options. For example, to open a database in read-only mode
you can use::
If *uri* is :const:`True`, *database* is interpreted as a
:abbr:`URI (Uniform Resource Identifier)` with a file path and an optional
query string. The scheme part *must* be ``"file:"``. The path can be a
relative or absolute file path. The query string allows us to pass
parameters to SQLite. Some useful URI tricks include::
db = sqlite3.connect('file:path/to/database?mode=ro', uri=True)
# Open a database in read-only mode.
con = sqlite3.connect("file:template.db?mode=ro", uri=True)
More information about this feature, including a list of recognized options, can
be found in the `SQLite URI documentation <https://www.sqlite.org/uri.html>`_.
# Don't implicitly create a new database file if it does not already exist.
# Will raise sqlite3.OperationalError if unable to open a database file.
con = sqlite3.connect("file:nosuchdb.db?mode=rw", uri=True)
# Create a shared named in-memory database.
con1 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
con2 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
con1.executescript("create table t(t); insert into t values(28);")
rows = con2.execute("select * from t").fetchall()
More information about this feature, including a list of recognized
parameters, can be found in the
`SQLite URI documentation <https://www.sqlite.org/uri.html>`_.
.. audit-event:: sqlite3.connect database sqlite3.connect
.. audit-event:: sqlite3.connect/handle connection_handle sqlite3.connect

View file

@ -212,7 +212,10 @@ library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])"
library/socket,,:len,fds.frombytes(cmsg_data[:len(cmsg_data) - (len(cmsg_data) % fds.itemsize)])
library/sqlite3,,:year,"cur.execute(""select * from lang where first_appeared=:year"", {""year"": 1972})"
library/sqlite3,,:memory,
library/sqlite3,,:path,"db = sqlite3.connect('file:path/to/database?mode=ro', uri=True)"
library/sqlite3,,:template,"con = sqlite3.connect(""file:template.db?mode=ro"", uri=True)"
library/sqlite3,,:nosuchdb,"con = sqlite3.connect(""file:nosuchdb.db?mode=rw"", uri=True)"
library/sqlite3,,:mem1,"con1 = sqlite3.connect(""file:mem1?mode=memory&cache=shared"", uri=True)"
library/sqlite3,,:mem1,"con2 = sqlite3.connect(""file:mem1?mode=memory&cache=shared"", uri=True)"
library/ssl,,:My,"Organizational Unit Name (eg, section) []:My Group"
library/ssl,,:My,"Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc."
library/ssl,,:myserver,"Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com"

1 c-api/arg :ref PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
212 library/socket :len fds.frombytes(cmsg_data[:len(cmsg_data) - (len(cmsg_data) % fds.itemsize)])
213 library/sqlite3 :year cur.execute("select * from lang where first_appeared=:year", {"year": 1972})
214 library/sqlite3 :memory
215 library/sqlite3 :path :template db = sqlite3.connect('file:path/to/database?mode=ro', uri=True) con = sqlite3.connect("file:template.db?mode=ro", uri=True)
216 library/sqlite3 :nosuchdb con = sqlite3.connect("file:nosuchdb.db?mode=rw", uri=True)
217 library/sqlite3 :mem1 con1 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
218 library/sqlite3 :mem1 con2 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
219 library/ssl :My Organizational Unit Name (eg, section) []:My Group
220 library/ssl :My Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc.
221 library/ssl :myserver Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com