From 7b0830789600b2eda1022ce285254688c58c9c94 Mon Sep 17 00:00:00 2001 From: hb <34821912+chenhbb@users.noreply.github.com> Date: Sat, 27 Jun 2026 12:31:02 +0800 Subject: [PATCH] fix: prevent implicit database creation on connection for SQLite (#1986) --- .../src/components/connection/ConnectionDialog.vue | 14 ++++++++++++++ crates/dbx-core/src/connection.rs | 6 +----- crates/dbx-core/src/db/duckdb_driver.rs | 6 +----- src-tauri/src/commands/connection.rs | 10 ++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue index bb349a436c..a200a44f87 100644 --- a/apps/desktop/src/components/connection/ConnectionDialog.vue +++ b/apps/desktop/src/components/connection/ConnectionDialog.vue @@ -2561,6 +2561,13 @@ async function createDuckDbFilePath() { const path = ensureDuckDbFileExtension(selected); form.value.host = path; + + try { + const { writeTextFile } = await import("@tauri-apps/plugin-fs"); + await writeTextFile(path, ""); + } catch (e) { + console.error("Failed to create DuckDB file:", e); + } } function ensureSqliteFileExtension(path: string): string { @@ -2580,6 +2587,13 @@ async function createSqliteFilePath() { const path = ensureSqliteFileExtension(selected); form.value.host = path; + + try { + const { writeTextFile } = await import("@tauri-apps/plugin-fs"); + await writeTextFile(path, ""); + } catch (e) { + console.error("Failed to create SQLite file:", e); + } } async function browseJdbcDriverPaths() { diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs index 42c0ee0656..a4ac772cff 100644 --- a/crates/dbx-core/src/connection.rs +++ b/crates/dbx-core/src/connection.rs @@ -712,11 +712,7 @@ impl AppState { }) .collect(); PoolKind::Sqlite( - db::sqlite::connect_path_create_if_missing_with_extensions( - &expand_tilde(&db_config.host), - extensions, - ) - .await?, + db::sqlite::connect_path_with_extensions(&expand_tilde(&db_config.host), extensions).await?, ) } DatabaseType::Rqlite => { diff --git a/crates/dbx-core/src/db/duckdb_driver.rs b/crates/dbx-core/src/db/duckdb_driver.rs index 69db54d132..8ef56bea71 100644 --- a/crates/dbx-core/src/db/duckdb_driver.rs +++ b/crates/dbx-core/src/db/duckdb_driver.rs @@ -39,11 +39,7 @@ fn validate_duckdb_path(path: &str) -> Result<(), String> { return Err(format!("Database file path is a directory, not a file: {}", path)); } if !path_obj.exists() { - if let Some(parent) = path_obj.parent() { - if !parent.as_os_str().is_empty() && !parent.exists() { - return Err(format!("Parent directory does not exist: {}", parent.display())); - } - } + return Err(format!("Database file does not exist: {}", path)); } Ok(()) } diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rs index 12fd7b25be..d662e9128a 100644 --- a/src-tauri/src/commands/connection.rs +++ b/src-tauri/src/commands/connection.rs @@ -605,12 +605,7 @@ pub async fn test_connection(state: State<'_, Arc>, config: Connection extension }) .collect(); - match db::sqlite::connect_path_create_if_missing_with_extensions( - &expand_tilde(&config.host), - extensions, - ) - .await - { + match db::sqlite::connect_path_with_extensions(&expand_tilde(&config.host), extensions).await { Ok(_) => Ok("Connection successful".to_string()), Err(e) => Err(e), } @@ -875,8 +870,7 @@ pub async fn connect_db(state: State<'_, Arc>, config: ConnectionConfi }) .collect(); PoolKind::Sqlite( - db::sqlite::connect_path_create_if_missing_with_extensions(&expand_tilde(&db_config.host), extensions) - .await?, + db::sqlite::connect_path_with_extensions(&expand_tilde(&db_config.host), extensions).await?, ) } DatabaseType::Redis => {