mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-07-07 12:35:00 +00:00
add delete where basic functionality
This commit is contained in:
parent
74fc789719
commit
86ea224069
2 changed files with 39 additions and 1 deletions
|
@ -422,7 +422,7 @@ fn emit_program_for_delete(
|
|||
&mut plan.where_clause,
|
||||
)?;
|
||||
|
||||
emit_delete_insns(program, &mut t_ctx, &plan.table_references)?;
|
||||
emit_delete_insns(program, &mut t_ctx, &plan.table_references, &plan)?;
|
||||
|
||||
// Clean up and close the main execution loop
|
||||
close_loop(
|
||||
|
@ -444,6 +444,7 @@ fn emit_delete_insns(
|
|||
program: &mut ProgramBuilder,
|
||||
t_ctx: &mut TranslateCtx,
|
||||
table_references: &TableReferences,
|
||||
plan: &DeletePlan,
|
||||
) -> Result<()> {
|
||||
let table_reference = table_references.joined_tables().first().unwrap();
|
||||
let cursor_id = match &table_reference.op {
|
||||
|
@ -465,6 +466,27 @@ fn emit_delete_insns(
|
|||
let main_table_cursor_id =
|
||||
program.resolve_cursor_id(&CursorKey::table(table_reference.internal_id));
|
||||
|
||||
for cond in plan
|
||||
.where_clause
|
||||
.iter()
|
||||
.filter(|c| c.should_eval_before_loop(&[JoinOrderMember::default()]))
|
||||
{
|
||||
let jump_target = program.allocate_label();
|
||||
let meta = ConditionMetadata {
|
||||
jump_if_condition_is_true: false,
|
||||
jump_target_when_true: jump_target,
|
||||
jump_target_when_false: t_ctx.label_main_loop_end.unwrap(),
|
||||
};
|
||||
translate_condition_expr(
|
||||
program,
|
||||
&plan.table_references,
|
||||
&cond.expr,
|
||||
meta,
|
||||
&t_ctx.resolver,
|
||||
)?;
|
||||
program.preassign_label_to_next_insn(jump_target);
|
||||
}
|
||||
|
||||
// Emit the instructions to delete the row
|
||||
let key_reg = program.alloc_register();
|
||||
program.emit_insn(Insn::RowId {
|
||||
|
|
16
testing/delete.test
Normal file → Executable file
16
testing/delete.test
Normal file → Executable file
|
@ -62,3 +62,19 @@ if {[info exists ::env(SQLITE_EXEC)] && $::env(SQLITE_EXEC) eq "scripts/limbo-sq
|
|||
SELECT * FROM t;
|
||||
} {}
|
||||
}
|
||||
|
||||
do_execsql_test_on_specific_db {:memory:} delete_where_falsy {
|
||||
CREATE TABLE resourceful_schurz (diplomatic_kaplan BLOB);
|
||||
INSERT INTO resourceful_schurz VALUES (X'696E646570656E64656E745F6A6165636B6C65'), (X'67656E65726F75735F62617262616E65677261'), (X'73757065725F74616E6E656E6261756D'), (X'6D6F76696E675F6E616F756D6F76'), (X'7374756E6E696E675F6B62');
|
||||
INSERT INTO resourceful_schurz VALUES (X'70617373696F6E6174655F726F62696E'), (X'666169746866756C5F74686F6D6173'), (X'76696272616E745F6D69726F736C6176'), (X'737061726B6C696E675F67726179');
|
||||
DELETE FROM resourceful_schurz WHERE - x'666169746866756c5f74686f6d6173';
|
||||
SELECT * FROM resourceful_schurz;
|
||||
} {independent_jaeckle
|
||||
generous_barbanegra
|
||||
super_tannenbaum
|
||||
moving_naoumov
|
||||
stunning_kb
|
||||
passionate_robin
|
||||
faithful_thomas
|
||||
vibrant_miroslav
|
||||
sparkling_gray}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue