Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module #24203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Module functions and constants
The :mod:`sqlite3` module internally uses a statement cache to avoid SQL parsing
overhead. If you want to explicitly set the number of statements that are cached
for the connection, you can set the *cached_statements* parameter. The currently
implemented default is to cache 100 statements.
implemented default is to cache 128 statements.

If *uri* is true, *database* is interpreted as a URI. This allows you
to specify options. For example, to open a database in read-only mode
Expand Down
11 changes: 11 additions & 0 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sqlite3 as sqlite
import sys

from test.support import gc_collect
from test.support.os_helper import TESTFN, unlink


Expand Down Expand Up @@ -181,6 +182,11 @@ def __fspath__(self):
with sqlite.connect(path) as cx:
cx.execute('create table test(id integer)')

# bpo-42862: addCleanup fails to unlink TESTFN on Windows unless we
# explicitly close the connection and run the GC.
cx.close()
gc_collect()

def test_open_uri(self):
self.addCleanup(unlink, TESTFN)
with sqlite.connect(TESTFN) as cx:
Expand All @@ -191,6 +197,11 @@ def test_open_uri(self):
with self.assertRaises(sqlite.OperationalError):
cx.execute('insert into test(id) values(1)')

# bpo-42862: addCleanup fails to unlink TESTFN on Windows unless we
# explicitly close the connection and run the GC.
cx.close()
gc_collect()


class CursorTests(unittest.TestCase):
def setUp(self):
Expand Down
7 changes: 7 additions & 0 deletions Lib/sqlite3/test/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import unittest
import sqlite3 as sqlite

from test.support import gc_collect
from test.support.os_helper import TESTFN, unlink


Expand Down Expand Up @@ -261,6 +262,12 @@ def trace(statement):
cur.execute(queries[1])
self.assertEqual(traced_statements, queries)

# bpo-42862: addCleanup fails to unlink TESTFN on Windows unless we
# explicitly close the connections and run the GC.
con1.close()
con2.close()
gc_collect()


def suite():
tests = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:mod:`sqlite3` now utilizes :meth:`functools.lru_cache` to implement the
connection statement cache. As a small optimisation, the default
statement cache size has been increased from 100 to 128.
Patch by Erlend E. Aasland.
Loading