mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-06 16:54:23 +01:00
Add changes tracking to the 'Connection' struct + 'Insn::InsertAwait' now affects changes counter
This commit is contained in:
@@ -141,6 +141,8 @@ impl Database {
|
||||
header,
|
||||
transaction_state: RefCell::new(TransactionState::None),
|
||||
last_insert_rowid: Cell::new(0),
|
||||
last_change: Cell::new(0),
|
||||
total_changes: Cell::new(0),
|
||||
});
|
||||
let rows = conn.query("SELECT * FROM sqlite_schema")?;
|
||||
let mut schema = schema.borrow_mut();
|
||||
@@ -156,6 +158,8 @@ impl Database {
|
||||
header: self.header.clone(),
|
||||
last_insert_rowid: Cell::new(0),
|
||||
transaction_state: RefCell::new(TransactionState::None),
|
||||
last_change: Cell::new(0),
|
||||
total_changes: Cell::new(0),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -231,6 +235,8 @@ pub struct Connection {
|
||||
header: Rc<RefCell<DatabaseHeader>>,
|
||||
transaction_state: RefCell<TransactionState>,
|
||||
last_insert_rowid: Cell<u64>,
|
||||
last_change: Cell<i64>,
|
||||
total_changes: Cell<i64>,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
|
||||
@@ -1012,11 +1012,14 @@ pub fn translate_expr(
|
||||
unreachable!("this is always ast::Expr::Cast")
|
||||
}
|
||||
ScalarFunc::Changes => {
|
||||
if let Some(args) = args{
|
||||
crate::bail_parse_error!("{} fucntion with more than 0 arguments", srf);
|
||||
if let Some(_) = args {
|
||||
crate::bail_parse_error!(
|
||||
"{} fucntion with more than 0 arguments",
|
||||
srf
|
||||
);
|
||||
}
|
||||
let start_reg = program.alloc_register();
|
||||
program.emit_insn(Insn::Function{
|
||||
program.emit_insn(Insn::Function {
|
||||
constant_mask: 0,
|
||||
start_reg,
|
||||
dest: target_register,
|
||||
@@ -1515,11 +1518,14 @@ pub fn translate_expr(
|
||||
Ok(target_register)
|
||||
}
|
||||
ScalarFunc::TotalChanges => {
|
||||
if let Some(args) = args {
|
||||
crate::bail_parse_error!("{} fucntion with more than 0 arguments", srf.to_string());
|
||||
if let Some(_) = args {
|
||||
crate::bail_parse_error!(
|
||||
"{} fucntion with more than 0 arguments",
|
||||
srf.to_string()
|
||||
);
|
||||
}
|
||||
let start_reg = program.alloc_register();
|
||||
program.emit_insn(Insn::Function{
|
||||
program.emit_insn(Insn::Function {
|
||||
constant_mask: 0,
|
||||
start_reg,
|
||||
dest: target_register,
|
||||
|
||||
@@ -1322,8 +1322,9 @@ impl Program {
|
||||
state.registers[*dest] = result;
|
||||
}
|
||||
ScalarFunc::Changes => {
|
||||
//placeholder
|
||||
state.registers[*dest] = OwnedValue::Integer(0);
|
||||
let res = &self.connection.upgrade().unwrap().last_change;
|
||||
let changes = res.get();
|
||||
state.registers[*dest] = OwnedValue::Integer(changes);
|
||||
}
|
||||
ScalarFunc::Char => {
|
||||
let reg_values =
|
||||
@@ -1534,8 +1535,9 @@ impl Program {
|
||||
state.registers[*dest] = result;
|
||||
}
|
||||
ScalarFunc::TotalChanges => {
|
||||
//placeholder
|
||||
state.registers[*dest] = OwnedValue::Integer(0);
|
||||
let res = &self.connection.upgrade().unwrap().total_changes;
|
||||
let total_changes = res.get();
|
||||
state.registers[*dest] = OwnedValue::Integer(total_changes);
|
||||
}
|
||||
ScalarFunc::UnixEpoch => {
|
||||
if *start_reg == 0 {
|
||||
@@ -1739,6 +1741,9 @@ impl Program {
|
||||
if let Some(rowid) = cursor.rowid()? {
|
||||
if let Some(conn) = self.connection.upgrade() {
|
||||
conn.update_last_rowid(rowid);
|
||||
let prev_total_changes = conn.total_changes.get();
|
||||
conn.last_change.set(1);
|
||||
conn.total_changes.set(prev_total_changes + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user