From 6d622badc3bc09d1b9bc91d557fcc8dd411efd72 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 9 Feb 2022 08:57:34 +0000 Subject: [PATCH] Check if record actually exists when selecting --- src/doc/empty.rs | 22 ++++++++++++++++++++++ src/doc/mod.rs | 1 + src/doc/select.rs | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 src/doc/empty.rs diff --git a/src/doc/empty.rs b/src/doc/empty.rs new file mode 100644 index 00000000..e7ef4c72 --- /dev/null +++ b/src/doc/empty.rs @@ -0,0 +1,22 @@ +use crate::dbs::Executor; +use crate::dbs::Options; +use crate::dbs::Runtime; +use crate::dbs::Statement; +use crate::doc::Document; +use crate::err::Error; +use crate::sql::value::Value; + +impl Document { + pub async fn empty( + &self, + _ctx: &Runtime, + _opt: &Options, + _exe: &Executor<'_>, + _stm: &Statement<'_>, + ) -> Result<(), Error> { + match self.id.is_some() && self.current == Value::None { + true => Err(Error::IgnoreError), + false => Ok(()), + } + } +} diff --git a/src/doc/mod.rs b/src/doc/mod.rs index 6e9d6435..dc7289b7 100644 --- a/src/doc/mod.rs +++ b/src/doc/mod.rs @@ -7,6 +7,7 @@ mod compute; mod create; mod delete; mod document; +mod empty; mod erase; mod event; mod grant; diff --git a/src/doc/select.rs b/src/doc/select.rs index f6087b8a..eec7bd05 100644 --- a/src/doc/select.rs +++ b/src/doc/select.rs @@ -14,6 +14,8 @@ impl Document { exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { + // Check if record exists + self.empty(ctx, opt, exe, stm).await?; // Check where clause self.check(ctx, opt, exe, stm).await?; // Check if allowed