Skip to content

Commit e7cf19e

Browse files
committed
bug(sqlite): query macro argument lifetime use inconsistent with other db platforms
Signed-off-by: Joshua Potts <[email protected]>
1 parent c825bd3 commit e7cf19e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/sqlite/macros.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,31 @@ async fn test_query_scalar() -> anyhow::Result<()> {
175175
Ok(())
176176
}
177177

178+
#[sqlx_macros::test]
179+
async fn query_by_string() -> anyhow::Result<()> {
180+
let mut conn = new::<Sqlite>().await?;
181+
182+
let string = "Hello, world!".to_string();
183+
let ref tuple = ("Hello, world!".to_string(),);
184+
185+
let result = sqlx::query!(
186+
"SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)",
187+
string, // make sure we don't actually take ownership here
188+
&string[..],
189+
Some(&string),
190+
Some(&string[..]),
191+
Option::<String>::None,
192+
string.clone(),
193+
tuple.0 // make sure we're not trying to move out of a field expression
194+
)
195+
.fetch_one(&mut conn)
196+
.await?;
197+
198+
assert_eq!(result.string, string);
199+
200+
Ok(())
201+
}
202+
178203
#[sqlx_macros::test]
179204
async fn macro_select_from_view() -> anyhow::Result<()> {
180205
let mut conn = new::<Sqlite>().await?;

0 commit comments

Comments
 (0)