@@ -132,142 +132,18 @@ You've now created an SQLite database using the :mod:`!sqlite3` module.
132
132
Reference
133
133
---------
134
134
135
+ .. We keep the old sqlite3-module-contents ref to prevent breaking links.
135
136
.. _sqlite3-module-contents :
136
137
137
- Module functions and constants
138
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138
+ .. _sqlite3-module-functions :
139
139
140
+ Module functions
141
+ ^^^^^^^^^^^^^^^^
140
142
141
- .. data :: apilevel
142
-
143
- String constant stating the supported DB-API level. Required by the DB-API.
144
- Hard-coded to ``"2.0" ``.
145
-
146
- .. data :: paramstyle
147
-
148
- String constant stating the type of parameter marker formatting expected by
149
- the :mod: `!sqlite3 ` module. Required by the DB-API. Hard-coded to
150
- ``"qmark" ``.
151
-
152
- .. note ::
153
-
154
- The :mod: `!sqlite3 ` module supports both ``qmark `` and ``numeric `` DB-API
155
- parameter styles, because that is what the underlying SQLite library
156
- supports. However, the DB-API does not allow multiple values for
157
- the ``paramstyle `` attribute.
158
-
159
- .. data :: version
160
-
161
- Version number of this module as a :class: `string <str> `.
162
- This is not the version of the SQLite library.
163
-
164
- .. deprecated-removed :: 3.12 3.14
165
- This constant used to reflect the version number of the ``pysqlite ``
166
- package, a third-party library which used to upstream changes to
167
- :mod: `!sqlite3 `. Today, it carries no meaning or practical value.
168
-
169
-
170
- .. data :: version_info
171
-
172
- Version number of this module as a :class: `tuple ` of :class: `integers <int> `.
173
- This is not the version of the SQLite library.
174
-
175
- .. deprecated-removed :: 3.12 3.14
176
- This constant used to reflect the version number of the ``pysqlite ``
177
- package, a third-party library which used to upstream changes to
178
- :mod: `!sqlite3 `. Today, it carries no meaning or practical value.
179
-
180
-
181
- .. data :: sqlite_version
182
-
183
- Version number of the runtime SQLite library as a :class: `string <str> `.
184
-
185
-
186
- .. data :: sqlite_version_info
187
-
188
- Version number of the runtime SQLite library as a :class: `tuple ` of
189
- :class: `integers <int> `.
190
-
191
-
192
- .. data :: threadsafety
193
-
194
- Integer constant required by the DB-API 2.0, stating the level of thread
195
- safety the :mod: `!sqlite3 ` module supports. This attribute is set based on
196
- the default `threading mode <https://sqlite.org/threadsafe.html >`_ the
197
- underlying SQLite library is compiled with. The SQLite threading modes are:
198
-
199
- 1. **Single-thread **: In this mode, all mutexes are disabled and SQLite is
200
- unsafe to use in more than a single thread at once.
201
- 2. **Multi-thread **: In this mode, SQLite can be safely used by multiple
202
- threads provided that no single database connection is used
203
- simultaneously in two or more threads.
204
- 3. **Serialized **: In serialized mode, SQLite can be safely used by
205
- multiple threads with no restriction.
206
-
207
- The mappings from SQLite threading modes to DB-API 2.0 threadsafety levels
208
- are as follows:
209
-
210
- +------------------+-----------------+----------------------+-------------------------------+
211
- | SQLite threading | `threadsafety `_ | `SQLITE_THREADSAFE `_ | DB-API 2.0 meaning |
212
- | mode | | | |
213
- +==================+=================+======================+===============================+
214
- | single-thread | 0 | 0 | Threads may not share the |
215
- | | | | module |
216
- +------------------+-----------------+----------------------+-------------------------------+
217
- | multi-thread | 1 | 2 | Threads may share the module, |
218
- | | | | but not connections |
219
- +------------------+-----------------+----------------------+-------------------------------+
220
- | serialized | 3 | 1 | Threads may share the module, |
221
- | | | | connections and cursors |
222
- +------------------+-----------------+----------------------+-------------------------------+
223
-
224
- .. _threadsafety : https://peps.python.org/pep-0249/#threadsafety
225
- .. _SQLITE_THREADSAFE : https://sqlite.org/compile.html#threadsafe
226
-
227
- .. versionchanged :: 3.11
228
- Set *threadsafety * dynamically instead of hard-coding it to ``1 ``.
229
-
230
- .. data :: PARSE_DECLTYPES
231
-
232
- Pass this flag value to the *detect_types * parameter of
233
- :func: `connect ` to look up a converter function using
234
- the declared types for each column.
235
- The types are declared when the database table is created.
236
- :mod: `!sqlite3 ` will look up a converter function using the first word of the
237
- declared type as the converter dictionary key.
238
- For example:
239
-
240
-
241
- .. code-block :: sql
242
-
243
- CREATE TABLE test(
244
- i integer primary key, ! will look up a converter named "integer"
245
- p point, ! will look up a converter named "point"
246
- n number(10) ! will look up a converter named "number"
247
- )
248
-
249
- This flag may be combined with :const: `PARSE_COLNAMES ` using the ``| ``
250
- (bitwise or) operator.
251
-
252
-
253
- .. data :: PARSE_COLNAMES
254
-
255
- Pass this flag value to the *detect_types * parameter of
256
- :func: `connect ` to look up a converter function by
257
- using the type name, parsed from the query column name,
258
- as the converter dictionary key.
259
- The type name must be wrapped in square brackets (``[] ``).
260
-
261
- .. code-block :: sql
262
-
263
- SELECT p as "p [point]" FROM test; ! will look up converter "point"
264
-
265
- This flag may be combined with :const: `PARSE_DECLTYPES ` using the ``| ``
266
- (bitwise or) operator.
267
-
268
-
269
-
270
- .. function :: connect(database, timeout=5.0, detect_types=0, isolation_level="DEFERRED", check_same_thread=True, factory=sqlite3.Connection, cached_statements=128, uri=False)
143
+ .. function :: connect(database, timeout=5.0, detect_types=0, \
144
+ isolation_level="DEFERRED", check_same_thread=True, \
145
+ factory=sqlite3.Connection, cached_statements=128, \
146
+ uri=False)
271
147
272
148
Open a connection to an SQLite database.
273
149
@@ -344,30 +220,6 @@ Module functions and constants
344
220
.. versionadded :: 3.10
345
221
The ``sqlite3.connect/handle `` auditing event.
346
222
347
-
348
- .. function :: register_converter(typename, converter, /)
349
-
350
- Register the *converter * callable to convert SQLite objects of type
351
- *typename * into a Python object of a specific type.
352
- The converter is invoked for all SQLite values of type *typename *;
353
- it is passed a :class: `bytes ` object and should return an object of the
354
- desired Python type.
355
- Consult the parameter *detect_types * of
356
- :func: `connect ` for information regarding how type detection works.
357
-
358
- Note: *typename * and the name of the type in your query are matched
359
- case-insensitively.
360
-
361
-
362
- .. function :: register_adapter(type, adapter, /)
363
-
364
- Register an *adapter * callable to adapt the Python type *type * into an
365
- SQLite type.
366
- The adapter is called with a Python object of type *type * as its sole
367
- argument, and must return a value of a
368
- :ref: `type that SQLite natively understands <sqlite3-types >`.
369
-
370
-
371
223
.. function :: complete_statement(statement)
372
224
373
225
Returns ``True `` if the string *statement * contains one or more complete SQL
@@ -377,10 +229,8 @@ Module functions and constants
377
229
378
230
This can be used to build a shell for SQLite, as in the following example:
379
231
380
-
381
232
.. literalinclude :: ../includes/sqlite3/complete_statement.py
382
233
383
-
384
234
.. function :: enable_callback_tracebacks(flag, /)
385
235
386
236
Enable or disable callback tracebacks.
@@ -408,6 +258,154 @@ Module functions and constants
408
258
UnraisableHookArgs(exc_type=<class 'ZeroDivisionError'>, exc_value=ZeroDivisionError('division by zero'), exc_traceback=<traceback object at 0x10b559900>, err_msg=None, object=<function <lambda> at 0x10b4e3ee0>)
409
259
<sqlite3.Cursor object at 0x10b1fe840>
410
260
261
+ .. function :: register_adapter(type, adapter, /)
262
+
263
+ Register an *adapter * callable to adapt the Python type *type * into an
264
+ SQLite type.
265
+ The adapter is called with a Python object of type *type * as its sole
266
+ argument, and must return a value of a
267
+ :ref: `type that SQLite natively understands <sqlite3-types >`.
268
+
269
+ .. function :: register_converter(typename, converter, /)
270
+
271
+ Register the *converter * callable to convert SQLite objects of type
272
+ *typename * into a Python object of a specific type.
273
+ The converter is invoked for all SQLite values of type *typename *;
274
+ it is passed a :class: `bytes ` object and should return an object of the
275
+ desired Python type.
276
+ Consult the parameter *detect_types * of
277
+ :func: `connect ` for information regarding how type detection works.
278
+
279
+ Note: *typename * and the name of the type in your query are matched
280
+ case-insensitively.
281
+
282
+
283
+ .. _sqlite3-module-constants :
284
+
285
+ Module constants
286
+ ^^^^^^^^^^^^^^^^
287
+
288
+ .. data :: PARSE_COLNAMES
289
+
290
+ Pass this flag value to the *detect_types * parameter of
291
+ :func: `connect ` to look up a converter function by
292
+ using the type name, parsed from the query column name,
293
+ as the converter dictionary key.
294
+ The type name must be wrapped in square brackets (``[] ``).
295
+
296
+ .. code-block :: sql
297
+
298
+ SELECT p as "p [point]" FROM test; ! will look up converter "point"
299
+
300
+ This flag may be combined with :const: `PARSE_DECLTYPES ` using the ``| ``
301
+ (bitwise or) operator.
302
+
303
+ .. data :: PARSE_DECLTYPES
304
+
305
+ Pass this flag value to the *detect_types * parameter of
306
+ :func: `connect ` to look up a converter function using
307
+ the declared types for each column.
308
+ The types are declared when the database table is created.
309
+ :mod: `!sqlite3 ` will look up a converter function using the first word of the
310
+ declared type as the converter dictionary key.
311
+ For example:
312
+
313
+ .. code-block :: sql
314
+
315
+ CREATE TABLE test(
316
+ i integer primary key, ! will look up a converter named "integer"
317
+ p point, ! will look up a converter named "point"
318
+ n number(10) ! will look up a converter named "number"
319
+ )
320
+
321
+ This flag may be combined with :const: `PARSE_COLNAMES ` using the ``| ``
322
+ (bitwise or) operator.
323
+
324
+ .. data :: apilevel
325
+
326
+ String constant stating the supported DB-API level. Required by the DB-API.
327
+ Hard-coded to ``"2.0" ``.
328
+
329
+ .. data :: paramstyle
330
+
331
+ String constant stating the type of parameter marker formatting expected by
332
+ the :mod: `!sqlite3 ` module. Required by the DB-API. Hard-coded to
333
+ ``"qmark" ``.
334
+
335
+ .. note ::
336
+
337
+ The :mod: `!sqlite3 ` module supports both ``qmark `` and ``numeric `` DB-API
338
+ parameter styles, because that is what the underlying SQLite library
339
+ supports. However, the DB-API does not allow multiple values for
340
+ the ``paramstyle `` attribute.
341
+
342
+ .. data :: sqlite_version
343
+
344
+ Version number of the runtime SQLite library as a :class: `string <str> `.
345
+
346
+ .. data :: sqlite_version_info
347
+
348
+ Version number of the runtime SQLite library as a :class: `tuple ` of
349
+ :class: `integers <int> `.
350
+
351
+ .. data :: threadsafety
352
+
353
+ Integer constant required by the DB-API 2.0, stating the level of thread
354
+ safety the :mod: `!sqlite3 ` module supports. This attribute is set based on
355
+ the default `threading mode <https://sqlite.org/threadsafe.html >`_ the
356
+ underlying SQLite library is compiled with. The SQLite threading modes are:
357
+
358
+ 1. **Single-thread **: In this mode, all mutexes are disabled and SQLite is
359
+ unsafe to use in more than a single thread at once.
360
+ 2. **Multi-thread **: In this mode, SQLite can be safely used by multiple
361
+ threads provided that no single database connection is used
362
+ simultaneously in two or more threads.
363
+ 3. **Serialized **: In serialized mode, SQLite can be safely used by
364
+ multiple threads with no restriction.
365
+
366
+ The mappings from SQLite threading modes to DB-API 2.0 threadsafety levels
367
+ are as follows:
368
+
369
+ +------------------+-----------------+----------------------+-------------------------------+
370
+ | SQLite threading | `threadsafety `_ | `SQLITE_THREADSAFE `_ | DB-API 2.0 meaning |
371
+ | mode | | | |
372
+ +==================+=================+======================+===============================+
373
+ | single-thread | 0 | 0 | Threads may not share the |
374
+ | | | | module |
375
+ +------------------+-----------------+----------------------+-------------------------------+
376
+ | multi-thread | 1 | 2 | Threads may share the module, |
377
+ | | | | but not connections |
378
+ +------------------+-----------------+----------------------+-------------------------------+
379
+ | serialized | 3 | 1 | Threads may share the module, |
380
+ | | | | connections and cursors |
381
+ +------------------+-----------------+----------------------+-------------------------------+
382
+
383
+ .. _threadsafety : https://peps.python.org/pep-0249/#threadsafety
384
+ .. _SQLITE_THREADSAFE : https://sqlite.org/compile.html#threadsafe
385
+
386
+ .. versionchanged :: 3.11
387
+ Set *threadsafety * dynamically instead of hard-coding it to ``1 ``.
388
+
389
+ .. data :: version
390
+
391
+ Version number of this module as a :class: `string <str> `.
392
+ This is not the version of the SQLite library.
393
+
394
+ .. deprecated-removed :: 3.12 3.14
395
+ This constant used to reflect the version number of the ``pysqlite ``
396
+ package, a third-party library which used to upstream changes to
397
+ :mod: `!sqlite3 `. Today, it carries no meaning or practical value.
398
+
399
+ .. data :: version_info
400
+
401
+ Version number of this module as a :class: `tuple ` of :class: `integers <int> `.
402
+ This is not the version of the SQLite library.
403
+
404
+ .. deprecated-removed :: 3.12 3.14
405
+ This constant used to reflect the version number of the ``pysqlite ``
406
+ package, a third-party library which used to upstream changes to
407
+ :mod: `!sqlite3 `. Today, it carries no meaning or practical value.
408
+
411
409
412
410
.. _sqlite3-connection-objects :
413
411
0 commit comments