add TypeCheck insn to update

This commit is contained in:
Ihor Andrianov
2025-04-07 19:54:25 +03:00
parent 3a97fd075f
commit 7c15465118
2 changed files with 15 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
// This module contains code for emitting bytecode instructions for SQL query execution.
// It handles translating high-level SQL operations into low-level bytecode that can be executed by the virtual machine.
use std::rc::Rc;
use limbo_sqlite3_parser::ast::{self};
use crate::function::Func;
@@ -614,6 +616,16 @@ fn emit_update_insns(
}
}
}
if let Some(btree_table) = table_ref.btree() {
if btree_table.is_strict {
program.emit_insn(Insn::TypeCheck {
start_reg: first_col_reg,
count: table_ref.columns().len(),
check_generated: true,
table_reference: Rc::clone(&btree_table),
});
}
}
let record_reg = program.alloc_register();
program.emit_insn(Insn::MakeRecord {
start_reg: first_col_reg,

View File

@@ -1375,10 +1375,10 @@ pub fn op_type_check(
col.name.as_ref().map(|s| s.as_str()).unwrap_or(""),
SQLITE_CONSTRAINT
)
} else if col.is_rowid_alias {
// If it is INTEGER PRIMARY KEY we let sqlite assign row_id
} else if col.is_rowid_alias && matches!(reg.get_owned_value(), OwnedValue::Null) {
// Handle INTEGER PRIMARY KEY for null as usual (Rowid will be auto-assigned)
return Ok(());
};
}
let col_affinity = col.affinity();
let ty_str = col.ty_str.as_str();
let applied = apply_affinity_char(reg, col_affinity);