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): decode opened SQL files with charset fallback
t8y2465ed195cfb0
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vueindex 68e96fa127..3b73224860 100644--- a/apps/desktop/src/App.vue+++ b/apps/desktop/src/App.vue@@ -454,10 +454,9 @@ async function openSqlFile() {try {if (isTauriRuntime()) {const { open } = await import("@tauri-apps/plugin-dialog");- const { readTextFile } = await import("@tauri-apps/plugin-fs");const path = await open({ filters: [{ name: "SQL", extensions: ["sql"] }], multiple: false });if (path) {- const content = await readTextFile(path as string);+ const content = await api.readExternalSqlFile(path as string);queryStore.updateSql(tab.id, content);}} else {diff --git a/src-tauri/src/commands/external_sql.rs b/src-tauri/src/commands/external_sql.rsindex e33d9d4454..a162d8f187 100644--- a/src-tauri/src/commands/external_sql.rs+++ b/src-tauri/src/commands/external_sql.rs@@ -1,6 +1,8 @@use std::path::{Path, PathBuf};use std::sync::Mutex;+use dbx_core::sql::decode_sql_file_bytes;+#[tauri::command]pub fn pending_open_sql_files(state: tauri::State<'_, ExternalSqlOpenState>) -> Vec<String> {let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));@@ -64,7 +66,8 @@ pub fn read_external_sql_file_content(path: &Path) -> Result<String, String> {if !is_sql_file_path(path) {return Err("Only .sql files can be opened this way".to_string());}- std::fs::read_to_string(path).map_err(|e| format!("Failed to read SQL file: {e}"))+ let bytes = std::fs::read(path).map_err(|e| format!("Failed to read SQL file: {e}"))?;+ decode_sql_file_bytes(&bytes)}fn dedupe_paths(paths: Vec<String>) -> Vec<String> {@@ -115,6 +118,17 @@ mod tests {assert_eq!(result.unwrap(), "select 1;");}+ #[test]+ fn reads_gbk_external_sql_file_content() {+ let path = std::env::temp_dir().join(format!("dbx-test-{}.sql", uuid::Uuid::new_v4()));+ std::fs::write(&path, b"select '\xD6\xD0\xCE\xC4';").unwrap();++ let result = read_external_sql_file_content(&path);++ let _ = std::fs::remove_file(&path);+ assert_eq!(result.unwrap(), "select '中文';");+ }+#[test]fn rejects_external_non_sql_file_content() {let path = std::env::temp_dir().join(format!("dbx-test-{}.txt", uuid::Uuid::new_v4()));