diff --git a/sqlx-core/src/raw_sql.rs b/sqlx-core/src/raw_sql.rs index 068959542a..f4104348bc 100644 --- a/sqlx-core/src/raw_sql.rs +++ b/sqlx-core/src/raw_sql.rs @@ -140,10 +140,7 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> { impl<'q> RawSql<'q> { /// Execute the SQL string and return the total number of rows affected. #[inline] - pub async fn execute<'e, E, DB>( - self, - executor: E, - ) -> crate::Result + pub async fn execute<'e, E, DB>(self, executor: E) -> crate::Result where 'q: 'e, DB: Database, @@ -170,10 +167,7 @@ impl<'q> RawSql<'q> { /// /// If the string contains multiple statements, their results will be concatenated together. #[inline] - pub fn fetch<'e, E, DB>( - self, - executor: E, - ) -> BoxStream<'e, Result> + pub fn fetch<'e, E, DB>(self, executor: E) -> BoxStream<'e, Result> where 'q: 'e, DB: Database, @@ -190,13 +184,7 @@ impl<'q> RawSql<'q> { pub fn fetch_many<'e, E, DB>( self, executor: E, - ) -> BoxStream< - 'e, - Result< - Either, - Error, - >, - > + ) -> BoxStream<'e, Result, Error>> where 'q: 'e, DB: Database, @@ -213,10 +201,7 @@ impl<'q> RawSql<'q> { /// To avoid exhausting available memory, ensure the result set has a known upper bound, /// e.g. using `LIMIT`. #[inline] - pub fn fetch_all<'e, E, DB>( - self, - executor: E, - ) -> BoxFuture<'e, crate::Result>> + pub fn fetch_all<'e, E, DB>(self, executor: E) -> BoxFuture<'e, crate::Result>> where 'q: 'e, DB: Database, @@ -238,10 +223,7 @@ impl<'q> RawSql<'q> { /// /// Otherwise, you might want to add `LIMIT 1` to your query. #[inline] - pub fn fetch_one<'e, E, DB>( - self, - executor: E, - ) -> BoxFuture<'e, crate::Result> + pub fn fetch_one<'e, E, DB>(self, executor: E) -> BoxFuture<'e, crate::Result> where 'q: 'e, DB: Database, @@ -263,10 +245,7 @@ impl<'q> RawSql<'q> { /// /// Otherwise, you might want to add `LIMIT 1` to your query. #[inline] - pub async fn fetch_optional<'e, E, DB>( - self, - executor: E, - ) -> crate::Result + pub async fn fetch_optional<'e, E, DB>(self, executor: E) -> crate::Result where 'q: 'e, DB: Database, @@ -275,25 +254,3 @@ impl<'q> RawSql<'q> { executor.fetch_one(self).await } } - -#[cfg(test)] -mod tests { - use sqlx::{Connection, SqliteConnection}; - - #[test] - fn issue_3150() { - tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap() - .block_on(async { - tokio::spawn(async { - let mut db = SqliteConnection::connect(":memory:").await.unwrap(); - sqlx::raw_sql("").execute(&mut db).await.unwrap(); - db.close().await.unwrap(); - }) - .await - }) - .ok(); - } -} diff --git a/tests/sqlite/sqlite.rs b/tests/sqlite/sqlite.rs index b733ccbb4c..d41eff5169 100644 --- a/tests/sqlite/sqlite.rs +++ b/tests/sqlite/sqlite.rs @@ -7,6 +7,7 @@ use sqlx::{ SqliteConnection, SqlitePool, Statement, TypeInfo, }; use sqlx_test::new; +use std::future::Future; use std::sync::Arc; #[sqlx_macros::test] @@ -960,3 +961,21 @@ async fn test_multiple_set_rollback_hook_calls_drop_old_handler() -> anyhow::Res assert_eq!(1, Arc::strong_count(&ref_counted_object)); Ok(()) } + +#[sqlx_macros::test] +async fn issue_3150() { + // Same bounds as `tokio::spawn()` + async fn fake_spawn(future: F) -> F::Output + where + F: Future + Send + 'static, + { + future.await + } + + fake_spawn(async { + let mut db = SqliteConnection::connect(":memory:").await.unwrap(); + sqlx::raw_sql("").execute(&mut db).await.unwrap(); + db.close().await.unwrap(); + }) + .await; +}