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)]
pub fn parse(input: &str) -> Result<Query, Error> {
match query(input) {
Ok((_, query)) => {
if query.empty() {
Err(Error::EmptyError)
} else {
Ok(query)
}
}
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),
@ -22,6 +18,7 @@ pub fn parse(input: &str) -> Result<Query, Error> {
sql: String::from(e.input),
}),
Err(Err::Incomplete(_)) => Err(Error::EmptyError),
},
}
}

View file

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