@@ -132,114 +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
-
165
- .. data :: version_info
166
-
167
- Version number of this module as a :class: `tuple ` of :class: `integers <int> `.
168
- This is not the version of the SQLite library.
169
-
170
-
171
- .. data :: sqlite_version
172
-
173
- Version number of the runtime SQLite library as a :class: `string <str> `.
174
-
175
-
176
- .. data :: sqlite_version_info
177
-
178
- Version number of the runtime SQLite library as a :class: `tuple ` of
179
- :class: `integers <int> `.
180
-
181
-
182
- .. data :: threadsafety
183
-
184
- Integer constant required by the DB-API, stating the level of thread safety
185
- the :mod: `!sqlite3 ` module supports. Currently hard-coded to ``1 ``, meaning
186
- *"Threads may share the module, but not connections." * However, this may not
187
- always be true. You can check the underlying SQLite library's compile-time
188
- threaded mode using the following query::
189
-
190
- import sqlite3
191
- con = sqlite3.connect(":memory:")
192
- con.execute("""
193
- select * from pragma_compile_options
194
- where compile_options like 'THREADSAFE=%'
195
- """).fetchall()
196
-
197
- Note that the `SQLITE_THREADSAFE levels
198
- <https://sqlite.org/compile.html#threadsafe> `_ do not match the DB-API 2.0
199
- ``threadsafety `` levels.
200
-
201
-
202
- .. data :: PARSE_DECLTYPES
203
-
204
- Pass this flag value to the *detect_types * parameter of
205
- :func: `connect ` to look up a converter function using
206
- the declared types for each column.
207
- The types are declared when the database table is created.
208
- :mod: `!sqlite3 ` will look up a converter function using the first word of the
209
- declared type as the converter dictionary key.
210
- For example:
211
-
212
-
213
- .. code-block :: sql
214
-
215
- CREATE TABLE test(
216
- i integer primary key, ! will look up a converter named "integer"
217
- p point, ! will look up a converter named "point"
218
- n number(10) ! will look up a converter named "number"
219
- )
220
-
221
- This flag may be combined with :const: `PARSE_COLNAMES ` using the ``| ``
222
- (bitwise or) operator.
223
-
224
-
225
- .. data :: PARSE_COLNAMES
226
-
227
- Pass this flag value to the *detect_types * parameter of
228
- :func: `connect ` to look up a converter function by
229
- using the type name, parsed from the query column name,
230
- as the converter dictionary key.
231
- The type name must be wrapped in square brackets (``[] ``).
232
-
233
- .. code-block :: sql
234
-
235
- SELECT p as "p [point]" FROM test; ! will look up converter "point"
236
-
237
- This flag may be combined with :const: `PARSE_DECLTYPES ` using the ``| ``
238
- (bitwise or) operator.
239
-
240
-
241
-
242
- .. 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)
243
147
244
148
Open a connection to an SQLite database.
245
149
@@ -316,6 +220,33 @@ Module functions and constants
316
220
.. versionadded :: 3.10
317
221
The ``sqlite3.connect/handle `` auditing event.
318
222
223
+ .. function :: complete_statement(statement)
224
+
225
+ Returns ``True `` if the string *statement * contains one or more complete SQL
226
+ statements terminated by semicolons. It does not verify that the SQL is
227
+ syntactically correct, only that there are no unclosed string literals and the
228
+ statement is terminated by a semicolon.
229
+
230
+ This can be used to build a shell for SQLite, as in the following example:
231
+
232
+ .. literalinclude :: ../includes/sqlite3/complete_statement.py
233
+
234
+ .. function :: enable_callback_tracebacks(flag, /)
235
+
236
+ Enable or disable callback tracebacks.
237
+ By default you will not get any tracebacks in user-defined functions,
238
+ aggregates, converters, authorizer callbacks etc. If you want to debug them,
239
+ you can call this function with *flag * set to ``True ``. Afterwards, you will
240
+ get tracebacks from callbacks on ``sys.stderr ``. Use ``False `` to
241
+ disable the feature again.
242
+
243
+ .. function :: register_adapter(type, adapter, /)
244
+
245
+ Register an *adapter * callable to adapt the Python type *type * into an
246
+ SQLite type.
247
+ The adapter is called with a Python object of type *type * as its sole
248
+ argument, and must return a value of a
249
+ :ref: `type that SQLite natively understands <sqlite3-types >`.
319
250
320
251
.. function :: register_converter(typename, converter, /)
321
252
@@ -331,36 +262,102 @@ Module functions and constants
331
262
case-insensitively.
332
263
333
264
334
- .. function :: register_adapter(type, adapter, /)
265
+ .. _ sqlite3-module-constants :
335
266
336
- Register an *adapter * callable to adapt the Python type *type * into an
337
- SQLite type.
338
- The adapter is called with a Python object of type *type * as its sole
339
- argument, and must return a value of a
340
- :ref: `type that SQLite natively understands <sqlite3-types >`.
267
+ Module constants
268
+ ^^^^^^^^^^^^^^^^
341
269
270
+ .. data :: PARSE_COLNAMES
342
271
343
- .. function :: complete_statement(statement)
272
+ Pass this flag value to the *detect_types * parameter of
273
+ :func: `connect ` to look up a converter function by
274
+ using the type name, parsed from the query column name,
275
+ as the converter dictionary key.
276
+ The type name must be wrapped in square brackets (``[] ``).
344
277
345
- Returns ``True `` if the string *statement * contains one or more complete SQL
346
- statements terminated by semicolons. It does not verify that the SQL is
347
- syntactically correct, only that there are no unclosed string literals and the
348
- statement is terminated by a semicolon.
278
+ .. code-block :: sql
349
279
350
- This can be used to build a shell for SQLite, as in the following example:
280
+ SELECT p as "p [point]" FROM test; ! will look up converter "point"
351
281
282
+ This flag may be combined with :const: `PARSE_DECLTYPES ` using the ``| ``
283
+ (bitwise or) operator.
352
284
353
- .. literalinclude :: ../includes/sqlite3/complete_statement.py
285
+ .. data :: PARSE_DECLTYPES
354
286
287
+ Pass this flag value to the *detect_types * parameter of
288
+ :func: `connect ` to look up a converter function using
289
+ the declared types for each column.
290
+ The types are declared when the database table is created.
291
+ :mod: `!sqlite3 ` will look up a converter function using the first word of the
292
+ declared type as the converter dictionary key.
293
+ For example:
355
294
356
- .. function :: enable_callback_tracebacks(flag, /)
295
+ .. code-block :: sql
357
296
358
- Enable or disable callback tracebacks.
359
- By default you will not get any tracebacks in user-defined functions,
360
- aggregates, converters, authorizer callbacks etc. If you want to debug them,
361
- you can call this function with *flag * set to ``True ``. Afterwards, you will
362
- get tracebacks from callbacks on ``sys.stderr ``. Use ``False `` to
363
- disable the feature again.
297
+ CREATE TABLE test(
298
+ i integer primary key, ! will look up a converter named "integer"
299
+ p point, ! will look up a converter named "point"
300
+ n number(10) ! will look up a converter named "number"
301
+ )
302
+
303
+ This flag may be combined with :const: `PARSE_COLNAMES ` using the ``| ``
304
+ (bitwise or) operator.
305
+
306
+ .. data :: apilevel
307
+
308
+ String constant stating the supported DB-API level. Required by the DB-API.
309
+ Hard-coded to ``"2.0" ``.
310
+
311
+ .. data :: paramstyle
312
+
313
+ String constant stating the type of parameter marker formatting expected by
314
+ the :mod: `!sqlite3 ` module. Required by the DB-API. Hard-coded to
315
+ ``"qmark" ``.
316
+
317
+ .. note ::
318
+
319
+ The :mod: `!sqlite3 ` module supports both ``qmark `` and ``numeric `` DB-API
320
+ parameter styles, because that is what the underlying SQLite library
321
+ supports. However, the DB-API does not allow multiple values for
322
+ the ``paramstyle `` attribute.
323
+
324
+ .. data :: sqlite_version
325
+
326
+ Version number of the runtime SQLite library as a :class: `string <str> `.
327
+
328
+ .. data :: sqlite_version_info
329
+
330
+ Version number of the runtime SQLite library as a :class: `tuple ` of
331
+ :class: `integers <int> `.
332
+
333
+ .. data :: threadsafety
334
+
335
+ Integer constant required by the DB-API, stating the level of thread safety
336
+ the :mod: `!sqlite3 ` module supports. Currently hard-coded to ``1 ``, meaning
337
+ *"Threads may share the module, but not connections." * However, this may not
338
+ always be true. You can check the underlying SQLite library's compile-time
339
+ threaded mode using the following query::
340
+
341
+ import sqlite3
342
+ con = sqlite3.connect(":memory:")
343
+ con.execute("""
344
+ select * from pragma_compile_options
345
+ where compile_options like 'THREADSAFE=%'
346
+ """).fetchall()
347
+
348
+ Note that the `SQLITE_THREADSAFE levels
349
+ <https://sqlite.org/compile.html#threadsafe> `_ do not match the DB-API 2.0
350
+ ``threadsafety `` levels.
351
+
352
+ .. data :: version
353
+
354
+ Version number of this module as a :class: `string <str> `.
355
+ This is not the version of the SQLite library.
356
+
357
+ .. data :: version_info
358
+
359
+ Version number of this module as a :class: `tuple ` of :class: `integers <int> `.
360
+ This is not the version of the SQLite library.
364
361
365
362
366
363
.. _sqlite3-connection-objects :
0 commit comments