Skip to content

Commit

Permalink
chore: move regression test to appropriate place, cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Nov 28, 2024
1 parent 493ec54 commit 0776c48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 49 deletions.
55 changes: 6 additions & 49 deletions sqlx-core/src/raw_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB::QueryResult>
pub async fn execute<'e, E, DB>(self, executor: E) -> crate::Result<DB::QueryResult>
where
'q: 'e,
DB: Database,
Expand All @@ -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<DB::Row, Error>>
pub fn fetch<'e, E, DB>(self, executor: E) -> BoxStream<'e, Result<DB::Row, Error>>
where
'q: 'e,
DB: Database,
Expand All @@ -190,13 +184,7 @@ impl<'q> RawSql<'q> {
pub fn fetch_many<'e, E, DB>(
self,
executor: E,
) -> BoxStream<
'e,
Result<
Either<DB::QueryResult, DB::Row>,
Error,
>,
>
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>
where
'q: 'e,
DB: Database,
Expand All @@ -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<Vec<DB::Row>>>
pub fn fetch_all<'e, E, DB>(self, executor: E) -> BoxFuture<'e, crate::Result<Vec<DB::Row>>>
where
'q: 'e,
DB: Database,
Expand All @@ -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<DB::Row>>
pub fn fetch_one<'e, E, DB>(self, executor: E) -> BoxFuture<'e, crate::Result<DB::Row>>
where
'q: 'e,
DB: Database,
Expand All @@ -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<DB::Row>
pub async fn fetch_optional<'e, E, DB>(self, executor: E) -> crate::Result<DB::Row>
where
'q: 'e,
DB: Database,
Expand All @@ -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();
}
}
19 changes: 19 additions & 0 deletions tests/sqlite/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<F>(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;
}

0 comments on commit 0776c48

Please sign in to comment.