2022-11-01 23:55:33 +00:00
|
|
|
use crate::cnf::PROTECTED_PARAM_NAMES;
|
2022-01-14 08:31:14 +00:00
|
|
|
use crate::ctx::Context;
|
2022-11-01 23:55:33 +00:00
|
|
|
use crate::err::Error;
|
2022-01-14 08:31:14 +00:00
|
|
|
use crate::sql::value::Value;
|
2022-06-20 01:13:28 +00:00
|
|
|
use std::collections::BTreeMap;
|
2022-01-14 08:31:14 +00:00
|
|
|
|
2022-12-30 08:23:19 +00:00
|
|
|
pub(crate) type Variables = Option<BTreeMap<String, Value>>;
|
2022-01-14 08:31:14 +00:00
|
|
|
|
|
|
|
pub(crate) trait Attach {
|
2022-11-01 23:55:33 +00:00
|
|
|
fn attach(self, ctx: Context) -> Result<Context, Error>;
|
2022-01-14 08:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Attach for Variables {
|
2022-11-01 23:55:33 +00:00
|
|
|
fn attach(self, mut ctx: Context) -> Result<Context, Error> {
|
2022-01-14 08:31:14 +00:00
|
|
|
match self {
|
|
|
|
Some(m) => {
|
|
|
|
for (key, val) in m {
|
2022-11-01 23:55:33 +00:00
|
|
|
// Check if the variable is a protected variable
|
|
|
|
match PROTECTED_PARAM_NAMES.contains(&key.as_str()) {
|
|
|
|
// The variable isn't protected and can be stored
|
|
|
|
false => ctx.add_value(key, val),
|
|
|
|
// The user tried to set a protected variable
|
|
|
|
true => {
|
|
|
|
return Err(Error::InvalidParam {
|
|
|
|
name: key,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 08:31:14 +00:00
|
|
|
}
|
2022-11-01 23:55:33 +00:00
|
|
|
Ok(ctx)
|
2022-01-14 08:31:14 +00:00
|
|
|
}
|
2022-11-01 23:55:33 +00:00
|
|
|
None => Ok(ctx),
|
2022-01-14 08:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|