From 2314e7f906662ca2f633c122381851bba7d57b62 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Mon, 17 Mar 2025 09:50:22 -0300 Subject: [PATCH 1/3] Improve explain output for `Transaction` bytecode. It isn't SQLite compliant but it helps a lot, specially when the user doesn't know what each register means. --- core/vdbe/explain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/vdbe/explain.rs b/core/vdbe/explain.rs index 0917729c8..613cd66ea 100644 --- a/core/vdbe/explain.rs +++ b/core/vdbe/explain.rs @@ -599,7 +599,7 @@ pub fn insn_to_str( 0, OwnedValue::build_text(""), 0, - "".to_string(), + format!("write={}", write), ), Insn::Goto { target_pc } => ( "Goto", From 250478fedfdd925efa58edb4c603e1935ab324d3 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Mon, 17 Mar 2025 10:01:00 -0300 Subject: [PATCH 2/3] Implement deferred transactions As explained in docs: https://sqlite.org/lang_transaction.html "BEGIN DEFERRED statement merely sets a flag on the database connection that turns off the automatic commit that would normally occur when the last statement finishes." The transaction upgrade (read -> write) is already handled by the VDBE --- core/translate/transaction.rs | 7 +++++-- testing/transactions.test | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/translate/transaction.rs b/core/translate/transaction.rs index 01994dfd4..60e00e73b 100644 --- a/core/translate/transaction.rs +++ b/core/translate/transaction.rs @@ -1,6 +1,6 @@ use crate::translate::{ProgramBuilder, ProgramBuilderOpts}; use crate::vdbe::insn::Insn; -use crate::{bail_parse_error, QueryMode, Result}; +use crate::{QueryMode, Result}; use limbo_sqlite3_parser::ast::{Name, TransactionType}; pub fn translate_tx_begin( @@ -18,7 +18,10 @@ pub fn translate_tx_begin( let tx_type = tx_type.unwrap_or(TransactionType::Deferred); match tx_type { TransactionType::Deferred => { - bail_parse_error!("BEGIN DEFERRED not supported yet"); + program.emit_insn(Insn::AutoCommit { + auto_commit: false, + rollback: false, + }); } TransactionType::Immediate | TransactionType::Exclusive => { program.emit_insn(Insn::Transaction { write: true }); diff --git a/testing/transactions.test b/testing/transactions.test index 3a14d8128..142c721f7 100755 --- a/testing/transactions.test +++ b/testing/transactions.test @@ -10,3 +10,7 @@ do_execsql_test basic-tx-1 { do_execsql_test basic-tx-2 { BEGIN EXCLUSIVE; END } {} + +do_execsql_test basic-tx-3 { + BEGIN DEFERRED; END + } {} \ No newline at end of file From 16396c57c7db6082723d432399cc99e9dc721347 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Mon, 17 Mar 2025 10:06:14 -0300 Subject: [PATCH 3/3] Removes unnecessary clone --- core/vdbe/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index af3349a55..95e115ad9 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -1263,9 +1263,7 @@ impl Program { } } if updated { - connection - .transaction_state - .replace(new_transaction_state.clone()); + connection.transaction_state.replace(new_transaction_state); } } state.pc += 1;