Use usize for START and LIMIT clauses
This commit is contained in:
parent
f8848e36f5
commit
e153c791f3
5 changed files with 20 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue