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。

feat(mysql): append semicolon to table DDL

t8y2d65b0e554831
diff --git a/crates/dbx-core/src/schema.rs b/crates/dbx-core/src/schema.rs
index 9aa835e321..0c798485a8 100644
--- a/crates/dbx-core/src/schema.rs
+++ b/crates/dbx-core/src/schema.rs
@@ -4891,6 +4891,23 @@ mod ddl_tests {
"SELECT pg_get_tabledef('\"tenant''s schema\".\"active users\"')"
);
}
+
+ #[test]
+ fn mysql_display_ddl_gets_statement_terminator() {
+ let ddl = "CREATE TABLE `users` (\n `id` int NOT NULL\n) ENGINE=InnoDB";
+
+ assert_eq!(
+ ensure_display_ddl_terminated(ddl.to_string()),
+ "CREATE TABLE `users` (\n `id` int NOT NULL\n) ENGINE=InnoDB;"
+ );
+ }
+
+ #[test]
+ fn mysql_display_ddl_does_not_duplicate_existing_terminator() {
+ let ddl = "CREATE TABLE `users` (`id` int);\n";
+
+ assert_eq!(ensure_display_ddl_terminated(ddl.to_string()), ddl);
+ }
}
pub async fn mysql_ddl(pool: &db::mysql::MySqlPool, table: &str) -> Result<String, String> {
@@ -4905,14 +4922,27 @@ pub async fn mysql_ddl(pool: &db::mysql::MySqlPool, table: &str) -> Result<Strin
let result = conn.query_iter(&sql).await.map_err(|e| e.to_string())?;
let rows: Vec<mysql_async::Row> = result.collect_and_drop().await.map_err(|e| e.to_string())?;
let row = rows.first().ok_or("DDL not found")?;
- row.get_opt::<String, usize>(1)
+ let ddl = row
+ .get_opt::<String, usize>(1)
.and_then(|result| result.ok())
.or_else(|| {
row.get_opt::<Vec<u8>, usize>(1)
.and_then(|result| result.ok())
.map(|b| String::from_utf8_lossy(&b).to_string())
})
- .ok_or_else(|| "Failed to read DDL".to_string())
+ .ok_or_else(|| "Failed to read DDL".to_string())?;
+ Ok(ensure_display_ddl_terminated(ddl))
+}
+
+fn ensure_display_ddl_terminated(sql: String) -> String {
+ let trimmed = sql.trim_end();
+ // SHOW CREATE TABLE returns a table definition, not a runnable script; DBX
+ // displays/copies it as SQL, so include the default statement terminator.
+ if trimmed.ends_with(';') {
+ sql
+ } else {
+ format!("{trimmed};")
+ }
}
pub async fn sqlite_ddl(pool: &db::sqlite::SqliteHandle, table: &str) -> Result<String, String> {