Skip to content

Commit 0776c48

Browse files
committed
chore: move regression test to appropriate place, cargo fmt
1 parent 493ec54 commit 0776c48

File tree

2 files changed

+25
-49
lines changed

2 files changed

+25
-49
lines changed

sqlx-core/src/raw_sql.rs

+6-49
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> {
140140
impl<'q> RawSql<'q> {
141141
/// Execute the SQL string and return the total number of rows affected.
142142
#[inline]
143-
pub async fn execute<'e, E, DB>(
144-
self,
145-
executor: E,
146-
) -> crate::Result<DB::QueryResult>
143+
pub async fn execute<'e, E, DB>(self, executor: E) -> crate::Result<DB::QueryResult>
147144
where
148145
'q: 'e,
149146
DB: Database,
@@ -170,10 +167,7 @@ impl<'q> RawSql<'q> {
170167
///
171168
/// If the string contains multiple statements, their results will be concatenated together.
172169
#[inline]
173-
pub fn fetch<'e, E, DB>(
174-
self,
175-
executor: E,
176-
) -> BoxStream<'e, Result<DB::Row, Error>>
170+
pub fn fetch<'e, E, DB>(self, executor: E) -> BoxStream<'e, Result<DB::Row, Error>>
177171
where
178172
'q: 'e,
179173
DB: Database,
@@ -190,13 +184,7 @@ impl<'q> RawSql<'q> {
190184
pub fn fetch_many<'e, E, DB>(
191185
self,
192186
executor: E,
193-
) -> BoxStream<
194-
'e,
195-
Result<
196-
Either<DB::QueryResult, DB::Row>,
197-
Error,
198-
>,
199-
>
187+
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>
200188
where
201189
'q: 'e,
202190
DB: Database,
@@ -213,10 +201,7 @@ impl<'q> RawSql<'q> {
213201
/// To avoid exhausting available memory, ensure the result set has a known upper bound,
214202
/// e.g. using `LIMIT`.
215203
#[inline]
216-
pub fn fetch_all<'e, E, DB>(
217-
self,
218-
executor: E,
219-
) -> BoxFuture<'e, crate::Result<Vec<DB::Row>>>
204+
pub fn fetch_all<'e, E, DB>(self, executor: E) -> BoxFuture<'e, crate::Result<Vec<DB::Row>>>
220205
where
221206
'q: 'e,
222207
DB: Database,
@@ -238,10 +223,7 @@ impl<'q> RawSql<'q> {
238223
///
239224
/// Otherwise, you might want to add `LIMIT 1` to your query.
240225
#[inline]
241-
pub fn fetch_one<'e, E, DB>(
242-
self,
243-
executor: E,
244-
) -> BoxFuture<'e, crate::Result<DB::Row>>
226+
pub fn fetch_one<'e, E, DB>(self, executor: E) -> BoxFuture<'e, crate::Result<DB::Row>>
245227
where
246228
'q: 'e,
247229
DB: Database,
@@ -263,10 +245,7 @@ impl<'q> RawSql<'q> {
263245
///
264246
/// Otherwise, you might want to add `LIMIT 1` to your query.
265247
#[inline]
266-
pub async fn fetch_optional<'e, E, DB>(
267-
self,
268-
executor: E,
269-
) -> crate::Result<DB::Row>
248+
pub async fn fetch_optional<'e, E, DB>(self, executor: E) -> crate::Result<DB::Row>
270249
where
271250
'q: 'e,
272251
DB: Database,
@@ -275,25 +254,3 @@ impl<'q> RawSql<'q> {
275254
executor.fetch_one(self).await
276255
}
277256
}
278-
279-
#[cfg(test)]
280-
mod tests {
281-
use sqlx::{Connection, SqliteConnection};
282-
283-
#[test]
284-
fn issue_3150() {
285-
tokio::runtime::Builder::new_current_thread()
286-
.enable_all()
287-
.build()
288-
.unwrap()
289-
.block_on(async {
290-
tokio::spawn(async {
291-
let mut db = SqliteConnection::connect(":memory:").await.unwrap();
292-
sqlx::raw_sql("").execute(&mut db).await.unwrap();
293-
db.close().await.unwrap();
294-
})
295-
.await
296-
})
297-
.ok();
298-
}
299-
}

tests/sqlite/sqlite.rs

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use sqlx::{
77
SqliteConnection, SqlitePool, Statement, TypeInfo,
88
};
99
use sqlx_test::new;
10+
use std::future::Future;
1011
use std::sync::Arc;
1112

1213
#[sqlx_macros::test]
@@ -960,3 +961,21 @@ async fn test_multiple_set_rollback_hook_calls_drop_old_handler() -> anyhow::Res
960961
assert_eq!(1, Arc::strong_count(&ref_counted_object));
961962
Ok(())
962963
}
964+
965+
#[sqlx_macros::test]
966+
async fn issue_3150() {
967+
// Same bounds as `tokio::spawn()`
968+
async fn fake_spawn<F>(future: F) -> F::Output
969+
where
970+
F: Future + Send + 'static,
971+
{
972+
future.await
973+
}
974+
975+
fake_spawn(async {
976+
let mut db = SqliteConnection::connect(":memory:").await.unwrap();
977+
sqlx::raw_sql("").execute(&mut db).await.unwrap();
978+
db.close().await.unwrap();
979+
})
980+
.await;
981+
}

0 commit comments

Comments
 (0)