You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error "database table is locked" when using fetch_one with sqlite executor #662
It seems the fetch_one function in the sqlite executor doesn't release the handle to the table. If the table is subsequently dropped an error is returned because of the lock on the table.
use sqlx::{Connection,Executor,Row};use sqlx::sqlite::SqliteConnection;#[tokio::main]asyncfnmain(){letmut conn = SqliteConnection::connect("sqlite::memory:").await.unwrap();
conn.execute("CREATE TABLE foobar (id INTEGER)").await.unwrap();
conn.execute("INSERT INTO foobar VALUES (42)").await.unwrap();let r = sqlx::query("SELECT id FROM foobar").fetch_one(&mut conn).await.unwrap();let x:i32 = r.try_get("id").unwrap();println!("{:}", x);
conn.execute("DROP TABLE foobar").await.unwrap();// panics!// thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Database(SqliteError { code: 6, message: "database table is locked" })', src\main.rs:13:5}
[dependencies]
tokio = { version = "0.2", features = ["full"] }
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "sqlite", "runtime-tokio", "macros" ] }
Activity
songday commentedon Sep 4, 2020
I don't know whether we met the same situation, my case is that CPU usage goes to 100%
if I change
fetch_onetofetch_all, everything is fine