tauri-plugin-sql opens each database with Pool::connect, a sqlx pool of
up to ten connections, and sqlx gives a connection back to its pool
through a spawned task. Two statements sent back to back made the pool
open a second connection and serve both in turn, so a transaction of
withTransaction was split: its BEGIN and first write on one connection,
a later write on the other, which waited for the first one's write lock
and failed with "database is locked" (code 5) after 5 s. Adding a keyword
from the right-click menu (six statements) and creating a sub-category
hit it; the 14 withTransaction call sites were exposed.
Right after Database.load, inside the exclusive section that opens a
profile, loadUnlocked now calls use_single_connection_pool, a new Tauri
command (db_pool_commands.rs) that replaces the plugin's DbPool::Sqlite
in DbInstances by a pool of one connection, never recycled, opened with
the plugin pool's own connect options, then closes the plugin's pool.
getDb() and withTransaction find the connection only once the switch
succeeded; a failed switch writes a folder-free Journal line, closes the
plugin's pool and fails the opening.
sqlx 0.8.6 becomes a direct dependency with features the plugin already
enables: Cargo.lock only gains the edge, no package.
test: reproduces #543. The Rust tests replay, on a real sqlx pool opened
like the plugin's, the statements of a keyword on one then two checked
transactions (one split) and of a sub-category: code 5 on the plugin's
pool, green after the swap (6 of 6 red on a no-op swap). db.test.ts pins
the place of the switch and its failure path.
Fixes#543
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>