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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sql): match quote and dash-dash rules in cursor statement split
kevin4778aa05b499
diff --git a/crates/dbx-sql-core/src/sql.rs b/crates/dbx-sql-core/src/sql.rsindex 701417f727..cb01535152 100644--- a/crates/dbx-sql-core/src/sql.rs+++ b/crates/dbx-sql-core/src/sql.rs@@ -1056,7 +1056,10 @@ fn split_sql_statement_ranges_with_options(sql: &str, options: SqlParsingOptions}if !in_single_quote && !in_double_quote && !in_backtick {- if ch == '-' && next == Some('-') {+ if ch == '-'+ && next == Some('-')+ && dash_dash_starts_line_comment(options.profile, next_char_at(sql, i + 2))+ {in_line_comment = true;i += 2;continue;@@ -1118,11 +1121,11 @@ fn split_sql_statement_ranges_with_options(sql: &str, options: SqlParsingOptions}match ch {- '\'' if !in_double_quote && !in_backtick && !is_escaped_single_quote(sql, i) => {+ '\'' if !in_double_quote && !in_backtick && !has_odd_trailing_backslashes(&sql[start..i]) => {in_single_quote = !in_single_quote;i += ch.len_utf8();}- '"' if !in_single_quote && !in_backtick => {+ '"' if !in_single_quote && !in_backtick && !has_odd_trailing_backslashes(&sql[start..i]) => {in_double_quote = !in_double_quote;i += ch.len_utf8();}@@ -1253,10 +1256,6 @@ fn next_char_len(sql: &str, index: usize) -> usize {next_char(sql, index).len_utf8()}-fn is_escaped_single_quote(sql: &str, index: usize) -> bool {- index > 0 && sql.as_bytes().get(index - 1) == Some(&b'\\')-}-fn is_on_delimiter_line(sql: &str, range_start: usize, index: usize, options: SqlParsingOptions) -> bool {let line_start = sql[range_start..index].rfind('\n').map_or(range_start, |pos| range_start + pos + 1);sql[line_start..index].trim_start().as_bytes().get(..9).is_some_and(|prefix| {@@ -3357,6 +3356,22 @@ mod tests {);}+ #[test]+ fn cursor_statement_closes_mysql_string_after_escaped_backslash() {+ let sql = "SELECT 'a\\\\';\nSELECT 2;";+ let cursor = sql.find("SELECT 2").unwrap() + 3;+ assert_eq!(find_statement_at_cursor_for_database(sql, cursor, DatabaseType::Mysql), "SELECT 2");+ assert_eq!(find_statement_at_cursor_for_database(sql, 3, DatabaseType::Mysql), "SELECT 'a\\\\'");+ }++ #[test]+ fn cursor_statement_treats_mysql_dash_dash_without_space_as_minus() {+ let sql = "SELECT 5--1;\nSELECT 2;";+ let cursor = sql.find("SELECT 2").unwrap() + 3;+ assert_eq!(find_statement_at_cursor_for_database(sql, cursor, DatabaseType::Mysql), "SELECT 2");+ assert_eq!(find_statement_at_cursor_for_database(sql, 3, DatabaseType::Mysql), "SELECT 5--1");+ }+#[test]fn keeps_mysql_string_open_after_odd_trailing_backslashes() {let sql = r#"INSERT INTO notes VALUES ('it\'s; still one value'); SELECT 1;"#;