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(mysql): stop crash on repeated DELIMITER directives
zipg5076569a0e5f
diff --git a/crates/dbx-core/tests/live_mysql57.rs b/crates/dbx-core/tests/live_mysql57.rsindex 5647d76939..2f13313386 100644--- a/crates/dbx-core/tests/live_mysql57.rs+++ b/crates/dbx-core/tests/live_mysql57.rs@@ -836,6 +836,67 @@ DROP PROCEDURE IF EXISTS {procedure};"cleanup.unwrap();}+#[tokio::test]+#[ignore = "requires DBX_LIVE_SQL_FILE_MYSQL_* env vars pointing at a writable MySQL connection"]+async fn live_mysql_repeated_delimiter_executes_original_user_script() {+ let suffix = uuid::Uuid::new_v4().simple().to_string();+ let config = live_mysql_sql_file_config(&format!("live-mysql-repeated-delimiter-{suffix}"));+ let (state, db_path) = app_state_with_config(config.clone()).await;+ let database = format!("dbx_repeated_delimiter_{suffix}");+ let sql = "\+DELIMITER ;;+drop procedure if exists p_ludp_data_table_scripts;;+delimiter ;;+create procedure p_ludp_data_table_scripts()+begin+ -- 定义变量,存储表及字段存在状态+ declare filedExist INT DEFAULT 0;+ declare currentDatabaseName VARCHAR(200) DEFAULT '';+ declare tableCount INT DEFAULT 0;++end ;;+call p_ludp_data_table_scripts();";++ let execution = async {+ execute_sql_statement(&state, &config.id, "", &format!("CREATE DATABASE `{database}`"), None, None).await?;+ let results = execute_multi_core(&state, &config.id, &database, sql, None, None).await?;+ assert_eq!(results.len(), 3);+ for result in &results {+ assert_ne!(result.columns, vec!["Error"], "script failed: {result:?}");+ }++ let source = execute_sql_statement(+ &state,+ &config.id,+ &database,+ "SHOW CREATE PROCEDURE p_ludp_data_table_scripts",+ None,+ None,+ )+ .await?;+ assert_eq!(source.rows.len(), 1);++ // Exercise the same UTF-16 cursor lookup used by the desktop command,+ // then execute the extracted routine against the live server.+ let cursor = sql[..sql.find("declare currentDatabaseName").unwrap()].encode_utf16().count();+ let current = dbx_core::sql::find_statement_at_cursor_for_database(sql, cursor, DatabaseType::Mysql);+ assert!(current.starts_with("create procedure"));+ execute_sql_statement(&state, &config.id, &database, "DROP PROCEDURE p_ludp_data_table_scripts", None, None)+ .await?;+ execute_sql_statement(&state, &config.id, &database, ¤t, None, None).await?;+ execute_sql_statement(&state, &config.id, &database, "CALL p_ludp_data_table_scripts()", None, None).await?;+ Ok::<_, String>(())+ }+ .await;++ let cleanup =+ execute_sql_statement(&state, &config.id, "", &format!("DROP DATABASE IF EXISTS `{database}`"), None, None)+ .await;+ let _ = std::fs::remove_file(db_path);+ cleanup.expect("remove isolated test database");+ execution.expect("original repeated DELIMITER script and cursor execution should succeed");+}+#[tokio::test]#[ignore = "requires a remote OceanBase MySQL-compatible endpoint"]async fn live_oceanbase_mysql_setup_applies_query_timeout() {diff --git a/crates/dbx-sql-core/src/sql.rs b/crates/dbx-sql-core/src/sql.rsindex d825b37c0d..19faaf252b 100644--- a/crates/dbx-sql-core/src/sql.rs+++ b/crates/dbx-sql-core/src/sql.rs@@ -883,7 +883,12 @@ impl SqlStatementSplitter {}}if let Some(delim) = self.custom_delimiter.clone() {- if self.buffer.ends_with(delim.as_str()) {+ // A DELIMITER command can itself end with the active+ // delimiter (for example `DELIMITER ;;`). Keep the+ // directive intact so the newline handler can switch the+ // delimiter instead of emitting a bogus `delimiter`+ // statement or advancing past the line start.+ if self.buffer.ends_with(delim.as_str()) && !self.on_delimiter_line() {self.buffer.truncate(self.buffer.len() - delim.len());self.push_current_statement(&mut statements);}@@ -1467,7 +1472,7 @@ fn split_sql_statement_ranges_with_options(sql: &str, options: SqlParsingOptionsi += ch.len_utf8();if !in_single_quote && !in_double_quote && !in_backtick {if let Some(delimiter) = &custom_delimiter {- if sql[start..i].ends_with(delimiter) {+ if sql[start..i].ends_with(delimiter) && !is_on_delimiter_line(sql, start, i, options) {let end = i - delimiter.len();push_statement_range(&mut ranges, sql, start, end, options);start = i;@@ -6017,6 +6022,45 @@ delimiter ;";);}+ #[test]+ fn mysql_repeated_delimiter_command_does_not_emit_directive_or_panic() {+ let sql = r#"DELIMITER ;;+drop procedure if exists p_ludp_data_table_scripts;;+delimiter ;;+create procedure p_ludp_data_table_scripts()+begin+ -- 定义变量,存储表及字段存在状态+ declare filedExist INT DEFAULT 0;+ declare currentDatabaseName VARCHAR(200) DEFAULT '';+ declare tableCount INT DEFAULT 0;++end ;;+call p_ludp_data_table_scripts();"#;++ let expected = vec![+ "drop procedure if exists p_ludp_data_table_scripts",+ "create procedure p_ludp_data_table_scripts()\nbegin\n -- 定义变量,存储表及字段存在状态\n declare filedExist INT DEFAULT 0;\n declare currentDatabaseName VARCHAR(200) DEFAULT '';\n declare tableCount INT DEFAULT 0;\n\nend",+ "call p_ludp_data_table_scripts();",+ ];+ assert_eq!(split_sql_statements_for_database(sql, DatabaseType::Mysql), expected);++ let ranges =+ split_sql_statement_ranges_with_options(sql, SqlParsingOptions::for_database_type(DatabaseType::Mysql));+ assert_eq!(ranges.iter().map(|range| range.text.as_str()).collect::<Vec<_>>(), expected);++ let cursor = sql[..sql.find("declare currentDatabaseName").unwrap()].encode_utf16().count();+ assert_eq!(find_statement_at_cursor_for_database(sql, cursor, DatabaseType::Mysql), expected[1]);++ let mut splitter =+ SqlStatementSplitter::with_options(SqlParsingOptions::for_database_type(DatabaseType::Mysql));+ let mut streamed = Vec::new();+ for ch in sql.chars() {+ streamed.extend(splitter.push_chunk(&ch.to_string()));+ }+ streamed.extend(splitter.finish());+ assert_eq!(streamed, expected);+ }+#[test]fn mysql_delimiter_command_skips_empty_custom_delimiter_statement_per_issue_1988() {let sql = "\