From 08165fc34e6450ed41559e7398cf04b65e791234 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 8 May 2024 07:17:20 -0300 Subject: [PATCH] core: SELECT support --- core/translate.rs | 9 ++++++++- core/vdbe.rs | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/translate.rs b/core/translate.rs index 727dc17e2..342bbc2cf 100644 --- a/core/translate.rs +++ b/core/translate.rs @@ -193,7 +193,14 @@ fn translate_expr( }); dest } - Literal::String(_) => todo!(), + Literal::String(s) => { + let dest = program.alloc_register(); + program.emit_insn(Insn::String8 { + value: s.to_string(), + dest, + }); + dest + } Literal::Blob(_) => todo!(), Literal::Keyword(_) => todo!(), Literal::Null => todo!(), diff --git a/core/vdbe.rs b/core/vdbe.rs index 1d7524059..754588384 100644 --- a/core/vdbe.rs +++ b/core/vdbe.rs @@ -80,6 +80,12 @@ pub enum Insn { dest: usize, }, + // Write a string value into a register. + String8 { + value: String, + dest: usize, + }, + // Read the rowid of the current row. RowId { cursor_id: CursorID, @@ -307,6 +313,10 @@ impl Program { state.registers[*dest] = OwnedValue::Integer(*value); state.pc += 1; } + Insn::String8 { value, dest } => { + state.registers[*dest] = OwnedValue::Text(Rc::new(value.into())); + state.pc += 1; + } Insn::RowId { cursor_id, dest } => { let cursor = cursors.get_mut(cursor_id).unwrap(); if let Some(ref rowid) = *cursor.rowid()? { @@ -417,6 +427,7 @@ fn insn_to_str(addr: usize, insn: &Insn) -> String { Insn::Integer { value, dest } => { ("Integer", *dest, *value as usize, 0, "", 0, "".to_string()) } + Insn::String8 { value, dest } => ("String8", *dest, 0, 0, "", 0, "".to_string()), Insn::RowId { cursor_id, dest } => ("RowId", *cursor_id, *dest, 0, "", 0, "".to_string()), Insn::DecrJumpZero { reg, target_pc } => { ("DecrJumpZero", *reg, *target_pc, 0, "", 0, "".to_string())