Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(sql): handle comment-only SQL files

lewisc180c40b3654
diff --git a/crates/dbx-core/src/sql.rs b/crates/dbx-core/src/sql.rs
index 72f6aece08..e6dd8a744e 100644
--- a/crates/dbx-core/src/sql.rs
+++ b/crates/dbx-core/src/sql.rs
@@ -1888,6 +1888,10 @@ fn leading_executable_sql_with_options(sql: &str, options: SqlParsingOptions) ->
i += 1;
}
+ if i >= bytes.len() {
+ break;
+ }
+
if i + 1 < bytes.len() && bytes[i] == b'-' && bytes[i + 1] == b'-' {
i += 2;
while i < bytes.len() && bytes[i] != b'\n' {
@@ -1931,6 +1935,10 @@ fn first_executable_sql_token_with_options(sql: &str, options: SqlParsingOptions
i += 1;
}
+ if i >= bytes.len() {
+ break;
+ }
+
if i + 1 < bytes.len() && bytes[i] == b'-' && bytes[i + 1] == b'-' {
i += 2;
while i < bytes.len() && bytes[i] != b'\n' {
@@ -2419,6 +2427,21 @@ mod tests {
);
}
+ #[test]
+ fn mysql_split_skips_comment_only_statement() {
+ assert!(split_sql_statements_for_database("-- DBX SQL preview crash reproducer\n\n;", DatabaseType::Mysql)
+ .is_empty());
+ }
+
+ #[test]
+ fn mysql_keyword_detection_skips_comment_only_input() {
+ assert!(!starts_with_executable_sql_keyword_for_database(
+ "-- DBX SQL preview crash reproducer\n\n",
+ &["SELECT"],
+ DatabaseType::Mysql,
+ ));
+ }
+
#[test]
fn decodes_utf8_bom_sql_file_bytes_without_bom_statement_prefix() {
let sql = decode_sql_file_bytes(b"\xEF\xBB\xBFCREATE TABLE t(id int);").unwrap();