|
|
@ -15,14 +15,12 @@ use miette::{bail, Diagnostic, Report, Result};
|
|
|
|
use smartstring::{LazyCompact, SmartString};
|
|
|
|
use smartstring::{LazyCompact, SmartString};
|
|
|
|
use thiserror::Error;
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::data::expr::PredicateTypeError;
|
|
|
|
|
|
|
|
use crate::data::functions::op_to_bool;
|
|
|
|
|
|
|
|
use crate::data::symb::Symbol;
|
|
|
|
use crate::data::symb::Symbol;
|
|
|
|
use crate::parse::{ImperativeCondition, ImperativeProgram, ImperativeStmt, SourceSpan};
|
|
|
|
use crate::parse::{ImperativeCondition, ImperativeProgram, ImperativeStmt, SourceSpan};
|
|
|
|
use crate::runtime::callback::CallbackCollector;
|
|
|
|
use crate::runtime::callback::CallbackCollector;
|
|
|
|
|
|
|
|
use crate::runtime::db::{seconds_since_the_epoch, RunningQueryCleanup, RunningQueryHandle};
|
|
|
|
use crate::runtime::transact::SessionTx;
|
|
|
|
use crate::runtime::transact::SessionTx;
|
|
|
|
use crate::{DataValue, Db, NamedRows, Poison, Storage, ValidityTs};
|
|
|
|
use crate::{DataValue, Db, NamedRows, Poison, Storage, ValidityTs};
|
|
|
|
use crate::runtime::db::{RunningQueryCleanup, RunningQueryHandle, seconds_since_the_epoch};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum ControlCode {
|
|
|
|
enum ControlCode {
|
|
|
|
Termination(NamedRows),
|
|
|
|
Termination(NamedRows),
|
|
|
@ -37,7 +35,6 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
tx: &mut SessionTx<'_>,
|
|
|
|
tx: &mut SessionTx<'_>,
|
|
|
|
cleanups: &mut Vec<(Vec<u8>, Vec<u8>)>,
|
|
|
|
cleanups: &mut Vec<(Vec<u8>, Vec<u8>)>,
|
|
|
|
cur_vld: ValidityTs,
|
|
|
|
cur_vld: ValidityTs,
|
|
|
|
span: SourceSpan,
|
|
|
|
|
|
|
|
callback_targets: &BTreeSet<SmartString<LazyCompact>>,
|
|
|
|
callback_targets: &BTreeSet<SmartString<LazyCompact>>,
|
|
|
|
callback_collector: &mut CallbackCollector,
|
|
|
|
callback_collector: &mut CallbackCollector,
|
|
|
|
) -> Result<bool> {
|
|
|
|
) -> Result<bool> {
|
|
|
@ -55,18 +52,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
callback_collector,
|
|
|
|
callback_collector,
|
|
|
|
)?,
|
|
|
|
)?,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Ok(match res.rows.first() {
|
|
|
|
Ok(!res.rows.is_empty())
|
|
|
|
None => false,
|
|
|
|
|
|
|
|
Some(row) => {
|
|
|
|
|
|
|
|
if row.is_empty() {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
op_to_bool(&row[row.len() - 1..])?
|
|
|
|
|
|
|
|
.get_bool()
|
|
|
|
|
|
|
|
.ok_or_else(|| PredicateTypeError(span, row.last().cloned().unwrap()))?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn execute_imperative_stmts(
|
|
|
|
fn execute_imperative_stmts(
|
|
|
@ -77,7 +63,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
cur_vld: ValidityTs,
|
|
|
|
cur_vld: ValidityTs,
|
|
|
|
callback_targets: &BTreeSet<SmartString<LazyCompact>>,
|
|
|
|
callback_targets: &BTreeSet<SmartString<LazyCompact>>,
|
|
|
|
callback_collector: &mut CallbackCollector,
|
|
|
|
callback_collector: &mut CallbackCollector,
|
|
|
|
poison: &Poison
|
|
|
|
poison: &Poison,
|
|
|
|
) -> Result<Either<NamedRows, ControlCode>> {
|
|
|
|
) -> Result<Either<NamedRows, ControlCode>> {
|
|
|
|
let mut ret = NamedRows::default();
|
|
|
|
let mut ret = NamedRows::default();
|
|
|
|
for p in ps {
|
|
|
|
for p in ps {
|
|
|
@ -151,15 +137,14 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
condition,
|
|
|
|
condition,
|
|
|
|
then_branch,
|
|
|
|
then_branch,
|
|
|
|
else_branch,
|
|
|
|
else_branch,
|
|
|
|
span,
|
|
|
|
|
|
|
|
negated,
|
|
|
|
negated,
|
|
|
|
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
} => {
|
|
|
|
let cond_val = self.execute_imperative_condition(
|
|
|
|
let cond_val = self.execute_imperative_condition(
|
|
|
|
condition,
|
|
|
|
condition,
|
|
|
|
tx,
|
|
|
|
tx,
|
|
|
|
cleanups,
|
|
|
|
cleanups,
|
|
|
|
cur_vld,
|
|
|
|
cur_vld,
|
|
|
|
*span,
|
|
|
|
|
|
|
|
callback_targets,
|
|
|
|
callback_targets,
|
|
|
|
callback_collector,
|
|
|
|
callback_collector,
|
|
|
|
)?;
|
|
|
|
)?;
|
|
|
@ -172,7 +157,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
cur_vld,
|
|
|
|
cur_vld,
|
|
|
|
callback_targets,
|
|
|
|
callback_targets,
|
|
|
|
callback_collector,
|
|
|
|
callback_collector,
|
|
|
|
poison
|
|
|
|
poison,
|
|
|
|
)? {
|
|
|
|
)? {
|
|
|
|
Left(rows) => {
|
|
|
|
Left(rows) => {
|
|
|
|
ret = rows;
|
|
|
|
ret = rows;
|
|
|
@ -192,7 +177,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
cur_vld,
|
|
|
|
cur_vld,
|
|
|
|
callback_targets,
|
|
|
|
callback_targets,
|
|
|
|
callback_collector,
|
|
|
|
callback_collector,
|
|
|
|
poison
|
|
|
|
poison,
|
|
|
|
)? {
|
|
|
|
)? {
|
|
|
|
Left(_) => {}
|
|
|
|
Left(_) => {}
|
|
|
|
Right(ctrl) => match ctrl {
|
|
|
|
Right(ctrl) => match ctrl {
|
|
|
@ -286,7 +271,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
cur_vld,
|
|
|
|
cur_vld,
|
|
|
|
&callback_targets,
|
|
|
|
&callback_targets,
|
|
|
|
&mut callback_collector,
|
|
|
|
&mut callback_collector,
|
|
|
|
&poison
|
|
|
|
&poison,
|
|
|
|
)? {
|
|
|
|
)? {
|
|
|
|
Left(res) => ret = res,
|
|
|
|
Left(res) => ret = res,
|
|
|
|
Right(ctrl) => match ctrl {
|
|
|
|
Right(ctrl) => match ctrl {
|
|
|
@ -308,11 +293,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
tx.store_tx.del_range_from_persisted(&lower, &upper)?;
|
|
|
|
tx.store_tx.del_range_from_persisted(&lower, &upper)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if is_write {
|
|
|
|
|
|
|
|
tx.commit_tx()?;
|
|
|
|
tx.commit_tx()?;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tx.commit_tx()?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
if !callback_collector.is_empty() {
|
|
|
|
if !callback_collector.is_empty() {
|
|
|
|