use crate::{
binder::bound::BoundInsertStmt,
executor::{ExecutionError, ExecutionResult, Executor},
};
impl Executor {
pub fn execute_insert_table(
&mut self,
stmt: BoundInsertStmt,
) -> Result<ExecutionResult, ExecutionError> {
let db = stmt.db;
let schema = stmt.schema;
let table = stmt.table;
let rows = stmt.rows;
let table_entry = self.catalog.get_table(db, schema, table)?;
let columns = table_entry.columns.clone();
let row_count = rows.len();
if self.storage.is_some() {
let key = (db, schema, table);
self.get_or_open_table_heap(db, schema, table)?;
for row in &rows {
let table_heap = self
.table_heaps
.get_mut(&key)
.expect("just inserted by get_or_open_table_heap above");
table_heap
.insert_tuple(&columns, row, &self.catalog.interner)
.map_err(|e| ExecutionError::Storage(e.to_string()))?;
}
}
Ok(ExecutionResult::Inserted {
name: table,
count: row_count,
})
}
}