Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-44092: Don't reset statements/cursors before rollback#26026

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
pablogsal merged 21 commits intopython:mainfromerlend-aasland:sqlite-rollback
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
21 commits
Select commitHold shift + click to select a range
8acdabe
bpo-44092: Don't reset statements/cursors before rollback
May 10, 2021
8fb7475
Add NEWS
May 19, 2021
898625a
Remove test_cursor_registration
May 19, 2021
ad18bec
Merge branch 'main' into sqlite-rollback
Jun 18, 2021
31b01bf
Merge branch 'main' into sqlite-rollback
Jun 24, 2021
d4202e4
Add What's New
Jun 24, 2021
f5d5e68
Merge branch 'main' into sqlite-rollback
Jul 29, 2021
0cd5a67
Merge branch 'main' into sqlite-rollback
Jul 29, 2021
c30752b
Sync with main bco. GH-25998
Aug 19, 2021
019bc08
Remove now obsolete pysqlite_do_all_statements()
Aug 19, 2021
90e76a8
Sync NEWS/What's New text
Aug 19, 2021
fc55047
Adjust test docstring wording
Aug 19, 2021
099b696
Adjust whitespace around new test class
Aug 19, 2021
29eee0e
Simplify rollback test
Aug 19, 2021
8f7024c
Merge branch 'main' into sqlite-rollback
Aug 30, 2021
f7065b1
Merge branch 'main' into sqlite-rollback
Sep 8, 2021
9ebb0fb
Merge branch 'main' into sqlite-rollback
Sep 14, 2021
e7b20ab
Merge branch 'main' into sqlite-rollback
Sep 19, 2021
6d6c2f4
Merge branch 'main' into sqlite-rollback
Oct 6, 2021
de0554f
Merge remote-tracking branch 'upstream/main' into sqlite-rollback
Oct 19, 2021
1766967
Merge branch 'main' into sqlite-rollback
Nov 1, 2021
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
5 changes: 5 additions & 0 deletionsDoc/whatsnew/3.11.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -248,6 +248,11 @@ sqlite3
(Contributed by Aviv Palivoda, Daniel Shahaf, and Erlend E. Aasland in
:issue:`16379`.)

* Fetch across rollback no longer raises :exc:`~sqlite3.InterfaceError`.
Instead we leave it to the SQLite library to handle these cases.
(Contributed by Erlend E. Aasland in :issue:`44092`.)


threading
---------

Expand Down
22 changes: 0 additions & 22 deletionsLib/test/test_sqlite3/test_regression.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -230,28 +230,6 @@ def __init__(self, name):
with self.assertRaises(sqlite.ProgrammingError):
cur = con.cursor()

def test_cursor_registration(self):
"""
Verifies that subclassed cursor classes are correctly registered with
the connection object, too. (fetch-across-rollback problem)
"""
class Connection(sqlite.Connection):
def cursor(self):
return Cursor(self)

class Cursor(sqlite.Cursor):
def __init__(self, con):
sqlite.Cursor.__init__(self, con)

con = Connection(":memory:")
cur = con.cursor()
cur.execute("create table foo(x)")
cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)])
cur.execute("select x from foo")
con.rollback()
with self.assertRaises(sqlite.InterfaceError):
cur.fetchall()

def test_auto_commit(self):
"""
Verifies that creating a connection in autocommit mode works.
Expand Down
45 changes: 39 additions & 6 deletionsLib/test/test_sqlite3/test_transactions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,19 +129,52 @@ def test_locking(self):
self.con1.commit()

def test_rollback_cursor_consistency(self):
"""
Checks if cursors on the connection are set into a "reset" state
when a rollback is done on the connection.
"""
"""Check that cursors behave correctly after rollback."""
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.execute("create table test(x)")
cur.execute("insert into test(x) values (5)")
cur.execute("select 1 union select 2 union select 3")

con.rollback()
with self.assertRaises(sqlite.InterfaceError):
cur.fetchall()
self.assertEqual(cur.fetchall(), [(1,), (2,), (3,)])


class RollbackTests(unittest.TestCase):
"""bpo-44092: sqlite3 now leaves it to SQLite to resolve rollback issues"""

def setUp(self):
self.con = sqlite.connect(":memory:")
self.cur1 = self.con.cursor()
self.cur2 = self.con.cursor()
with self.con:
self.con.execute("create table t(c)");
self.con.executemany("insert into t values(?)", [(0,), (1,), (2,)])
self.cur1.execute("begin transaction")
select = "select c from t"
self.cur1.execute(select)
self.con.rollback()
self.res = self.cur2.execute(select) # Reusing stmt from cache

def tearDown(self):
self.con.close()

def _check_rows(self):
for i, row in enumerate(self.res):
self.assertEqual(row[0], i)

def test_no_duplicate_rows_after_rollback_del_cursor(self):
del self.cur1
self._check_rows()

def test_no_duplicate_rows_after_rollback_close_cursor(self):
self.cur1.close()
self._check_rows()

def test_no_duplicate_rows_after_rollback_new_query(self):
self.cur1.execute("select c from t where c = 1")
self._check_rows()


class SpecialCommandTests(unittest.TestCase):
def setUp(self):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fetch across rollback no longer raises :exc:`~sqlite3.InterfaceError`. Instead
we leave it to the SQLite library to handle these cases.
Patch by Erlend E. Aasland.
24 changes: 0 additions & 24 deletionsModules/_sqlite/connection.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -234,28 +234,6 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
return 0;
}

static void
pysqlite_do_all_statements(pysqlite_Connection *self)
{
// Reset all statements
sqlite3_stmt *stmt = NULL;
while ((stmt = sqlite3_next_stmt(self->db, stmt))) {
if (sqlite3_stmt_busy(stmt)) {
(void)sqlite3_reset(stmt);
}
}

// Reset all cursors
for (int i = 0; i < PyList_Size(self->cursors); i++) {
PyObject *weakref = PyList_GetItem(self->cursors, i);
PyObject *object = PyWeakref_GetObject(weakref);
if (object != Py_None) {
pysqlite_Cursor *cursor = (pysqlite_Cursor *)object;
cursor->reset = 1;
}
}
}

#define VISIT_CALLBACK_CONTEXT(ctx) \
do { \
if (ctx) { \
Expand DownExpand Up@@ -506,8 +484,6 @@ pysqlite_connection_rollback_impl(pysqlite_Connection *self)
}

if (!sqlite3_get_autocommit(self->db)) {
pysqlite_do_all_statements(self);

int rc;

Py_BEGIN_ALLOW_THREADS
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp