From 91c53e41888743ec2d1e1afb6d704ad58aabf23b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 14 Jan 2022 22:35:44 +0000 Subject: [PATCH] Improve empty query errors --- src/sql/parser.rs | 31 ++++++++++++++----------------- src/sql/query.rs | 4 ---- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/sql/parser.rs b/src/sql/parser.rs index 576d0850..9373ed06 100644 --- a/src/sql/parser.rs +++ b/src/sql/parser.rs @@ -5,23 +5,20 @@ use std::str; #[allow(dead_code)] pub fn parse(input: &str) -> Result { - match query(input) { - Ok((_, query)) => { - if query.empty() { - Err(Error::EmptyError) - } else { - Ok(query) - } - } - Err(Err::Error(e)) => Err(Error::ParseError { - pos: input.len() - e.input.len(), - sql: String::from(e.input), - }), - Err(Err::Failure(e)) => Err(Error::ParseError { - pos: input.len() - e.input.len(), - sql: String::from(e.input), - }), - Err(Err::Incomplete(_)) => Err(Error::EmptyError), + match input.trim().len() { + 0 => Err(Error::EmptyError), + _ => match query(input) { + Ok((_, query)) => Ok(query), + Err(Err::Error(e)) => Err(Error::ParseError { + pos: input.len() - e.input.len(), + sql: String::from(e.input), + }), + Err(Err::Failure(e)) => Err(Error::ParseError { + pos: input.len() - e.input.len(), + sql: String::from(e.input), + }), + Err(Err::Incomplete(_)) => Err(Error::EmptyError), + }, } } diff --git a/src/sql/query.rs b/src/sql/query.rs index 1ce2d252..6182be54 100644 --- a/src/sql/query.rs +++ b/src/sql/query.rs @@ -11,10 +11,6 @@ pub struct Query { } impl Query { - pub fn empty(&self) -> bool { - self.statements.len() == 0 - } - pub fn statements(&self) -> &Vec { &self.statements.0 }