Skip to content

Commit ddad1e9

Browse files
committed
Include the trailing semicolon in sql queries sent to the database
Fixes #318
1 parent b2f646a commit ddad1e9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- In short, if you saw an error like `Error: unrecognized token ":"` after upgrading to 0.20.5, this version should fix it.
1414
- The `dynamic` component now properly displays error messages when its properties are invalid. There used to be a bug where errors would be silently ignored, making it hard to debug invalid dynamic components.
1515
- New [`sqlpage.request_method`](https://sql.ophir.dev/functions.sql?function=request_method#function) function to get the HTTP method used to access the current page. This is useful to create pages that behave differently depending on whether they are accessed with a GET request (to display a form, for instance) or a POST request (to process the form).
16+
- include the trailing semicolon as a part of the SQL statement sent to the database. This doesn't change anything in most databases, but Microsoft SQL Server requires a trailing semicolon after certain statements, such as `MERGE`. Fixes [issue #318](https://github.com/lovasoa/SQLpage/issues/318)
1617

1718
## 0.20.5 (2024-05-07)
1819

src/webserver/database/sql.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ fn parse_single_statement(parser: &mut Parser<'_>, db_kind: AnyKind) -> Option<P
9999
Err(err) => return Some(syntax_error(err, parser)),
100100
};
101101
log::debug!("Parsed statement: {stmt}");
102-
while parser.consume_token(&SemiColon) {}
102+
let mut semicolon = false;
103+
while parser.consume_token(&SemiColon) {
104+
semicolon = true;
105+
}
103106
let params = ParameterExtractor::extract_parameters(&mut stmt, db_kind);
104107
if let Some((variable, query)) = extract_set_variable(&mut stmt) {
105108
return Some(ParsedStatement::SetVariable {
@@ -114,7 +117,10 @@ fn parse_single_statement(parser: &mut Parser<'_>, db_kind: AnyKind) -> Option<P
114117
log::debug!("Optimised a static simple select to avoid a trivial database query: {stmt} optimized to {static_statement:?}");
115118
return Some(ParsedStatement::StaticSimpleSelect(static_statement));
116119
}
117-
let query = stmt.to_string();
120+
let query = format!(
121+
"{stmt}{semicolon}",
122+
semicolon = if semicolon { ";" } else { "" }
123+
);
118124
log::debug!("Final transformed statement: {stmt}");
119125
Some(ParsedStatement::StmtWithParams(StmtWithParams {
120126
query,

0 commit comments

Comments
 (0)