@@ -312,4 +312,65 @@ async fn it_encodes_decodes_json() -> anyhow::Result<()> {
312312
313313 Ok ( ( ) )
314314 }
315+ =======
316+ #[ sqlx_macros:: test]
317+ async fn it_can_query_by_string_args ( ) -> sqlx:: Result < ( ) > {
318+ install_default_drivers ( ) ;
319+
320+ let mut conn = new :: < Any > ( ) . await ?;
321+
322+ let string = "Hello, world!" . to_string ( ) ;
323+ let ref tuple = ( "Hello, world!" . to_string ( ) , ) ;
324+
325+ #[ cfg( feature = "postgres" ) ]
326+ const SQL : & str =
327+ "SELECT 'Hello, world!' as string where 'Hello, world!' in ($1, $2, $3, $4, $5, $6, $7)" ;
328+
329+ #[ cfg( not( feature = "postgres" ) ) ]
330+ const SQL : & str =
331+ "SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)" ;
332+
333+ {
334+ let query = sqlx:: query ( SQL )
335+ // validate flexibility of lifetimes
336+ . bind ( & string)
337+ . bind ( & string[ ..] )
338+ . bind ( Some ( & string) )
339+ . bind ( Some ( & string[ ..] ) )
340+ . bind ( & Option :: < String > :: None )
341+ . bind ( & string. clone ( ) )
342+ . bind ( & tuple. 0 ) ; // should not get "temporary value is freed at the end of this statement" here
343+
344+ let result = query. fetch_one ( & mut conn) . await ?;
345+
346+ let column_0: String = result. try_get ( 0 ) ?;
347+
348+ assert_eq ! ( column_0, string) ;
349+ }
350+
351+ {
352+ let mut query = sqlx:: query ( SQL ) ;
353+
354+ let query = || -> Result < _ , BoxDynError > {
355+ // validate flexibility of lifetimes
356+ query. try_bind ( & string) ?;
357+ query. try_bind ( & string[ ..] ) ?;
358+ query. try_bind ( Some ( & string) ) ?;
359+ query. try_bind ( Some ( & string[ ..] ) ) ?;
360+ query. try_bind ( & Option :: < String > :: None ) ?;
361+ query. try_bind ( & string. clone ( ) ) ?;
362+ query. try_bind ( & tuple. 0 ) ?;
363+
364+ Ok ( query)
365+ } ( )
366+ . map_err ( Error :: Encode ) ?;
367+
368+ let result = query. fetch_one ( & mut conn) . await ?;
369+
370+ let column_0: String = result. try_get ( 0 ) ?;
371+
372+ assert_eq ! ( column_0, string) ;
373+ }
374+
375+ Ok ( ( ) )
315376}
0 commit comments