Ensure advanced DEFINE PARAM
parameters are computed correctly (#3358)
This commit is contained in:
parent
650eb8ed5d
commit
f090ff3360
3 changed files with 28 additions and 5 deletions
|
@ -100,8 +100,8 @@ impl Param {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Return the value
|
||||
Ok(val.value.to_owned())
|
||||
// Return the computed value
|
||||
val.value.compute(ctx, opt, txn, doc).await
|
||||
}
|
||||
// The param has not been set globally
|
||||
Err(_) => Ok(Value::None),
|
||||
|
|
|
@ -24,10 +24,10 @@ impl DefineParamStatement {
|
|||
/// Process this type returning a computed simple Value
|
||||
pub(crate) async fn compute(
|
||||
&self,
|
||||
_ctx: &Context<'_>,
|
||||
ctx: &Context<'_>,
|
||||
opt: &Options,
|
||||
txn: &Transaction,
|
||||
_doc: Option<&CursorDoc<'_>>,
|
||||
doc: Option<&CursorDoc<'_>>,
|
||||
) -> Result<Value, Error> {
|
||||
// Allowed to run?
|
||||
opt.is_allowed(Action::Edit, ResourceKind::Parameter, &Base::Db)?;
|
||||
|
@ -35,11 +35,16 @@ impl DefineParamStatement {
|
|||
let mut run = txn.lock().await;
|
||||
// Clear the cache
|
||||
run.clear_cache();
|
||||
// Compute the param
|
||||
let val = DefineParamStatement {
|
||||
value: self.value.compute(ctx, opt, txn, doc).await?,
|
||||
..self.clone()
|
||||
};
|
||||
// Process the statement
|
||||
let key = crate::key::database::pa::new(opt.ns(), opt.db(), &self.name);
|
||||
run.add_ns(opt.ns(), opt.strict).await?;
|
||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||
run.set(key, self).await?;
|
||||
run.set(key, val).await?;
|
||||
// Ok all good
|
||||
Ok(Value::None)
|
||||
}
|
||||
|
|
|
@ -112,6 +112,24 @@ mod cli_integration {
|
|||
assert_eq!(fs::read_to_string(file).unwrap(), "Save");
|
||||
}
|
||||
|
||||
info!("* Advanced uncomputed variable to be computed before saving");
|
||||
{
|
||||
let args = format!(
|
||||
"sql --conn ws://{addr} {creds} --ns {throwaway} --db {throwaway} --multi",
|
||||
throwaway = Ulid::new()
|
||||
);
|
||||
let output = common::run(&args)
|
||||
.input(
|
||||
"DEFINE PARAM $something VALUE <set>[1, 2, 3]; \
|
||||
$something;
|
||||
",
|
||||
)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(output.contains("[1, 2, 3]"), "missing success in {output}");
|
||||
}
|
||||
|
||||
info!("* Multi-statement (and multi-line) query including error(s) over WS");
|
||||
{
|
||||
let args = format!(
|
||||
|
|
Loading…
Reference in a new issue