Skip to content

Commit 76649e4

Browse files
committed
update sql parser
1 parent df8cd48 commit 76649e4

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ This is a bugfix release.
77
- Fix a bug where the form component would not display the right checked state in radio buttons and checkboxes.
88
- https://github.com/sqlpage/SQLPage/issues/751
99
- Fix a bug in the [link](https://sql-page.com/component.sql?component=link) component where the properties `view_link`, `edit_link`, and `delete_link` had become incompatible with the main `link` property.
10+
- Updated sqlparser to [v0.53](https://github.com/apache/datafusion-sqlparser-rs/blob/main/changelog/0.53.0.md) which fixes parse errors when using some advanced SQL syntax
11+
- adds support for SQLite's `UPDATE OR REPLACE` syntax
12+
- adds support for MSSQL's `JSON_ARRAY` and `JSON_OBJECT` functions
13+
- adds support for PostgreSQL's `JSON_OBJECT(key : value)` and `JSON_OBJECT(key VALUE value)` syntax
1014

1115
## 0.32.0 (2024-12-29)
1216

Cargo.lock

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ anyhow = "1"
4242
serde = "1"
4343
serde_json = { version = "1.0.82", features = ["preserve_order", "raw_value"] }
4444
lambda-web = { version = "0.2.1", features = ["actix4"], optional = true }
45-
sqlparser = { version = "0.52.0", features = ["visitor"] }
45+
sqlparser = { version = "0.53.0", features = ["visitor"] }
4646
async-stream = "0.3"
4747
async-trait = "0.1.61"
4848
async-recursion = "1.0.0"

src/webserver/database/sql.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ use crate::file_cache::AsyncFromStrWithState;
66
use crate::webserver::database::error_highlighting::quote_source_with_highlight;
77
use crate::{AppState, Database};
88
use async_trait::async_trait;
9+
use sqlparser::ast::helpers::attached_token::AttachedToken;
910
use sqlparser::ast::{
1011
BinaryOperator, CastKind, CharacterLength, DataType, Expr, Function, FunctionArg,
1112
FunctionArgExpr, FunctionArgumentList, FunctionArguments, Ident, ObjectName,
12-
OneOrManyWithParens, SelectItem, SetExpr, Statement, Value, VisitMut, VisitorMut,
13+
OneOrManyWithParens, SelectItem, SetExpr, Spanned, Statement, Value, VisitMut, VisitorMut,
1314
};
1415
use sqlparser::dialect::{Dialect, MsSqlDialect, MySqlDialect, PostgreSqlDialect, SQLiteDialect};
1516
use sqlparser::parser::{Parser, ParserError};
16-
use sqlparser::tokenizer::Token::{SemiColon, EOF};
17-
use sqlparser::tokenizer::Tokenizer;
17+
use sqlparser::tokenizer::Token::{self, SemiColon, EOF};
18+
use sqlparser::tokenizer::{TokenWithSpan, Tokenizer};
1819
use sqlx::any::AnyKind;
1920
use std::ops::ControlFlow;
2021
use std::path::{Path, PathBuf};
@@ -171,10 +172,10 @@ fn parse_single_statement(
171172
}
172173

173174
fn syntax_error(err: ParserError, parser: &Parser, sql: &str) -> ParsedStatement {
174-
let location = parser.peek_token_no_skip().location;
175+
let location = parser.peek_token_no_skip().span;
175176
ParsedStatement::Error(anyhow::Error::from(err).context(format!(
176177
"Parsing failed: SQLPage couldn't understand the SQL file. Please check for syntax errors:\n\n{}",
177-
quote_source_with_highlight(sql, location.line, location.column)
178+
quote_source_with_highlight(sql, location.start.line, location.start.column)
178179
)))
179180
}
180181

@@ -769,6 +770,7 @@ impl VisitorMut for ParameterExtractor {
769770
filter: None,
770771
null_treatment: None,
771772
within_group: Vec::new(),
773+
uses_odbc_syntax: false,
772774
});
773775
}
774776
Expr::Cast {
@@ -884,6 +886,10 @@ fn expr_to_statement(expr: Expr) -> Statement {
884886
with: None,
885887
body: Box::new(sqlparser::ast::SetExpr::Select(Box::new(
886888
sqlparser::ast::Select {
889+
select_token: AttachedToken(TokenWithSpan::new(
890+
Token::make_keyword("SELECT"),
891+
expr.span(),
892+
)),
887893
distinct: None,
888894
top: None,
889895
projection: vec![SelectItem::ExprWithAlias {

0 commit comments

Comments
 (0)