mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-21 16:05:17 +01:00
instruction: added destroy instruction
added required functionality for destroy. minor cleanup of print statements
This commit is contained in:
@@ -316,10 +316,8 @@ impl Connection {
|
||||
pub(crate) fn run_cmd(self: &Rc<Connection>, cmd: Cmd) -> Result<Option<Statement>> {
|
||||
let db = self.db.clone();
|
||||
let syms: &SymbolTable = &db.syms.borrow();
|
||||
println!("the command {:?}", cmd);
|
||||
match cmd {
|
||||
Cmd::Stmt(stmt) => {
|
||||
println!("AST: {:?}", stmt);
|
||||
let program = Rc::new(translate::translate(
|
||||
&self.schema.borrow(),
|
||||
stmt,
|
||||
@@ -329,7 +327,6 @@ impl Connection {
|
||||
syms,
|
||||
QueryMode::Normal,
|
||||
)?);
|
||||
println!("the generated program {:?}", program);
|
||||
let stmt = Statement::new(program, self.pager.clone());
|
||||
Ok(Some(stmt))
|
||||
}
|
||||
@@ -370,13 +367,11 @@ impl Connection {
|
||||
}
|
||||
|
||||
pub fn execute(self: &Rc<Connection>, sql: impl AsRef<str>) -> Result<()> {
|
||||
println!("running execute");
|
||||
let sql = sql.as_ref();
|
||||
let db = &self.db;
|
||||
let syms: &SymbolTable = &db.syms.borrow();
|
||||
let mut parser = Parser::new(sql.as_bytes());
|
||||
let cmd = parser.next()?;
|
||||
println!("the command {:?}", cmd);
|
||||
if let Some(cmd) = cmd {
|
||||
match cmd {
|
||||
Cmd::Explain(stmt) => {
|
||||
|
||||
@@ -1101,6 +1101,22 @@ pub fn insn_to_str(
|
||||
0,
|
||||
format!("r[{}]=root iDb={} flags={}", root, db, flags),
|
||||
),
|
||||
Insn::Destroy {
|
||||
root,
|
||||
former_root_reg,
|
||||
is_temp,
|
||||
} => (
|
||||
"Destroy",
|
||||
*root as i32,
|
||||
*former_root_reg as i32,
|
||||
*is_temp as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
0,
|
||||
format!(
|
||||
"root iDb={} former_root={} is_temp={}",
|
||||
root, former_root_reg, is_temp
|
||||
),
|
||||
),
|
||||
Insn::DropTable { db, root } => (
|
||||
"DropTable",
|
||||
*db as i32,
|
||||
|
||||
@@ -590,6 +590,16 @@ pub enum Insn {
|
||||
flags: usize,
|
||||
},
|
||||
|
||||
/// Deletes an entire database table or index whose root page in the database file is given by P1.
|
||||
Destroy {
|
||||
/// The root page of the table/index to destroy
|
||||
root: usize,
|
||||
/// Register to store the former value of any moved root page (for AUTOVACUUM)
|
||||
former_root_reg: usize,
|
||||
/// Whether this is a temporary table (1) or main database table (0)
|
||||
is_temp: usize,
|
||||
},
|
||||
|
||||
// Drop a table
|
||||
DropTable {
|
||||
// The database within which this b-tree needs to be dropped (P1).
|
||||
|
||||
@@ -2688,14 +2688,24 @@ impl Program {
|
||||
state.registers[*root] = OwnedValue::Integer(root_page as i64);
|
||||
state.pc += 1;
|
||||
}
|
||||
Insn::DropTable { db, root } => {
|
||||
if *db > 0 {
|
||||
todo!("temp databases not implemented yet");
|
||||
Insn::Destroy {
|
||||
root,
|
||||
former_root_reg: _,
|
||||
is_temp,
|
||||
} => {
|
||||
if *is_temp == 1 {
|
||||
todo!("temp databases not implemented yet.");
|
||||
}
|
||||
let mut cursor = Box::new(BTreeCursor::new(pager.clone(), *root));
|
||||
cursor.btree_drop()?;
|
||||
state.pc += 1;
|
||||
}
|
||||
Insn::DropTable { db, root: _ } => {
|
||||
if *db > 0 {
|
||||
todo!("temp databases not implemented yet");
|
||||
}
|
||||
// TODO (Zaid): implement the functionality to clean up in-memory structures
|
||||
}
|
||||
Insn::Close { cursor_id } => {
|
||||
let mut cursors = state.cursors.borrow_mut();
|
||||
cursors.get_mut(*cursor_id).unwrap().take();
|
||||
|
||||
Reference in New Issue
Block a user