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