mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
fix(sqlite): autocommit mode transaction handling to match CPython (#5918)
This commit is contained in:
1 parent
f0cf9e6492
commit
e6fdef43dc
2 files changed
+18
-4
No files matched your search
-2
@@ -94,8 +94,6 @@ class TransactionTests(unittest.TestCase):
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0][0], 5)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_toggle_auto_commit(self):
|
||||
self.cur1.execute("create table test(i)")
|
||||
self.cur1.execute("insert into test(i) values (5)")
|
||||
|
||||
+18
-2
@@ -1346,6 +1346,16 @@ mod _sqlite {
|
||||
if let Some(val) = &val {
|
||||
begin_statement_ptr_from_isolation_level(val, vm)?;
|
||||
}
|
||||
|
||||
// If setting isolation_level to None (auto-commit mode), commit any pending transaction
|
||||
if val.is_none() {
|
||||
let db = self.db_lock(vm)?;
|
||||
if !db.is_autocommit() {
|
||||
// Keep the lock and call implicit_commit directly to avoid race conditions
|
||||
db.implicit_commit(vm)?;
|
||||
}
|
||||
}
|
||||
|
||||
let _ = unsafe { self.isolation_level.swap(val) };
|
||||
Ok(())
|
||||
}
|
||||
@@ -1472,7 +1482,10 @@ mod _sqlite {
|
||||
|
||||
let db = zelf.connection.db_lock(vm)?;
|
||||
|
||||
if stmt.is_dml && db.is_autocommit() {
|
||||
if stmt.is_dml
|
||||
&& db.is_autocommit()
|
||||
&& zelf.connection.isolation_level.deref().is_some()
|
||||
{
|
||||
db.begin_transaction(
|
||||
zelf.connection
|
||||
.isolation_level
|
||||
@@ -1552,7 +1565,10 @@ mod _sqlite {
|
||||
|
||||
let db = zelf.connection.db_lock(vm)?;
|
||||
|
||||
if stmt.is_dml && db.is_autocommit() {
|
||||
if stmt.is_dml
|
||||
&& db.is_autocommit()
|
||||
&& zelf.connection.isolation_level.deref().is_some()
|
||||
{
|
||||
db.begin_transaction(
|
||||
zelf.connection
|
||||
.isolation_level
|
||||
|
||||
Reference in new issue
Block a user