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
This commit is contained in:
Diego Reis 2025-03-17 10:01:00 -03:00
parent 2314e7f906
commit 250478fedf
2 changed files with 9 additions and 2 deletions

View file

@ -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 });

View file

@ -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
} {}