fix(query): skip comment-only SQL execution

This commit is contained in:
t8y2 committed 2026-06-15 14:18:40 +08:00
1 parent 7bb869d398
commit a32ead56b9
2 files changed
+40 -1

No files matched your search

+14 -1
View File
@@ -1585,10 +1585,14 @@ fn dollar_quote_tag_at(chars: &[char], start: usize) -> Option<String> {
None
}
fn has_executable_sql(statement: &str) -> bool {
pub fn has_executable_sql(statement: &str) -> bool {
has_executable_sql_with_options(statement, SqlParsingOptions::default())
}
pub fn has_executable_sql_for_database(statement: &str, db_type: DatabaseType) -> bool {
has_executable_sql_with_options(statement, SqlParsingOptions::for_database_type(db_type))
}
fn executable_sql_bounds(statement: &str, options: SqlParsingOptions) -> Option<(usize, usize)> {
let trimmed_end = statement.trim_end().len();
let trimmed = &statement[..trimmed_end];
@@ -1771,6 +1775,15 @@ mod tests {
);
}
#[test]
fn skips_comment_only_statement_with_semicolon() {
assert_eq!(
split_sql_script("-- insert sqluser.tb_a values (6,'006','测试6','无');").unwrap(),
Vec::<String>::new()
);
assert!(!super::has_executable_sql("-- insert sqluser.tb_a values (6,'006','测试6','无');"));
}
#[test]
fn keeps_postgres_dollar_quoted_function_body_together() {
let sql = "\