From 613f99ff9ae59c1b77f789c7a02fc72095c44526 Mon Sep 17 00:00:00 2001 From: step-baby <3528004749@qq.com> Date: Tue, 10 May 2022 17:59:39 +0800 Subject: [PATCH 1/4] fix: limit $1 --- Cargo.toml | 4 ++-- src/parser.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 94fd9f394..05a42faeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,10 +3,10 @@ name = "sqlparser" description = "Extensible SQL Lexer and Parser with support for ANSI SQL:2011" version = "0.16.0" authors = ["Andy Grove "] -homepage = "https://github.com/sqlparser-rs/sqlparser-rs" +#homepage = "https://github.com/sqlparser-rs/sqlparser-rs" documentation = "https://docs.rs/sqlparser/" keywords = [ "ansi", "sql", "lexer", "parser" ] -repository = "https://github.com/sqlparser-rs/sqlparser-rs" +#repository = "https://github.com/sqlparser-rs/sqlparser-rs" license = "Apache-2.0" include = [ "src/**/*.rs", diff --git a/src/parser.rs b/src/parser.rs index 1caf2f2c6..9f4ef5d83 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2563,6 +2563,7 @@ impl<'a> Parser<'a> { pub fn parse_number_value(&mut self) -> Result { match self.parse_value()? { v @ Value::Number(_, _) => Ok(v), + v @ Value::Placeholder(_) => Ok(v), _ => { self.prev_token(); self.expected("literal number", self.peek_token()) From 008f7e8b55c54c522776f0344aab1cfb8e0d88b3 Mon Sep 17 00:00:00 2001 From: step-baby <3528004749@qq.com> Date: Wed, 11 May 2022 11:27:02 +0800 Subject: [PATCH 2/4] feat: test limit $1 --- src/parser.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 9f4ef5d83..36e40b7a1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4300,7 +4300,7 @@ impl Word { #[cfg(test)] mod tests { use super::*; - use crate::test_utils::all_dialects; + use crate::test_utils::{all_dialects, TestedDialects}; #[test] fn test_prev_index() { @@ -4322,4 +4322,40 @@ mod tests { parser.prev_token(); }); } + + #[test] + fn test_parse_limit() { + let sql = "SELECT * FROM user LIMIT 1"; + all_dialects().run_parser_method(sql, |parser| { + let ast = parser.parse_query().unwrap(); + assert_eq!(ast.to_string(), sql.to_string()); + }); + + let sql = "SELECT * FROM user LIMIT $1 OFFSET $2"; + let dialects = TestedDialects { + dialects: vec![ + Box::new(PostgreSqlDialect {}), + Box::new(ClickHouseDialect {}), + Box::new(GenericDialect {}), + Box::new(MsSqlDialect {}), + Box::new(SnowflakeDialect {}), + ], + }; + + dialects.run_parser_method(sql, |parser| { + let ast = parser.parse_query().unwrap(); + assert_eq!(ast.to_string(), sql.to_string()); + }); + + let sql = "SELECT * FROM user LIMIT ? OFFSET ?"; + let dialects = TestedDialects { + dialects: vec![ + Box::new(MySqlDialect {}), + ], + }; + dialects.run_parser_method(sql, |parser| { + let ast = parser.parse_query().unwrap(); + assert_eq!(ast.to_string(), sql.to_string()); + }); + } } From af135771b76f07f314d9c55af06f0ee5256e1ee3 Mon Sep 17 00:00:00 2001 From: mao <50707849+step-baby@users.noreply.github.com> Date: Wed, 11 May 2022 11:43:42 +0800 Subject: [PATCH 3/4] Update Cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 05a42faeb..94fd9f394 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,10 +3,10 @@ name = "sqlparser" description = "Extensible SQL Lexer and Parser with support for ANSI SQL:2011" version = "0.16.0" authors = ["Andy Grove "] -#homepage = "https://github.com/sqlparser-rs/sqlparser-rs" +homepage = "https://github.com/sqlparser-rs/sqlparser-rs" documentation = "https://docs.rs/sqlparser/" keywords = [ "ansi", "sql", "lexer", "parser" ] -#repository = "https://github.com/sqlparser-rs/sqlparser-rs" +repository = "https://github.com/sqlparser-rs/sqlparser-rs" license = "Apache-2.0" include = [ "src/**/*.rs", From 5d362fbd2f826391cc61fd7e4cb26e0fe5260010 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Sun, 22 May 2022 15:30:06 -0400 Subject: [PATCH 4/4] cargo fmt --- src/parser.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 36e40b7a1..8aae5092e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4349,9 +4349,7 @@ mod tests { let sql = "SELECT * FROM user LIMIT ? OFFSET ?"; let dialects = TestedDialects { - dialects: vec![ - Box::new(MySqlDialect {}), - ], + dialects: vec![Box::new(MySqlDialect {})], }; dialects.run_parser_method(sql, |parser| { let ast = parser.parse_query().unwrap();