Improve empty query errors

This commit is contained in:
Tobie Morgan Hitchcock 2022-01-14 22:35:44 +00:00
parent 3dcedc20e8
commit 91c53e4188
2 changed files with 14 additions and 21 deletions

View file

@ -5,14 +5,10 @@ use std::str;
#[allow(dead_code)] #[allow(dead_code)]
pub fn parse(input: &str) -> Result<Query, Error> { pub fn parse(input: &str) -> Result<Query, Error> {
match query(input) { match input.trim().len() {
Ok((_, query)) => { 0 => Err(Error::EmptyError),
if query.empty() { _ => match query(input) {
Err(Error::EmptyError) Ok((_, query)) => Ok(query),
} else {
Ok(query)
}
}
Err(Err::Error(e)) => Err(Error::ParseError { Err(Err::Error(e)) => Err(Error::ParseError {
pos: input.len() - e.input.len(), pos: input.len() - e.input.len(),
sql: String::from(e.input), sql: String::from(e.input),
@ -22,6 +18,7 @@ pub fn parse(input: &str) -> Result<Query, Error> {
sql: String::from(e.input), sql: String::from(e.input),
}), }),
Err(Err::Incomplete(_)) => Err(Error::EmptyError), Err(Err::Incomplete(_)) => Err(Error::EmptyError),
},
} }
} }

View file

@ -11,10 +11,6 @@ pub struct Query {
} }
impl Query { impl Query {
pub fn empty(&self) -> bool {
self.statements.len() == 0
}
pub fn statements(&self) -> &Vec<Statement> { pub fn statements(&self) -> &Vec<Statement> {
&self.statements.0 &self.statements.0
} }