From e85897a14b2d35f5a23ff3f54a2db03c882966fc Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 25 Oct 2021 23:37:21 +0200 Subject: [PATCH 1/7] bpo-45608: Document missing DB-API attributes --- Doc/library/sqlite3.rst | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index eaea7ae390b972..c5912378ef1a39 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -117,6 +117,24 @@ Module functions and constants ------------------------------ +.. data:: apilevel + + String constant stating the supported DB-API level. Required by the DB-API. + Hard-coded to ``"2.0"``. + +.. data:: paramstyle + + String constant stating the type of parameter marker formatting expected by + the :mod:`sqlite3` module. Required by the DB-API. Hard-coded to + ``"qmark"``. + + .. note:: + + The :mod:`sqlite3` module supports both ``qmark`` and ``numeric`` DB-API + parameter styles, because that is what the underlying SQLite library + supports. However, the DB-API does not allow multiple values for + the ``paramstyle`` attribute. + .. data:: version The version number of this module, as a string. This is not the version of @@ -139,6 +157,26 @@ Module functions and constants The version number of the run-time SQLite library, as a tuple of integers. +.. data:: threadsafety + + Integer constant required by the DB-API, stating the level of thread safety + the :mod:`sqlite3` supports. Currently hard-coded to ``1``, meaning + _"Threads may share the module, but not connections."_ However, this may not + always be true. You can check the underlying SQLite library's compile-time + threaded mode using the following query:: + + >>> import sqlite3 + >>> con = sqlite3.connect(":memory:") + >>> con.execute(""" + select * from pragma_compile_options + where compile_options like 'THREADSAFE=%' + """).fetchall() + + Note that the `SQLITE_THREADSAFE levels + `_ do not match the DB-API 2.0 + ``threadsafety`` levels. + + .. data:: PARSE_DECLTYPES This constant is meant to be used with the *detect_types* parameter of the From 812313711e7cd3ee5383dc8cc9d7ec9be022255e Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 25 Oct 2021 23:47:02 +0200 Subject: [PATCH 2/7] Formatting: fix italics --- Doc/library/sqlite3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index c5912378ef1a39..755aac3cd2320a 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -161,7 +161,7 @@ Module functions and constants Integer constant required by the DB-API, stating the level of thread safety the :mod:`sqlite3` supports. Currently hard-coded to ``1``, meaning - _"Threads may share the module, but not connections."_ However, this may not + *"Threads may share the module, but not connections."* However, this may not always be true. You can check the underlying SQLite library's compile-time threaded mode using the following query:: From 36fafe25b08f5b5241bc2b7011c710b006747d7e Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 25 Oct 2021 23:47:46 +0200 Subject: [PATCH 3/7] Fix code example formatting --- Doc/library/sqlite3.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 755aac3cd2320a..bcd4110cb07595 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -168,9 +168,9 @@ Module functions and constants >>> import sqlite3 >>> con = sqlite3.connect(":memory:") >>> con.execute(""" - select * from pragma_compile_options - where compile_options like 'THREADSAFE=%' - """).fetchall() + select * from pragma_compile_options + where compile_options like 'THREADSAFE=%' + """).fetchall() Note that the `SQLITE_THREADSAFE levels `_ do not match the DB-API 2.0 From 3f0d232cae625d12dca80c046b7d585a5950b72c Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 26 Oct 2021 00:01:29 +0200 Subject: [PATCH 4/7] More formatting fixes. --- Doc/library/sqlite3.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index bcd4110cb07595..643de774e8f5ab 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -165,12 +165,12 @@ Module functions and constants always be true. You can check the underlying SQLite library's compile-time threaded mode using the following query:: - >>> import sqlite3 - >>> con = sqlite3.connect(":memory:") - >>> con.execute(""" - select * from pragma_compile_options - where compile_options like 'THREADSAFE=%' - """).fetchall() + import sqlite3 + con = sqlite3.connect(":memory:") + con.execute(""" + select * from pragma_compile_options + where compile_options like 'THREADSAFE=%%' + """).fetchall() Note that the `SQLITE_THREADSAFE levels `_ do not match the DB-API 2.0 From 8fdd435ce22da9b73a7ab7aefb7ce38af98006b1 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 26 Oct 2021 00:11:17 +0200 Subject: [PATCH 5/7] Also document missing cursor methods --- Doc/library/sqlite3.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 643de774e8f5ab..61a01b193a6ff9 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -748,6 +748,14 @@ Cursor Objects The cursor will be unusable from this point forward; a :exc:`ProgrammingError` exception will be raised if any operation is attempted with the cursor. + .. method:: setinputsizes(sizes) + + Required by the DB-API. Is a no-op in :mod:`sqlite3`. + + .. method:: setoutputsize(size [, column]) + + Required by the DB-API. Is a no-op in :mod:`sqlite3`. + .. attribute:: rowcount Although the :class:`Cursor` class of the :mod:`sqlite3` module implements this From 3448f92e4b576fa267b043db001528d1786eb3c4 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 26 Oct 2021 09:25:35 +0200 Subject: [PATCH 6/7] Remove superfluous '%' --- Doc/library/sqlite3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 61a01b193a6ff9..a2fa69a10e06c8 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -169,7 +169,7 @@ Module functions and constants con = sqlite3.connect(":memory:") con.execute(""" select * from pragma_compile_options - where compile_options like 'THREADSAFE=%%' + where compile_options like 'THREADSAFE=%' """).fetchall() Note that the `SQLITE_THREADSAFE levels From b087d3a9ddc956649cb79d92fef35b0fad6200f4 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 26 Oct 2021 09:29:03 +0200 Subject: [PATCH 7/7] Adjust wording --- Doc/library/sqlite3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index a2fa69a10e06c8..fe1b64ade95612 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -160,7 +160,7 @@ Module functions and constants .. data:: threadsafety Integer constant required by the DB-API, stating the level of thread safety - the :mod:`sqlite3` supports. Currently hard-coded to ``1``, meaning + the :mod:`sqlite3` module supports. Currently hard-coded to ``1``, meaning *"Threads may share the module, but not connections."* However, this may not always be true. You can check the underlying SQLite library's compile-time threaded mode using the following query::