change imperative code behaviour

main
Ziyang Hu 1 year ago
parent 55a7bacb64
commit 586b50df96

@ -96,7 +96,6 @@ fn parse_imperative_stmt(
}
Rule::if_chain | Rule::if_not_chain => {
let negated = pair.as_rule() == Rule::if_not_chain;
let span = pair.extract_span();
let mut inner = pair.into_inner();
let condition = inner.next().unwrap();
let cond = match condition.as_rule() {
@ -127,7 +126,6 @@ fn parse_imperative_stmt(
then_branch: body,
else_branch: else_body,
negated,
span,
}
}
Rule::loop_block => {

@ -71,7 +71,6 @@ pub(crate) enum ImperativeStmt {
then_branch: ImperativeProgram,
else_branch: ImperativeProgram,
negated: bool,
span: SourceSpan,
},
Loop {
label: Option<SmartString<LazyCompact>>,

@ -897,11 +897,7 @@ impl<'s, S: Storage<'s>> Db<S> {
tx.store_tx.del_range_from_persisted(&lower, &upper)?;
}
if is_write {
tx.commit_tx()?;
} else {
tx.commit_tx()?;
}
tx.commit_tx()?;
}
#[cfg(not(target_arch = "wasm32"))]
if !callback_collector.is_empty() {

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

Loading…
Cancel
Save