diff --git a/src/dbs/iterator.rs b/src/dbs/iterator.rs index 41243263..c3c26eee 100644 --- a/src/dbs/iterator.rs +++ b/src/dbs/iterator.rs @@ -208,11 +208,11 @@ impl<'a> Iterator<'a> { if let Some(l) = self.limit { if let Some(s) = self.start { - if self.results.len() as u64 == l.0 + s.0 { + if self.results.len() == l.0 + s.0 { self.ok = false } } else { - if self.results.len() as u64 == l.0 { + if self.results.len() == l.0 { self.ok = false } } diff --git a/src/sql/common.rs b/src/sql/common.rs index 113eb495..d00d3038 100644 --- a/src/sql/common.rs +++ b/src/sql/common.rs @@ -41,6 +41,11 @@ pub fn to_u64(s: &str) -> u64 { str::FromStr::from_str(s).unwrap() } +#[inline] +pub fn to_usize(s: &str) -> usize { + str::FromStr::from_str(s).unwrap() +} + #[inline] pub fn val_char(chr: char) -> bool { is_alphanumeric(chr as u8) || chr == '_' as char @@ -66,6 +71,11 @@ pub fn take_u64(i: &str) -> IResult<&str, u64> { Ok((i, v)) } +pub fn take_usize(i: &str) -> IResult<&str, usize> { + let (i, v) = map(take_while(is_digit), to_usize)(i)?; + Ok((i, v)) +} + pub fn take_digits(i: &str, n: usize) -> IResult<&str, u32> { let (i, v) = map(take_while_m_n(n, n, is_digit), to_u32)(i)?; Ok((i, v)) diff --git a/src/sql/limit.rs b/src/sql/limit.rs index 5ceadb53..39089faa 100644 --- a/src/sql/limit.rs +++ b/src/sql/limit.rs @@ -1,5 +1,5 @@ use crate::sql::comment::shouldbespace; -use crate::sql::common::take_u64; +use crate::sql::common::take_usize; use crate::sql::error::IResult; use nom::bytes::complete::tag_no_case; use nom::combinator::opt; @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] -pub struct Limit(pub u64); +pub struct Limit(pub usize); impl fmt::Display for Limit { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -20,7 +20,7 @@ pub fn limit(i: &str) -> IResult<&str, Limit> { let (i, _) = tag_no_case("LIMIT")(i)?; let (i, _) = opt(tuple((shouldbespace, tag_no_case("BY"))))(i)?; let (i, _) = shouldbespace(i)?; - let (i, v) = take_u64(i)?; + let (i, v) = take_usize(i)?; Ok((i, Limit(v))) } diff --git a/src/sql/start.rs b/src/sql/start.rs index c7c1d838..b0dbb9d5 100644 --- a/src/sql/start.rs +++ b/src/sql/start.rs @@ -1,5 +1,5 @@ use crate::sql::comment::shouldbespace; -use crate::sql::common::take_u64; +use crate::sql::common::take_usize; use crate::sql::error::IResult; use nom::bytes::complete::tag_no_case; use nom::combinator::opt; @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] -pub struct Start(pub u64); +pub struct Start(pub usize); impl fmt::Display for Start { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -20,7 +20,7 @@ pub fn start(i: &str) -> IResult<&str, Start> { let (i, _) = tag_no_case("START")(i)?; let (i, _) = opt(tuple((shouldbespace, tag_no_case("AT"))))(i)?; let (i, _) = shouldbespace(i)?; - let (i, v) = take_u64(i)?; + let (i, v) = take_usize(i)?; Ok((i, Start(v))) } diff --git a/src/sql/statements/select.rs b/src/sql/statements/select.rs index 7df229d9..b7c41920 100644 --- a/src/sql/statements/select.rs +++ b/src/sql/statements/select.rs @@ -48,13 +48,13 @@ pub struct SelectStatement { } impl SelectStatement { - pub fn limit(&self) -> u64 { + pub fn limit(&self) -> usize { match self.limit { Some(Limit(v)) => v, None => 0, } } - pub fn start(&self) -> u64 { + pub fn start(&self) -> usize { match self.start { Some(Start(v)) => v, None => 0,