Fix incorrect LIMIT/OFFSET parsing of form LIMIT x,y

In this case x is the OFFSET and y is the LIMIT, not the
other way around.
This commit is contained in:
Jussi Saurio
2025-09-25 15:10:14 +03:00
parent 3113822ceb
commit bb082c25f5
2 changed files with 29 additions and 8 deletions

View File

@@ -2603,16 +2603,24 @@ impl<'a> Parser<'a> {
return Ok(None);
}
let limit = self.parse_expr(0)?;
let offset = match self.peek()? {
let expr = self.parse_expr(0)?;
let (limit, offset) = match self.peek()? {
Some(tok) => match tok.token_type.unwrap() {
TK_OFFSET | TK_COMMA => {
eat_assert!(self, TK_OFFSET, TK_COMMA);
Some(self.parse_expr(0)?)
TK_COMMA => {
eat_assert!(self, TK_COMMA);
let offset = expr;
let limit = self.parse_expr(0)?;
(limit, Some(offset))
}
_ => None,
TK_OFFSET => {
eat_assert!(self, TK_OFFSET);
let limit = expr;
let offset = self.parse_expr(0)?;
(limit, Some(offset))
}
_ => (expr, None),
},
_ => None,
_ => (expr, None),
};
Ok(Some(Limit {

View File

@@ -44,4 +44,17 @@ do_execsql_test select-offset-subquery {
6|Nicholas|89
5|Edward|15
4|Jennifer|33
3|Tommy|18}
3|Tommy|18}
do_execsql_test_on_specific_db {:memory:} select-limit-comma-offset-equivalence {
CREATE TABLE nums (x INTEGER);
INSERT INTO nums VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
SELECT x FROM nums ORDER BY x LIMIT 3 OFFSET 2;
SELECT x FROM nums ORDER BY x LIMIT 2,3;
} {3
4
5
3
4
5}