bpo-45243: Add support for setting/getting sqlite3 connection limits (GH-28463)

This commit is contained in:
Erlend Egeberg Aasland 2021-11-01 23:50:53 +01:00 committed by GitHub
parent e2063d6a1e
commit b6b38a8226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 228 additions and 1 deletions

View file

@ -662,6 +662,40 @@ Connection Objects
.. versionadded:: 3.7
.. method:: getlimit(category, /)
Get a connection run-time limit. *category* is the limit category to be
queried.
Example, query the maximum length of an SQL statement::
import sqlite3
con = sqlite3.connect(":memory:")
lim = con.getlimit(sqlite3.SQLITE_LIMIT_SQL_LENGTH)
print(f"SQLITE_LIMIT_SQL_LENGTH={lim}")
.. versionadded:: 3.11
.. method:: setlimit(category, limit, /)
Set a connection run-time limit. *category* is the limit category to be
set. *limit* is the new limit. If the new limit is a negative number, the
limit is unchanged.
Attempts to increase a limit above its hard upper bound are silently
truncated to the hard upper bound. Regardless of whether or not the limit
was changed, the prior value of the limit is returned.
Example, limit the number of attached databases to 1::
import sqlite3
con = sqlite3.connect(":memory:")
con.setlimit(sqlite3.SQLITE_LIMIT_ATTACHED, 1)
.. versionadded:: 3.11
.. _sqlite3-cursor-objects:
Cursor Objects