From 5d25f4342b972f7e7c45707356329f5f80a8c0de Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Wed, 22 Sep 2021 15:48:49 -0700 Subject: [PATCH] chore(sqlite): add repro for #1419 --- tests/sqlite/sqlite.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/sqlite/sqlite.rs b/tests/sqlite/sqlite.rs index e794f49a74..1230ea0e6a 100644 --- a/tests/sqlite/sqlite.rs +++ b/tests/sqlite/sqlite.rs @@ -567,3 +567,37 @@ async fn concurrent_resets_dont_segfault() { sqlx_rt::sleep(Duration::from_millis(1)).await; } + +// https://github.com/launchbadge/sqlx/issues/1419 +#[sqlx_macros::test] +async fn row_dropped_after_connection_doesnt_panic() { + let mut conn = SqliteConnection::connect(":memory:").await.unwrap(); + + conn.execute( + "CREATE TABLE IF NOT EXISTS books +( + title TEXT NOT NULL, + created_at INTEGER DEFAULT (cast(strftime('%s','now') as int)), + updated_at INTEGER DEFAULT (cast(strftime('%s','now') as int)) +); + +INSERT INTO books(title) VALUES('hello'); +INSERT INTO books(title) VALUES('test'); +INSERT INTO books(title) VALUES('example'); +INSERT INTO books(title) VALUES('stuff'); +INSERT INTO books(title) VALUES('here'); +INSERT INTO books(title) VALUES('there'); +INSERT INTO books(title) VALUES('everywhere');", + ) + .await + .unwrap(); + + let _books = sqlx::query("SELECT * FROM books") + .fetch_all(&mut *conn3) + .await + .unwrap(); + + // hold `_books` past the lifetime of `conn` + drop(conn); + drop(_books); +}