2021-03-29 15:43:37 +00:00
|
|
|
use crate::dbs;
|
|
|
|
use crate::dbs::Executor;
|
2021-03-31 12:10:13 +00:00
|
|
|
use crate::dbs::Runtime;
|
2021-03-29 15:43:37 +00:00
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
2020-06-29 15:36:01 +00:00
|
|
|
use crate::sql::comment::mightbespace;
|
|
|
|
use crate::sql::comment::shouldbespace;
|
|
|
|
use crate::sql::expression::{expression, Expression};
|
2021-03-29 15:43:37 +00:00
|
|
|
use crate::sql::literal::Literal;
|
2020-06-29 15:36:01 +00:00
|
|
|
use crate::sql::param::{param, Param};
|
|
|
|
use nom::bytes::complete::tag;
|
|
|
|
use nom::bytes::complete::tag_no_case;
|
|
|
|
use nom::IResult;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::fmt;
|
|
|
|
|
2021-03-29 15:43:37 +00:00
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
2020-06-29 15:36:01 +00:00
|
|
|
pub struct SetStatement {
|
|
|
|
pub name: Param,
|
|
|
|
pub what: Expression,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for SetStatement {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "LET {} = {}", self.name, self.what)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 15:43:37 +00:00
|
|
|
impl dbs::Process for SetStatement {
|
|
|
|
fn process(
|
|
|
|
&self,
|
2021-03-31 12:10:13 +00:00
|
|
|
ctx: &Runtime,
|
2021-03-29 15:43:37 +00:00
|
|
|
exe: &Executor,
|
|
|
|
doc: Option<&Document>,
|
|
|
|
) -> Result<Literal, Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 15:36:01 +00:00
|
|
|
pub fn set(i: &str) -> IResult<&str, SetStatement> {
|
|
|
|
let (i, _) = tag_no_case("LET")(i)?;
|
|
|
|
let (i, _) = shouldbespace(i)?;
|
|
|
|
let (i, n) = param(i)?;
|
|
|
|
let (i, _) = mightbespace(i)?;
|
|
|
|
let (i, _) = tag("=")(i)?;
|
|
|
|
let (i, _) = mightbespace(i)?;
|
|
|
|
let (i, w) = expression(i)?;
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok((
|
|
|
|
i,
|
|
|
|
SetStatement {
|
|
|
|
name: n,
|
|
|
|
what: w,
|
|
|
|
},
|
|
|
|
))
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn let_statement() {
|
|
|
|
let sql = "LET $name = NULL";
|
|
|
|
let res = set(sql);
|
|
|
|
assert!(res.is_ok());
|
|
|
|
let out = res.unwrap().1;
|
|
|
|
assert_eq!("LET $name = NULL", format!("{}", out));
|
|
|
|
}
|
|
|
|
}
|