@@ -254,168 +254,5 @@ async fn it_encodes_decodes_json() -> anyhow::Result<()> {
254
254
255
255
assert_eq ! ( result. 0 , test_data) ;
256
256
257
- <<<<<<< Updated upstream
258
- let mut conn = new:: < Any > ( ) . await ?;
259
-
260
- let string = "Hello , world!".to_string();
261
- let ref tuple = (" Hello , world!".to_string(),);
262
-
263
- #[cfg(feature = " postgres") ]
264
- const SQL : & str =
265
- "SELECT 'Hello, world!' as string where 'Hello, world!' in ($1, $2, $3, $4, $5, $6, $7)" ;
266
-
267
- #[ cfg( not( feature = "postgres" ) ) ]
268
- const SQL : & str =
269
- "SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)" ;
270
-
271
- {
272
- let query = sqlx:: query ( SQL )
273
- // validate flexibility of lifetimes
274
- . bind ( & string)
275
- . bind ( & string[ ..] )
276
- . bind ( Some ( & string) )
277
- . bind ( Some ( & string[ ..] ) )
278
- . bind ( & Option :: < String > :: None )
279
- . bind ( & string. clone ( ) )
280
- . bind ( & tuple. 0 ) ; // should not get "temporary value is freed at the end of this statement" here
281
-
282
- let result = query. fetch_one ( & mut conn) . await ?;
283
-
284
- let column_0: String = result. try_get ( 0 ) ?;
285
-
286
- assert_eq ! ( column_0, string) ;
287
- }
288
-
289
- {
290
- let mut query = sqlx:: query ( SQL ) ;
291
-
292
- let query = || -> Result < _ , BoxDynError > {
293
- // validate flexibility of lifetimes
294
- query. try_bind ( & string) ?;
295
- query. try_bind ( & string[ ..] ) ?;
296
- query. try_bind ( Some ( & string) ) ?;
297
- query. try_bind ( Some ( & string[ ..] ) ) ?;
298
- query. try_bind ( & Option :: < String > :: None ) ?;
299
- query. try_bind ( & string. clone ( ) ) ?;
300
- query. try_bind ( & tuple. 0 ) ?;
301
-
302
- Ok ( query)
303
- } ( )
304
- . map_err ( Error :: Encode ) ?;
305
-
306
- let result = query. fetch_one ( & mut conn) . await ?;
307
-
308
- let column_0: String = result. try_get ( 0 ) ?;
309
-
310
- assert_eq ! ( column_0, string) ;
311
- }
312
- }
313
-
314
- #[ cfg( feature = "json" ) ]
315
- #[ sqlx_macros:: test]
316
- async fn it_encodes_decodes_json ( ) -> anyhow:: Result < ( ) > {
317
- sqlx:: any:: install_default_drivers ( ) ;
318
-
319
- // Create new connection
320
- let mut conn = new :: < Any > ( ) . await ?;
321
-
322
- // Test with serde_json::Value
323
- let json_value = serde_json:: json!( {
324
- "name" : "test" ,
325
- "value" : 42 ,
326
- "items" : [ 1 , 2 , 3 ]
327
- } ) ;
328
-
329
- // This will work by encoding JSON as text and decoding it back
330
- let result: serde_json:: Value = sqlx:: query_scalar ( "SELECT ?" )
331
- . bind ( Json ( & json_value) )
332
- . fetch_one ( & mut conn)
333
- . await ?;
334
-
335
- assert_eq ! ( result, json_value) ;
336
-
337
- // Test with custom struct
338
- #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
339
- struct TestData {
340
- name : String ,
341
- count : i32 ,
342
- }
343
-
344
- let test_data = TestData {
345
- name : "example" . to_string ( ) ,
346
- count : 100 ,
347
- } ;
348
-
349
- let result: Json < TestData > = sqlx:: query_scalar ( "SELECT ?" )
350
- . bind ( Json ( & test_data) )
351
- . fetch_one ( & mut conn)
352
- . await ?;
353
-
354
- assert_eq ! ( result. 0 , test_data) ;
355
-
356
- Ok ( ( ) )
357
- }
358
- =======
359
- #[ sqlx_macros:: test]
360
- async fn it_can_query_by_string_args ( ) -> sqlx:: Result < ( ) > {
361
- install_default_drivers ( ) ;
362
-
363
- let mut conn = new :: < Any > ( ) . await ?;
364
-
365
- let string = "Hello, world!" . to_string ( ) ;
366
- let ref tuple = ( "Hello, world!" . to_string ( ) , ) ;
367
-
368
- #[ cfg( feature = "postgres" ) ]
369
- const SQL : & str =
370
- "SELECT 'Hello, world!' as string where 'Hello, world!' in ($1, $2, $3, $4, $5, $6, $7)" ;
371
-
372
- #[ cfg( not( feature = "postgres" ) ) ]
373
- const SQL : & str =
374
- "SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)" ;
375
-
376
- {
377
- let query = sqlx:: query ( SQL )
378
- // validate flexibility of lifetimes
379
- . bind ( & string)
380
- . bind ( & string[ ..] )
381
- . bind ( Some ( & string) )
382
- . bind ( Some ( & string[ ..] ) )
383
- . bind ( & Option :: < String > :: None )
384
- . bind ( & string. clone ( ) )
385
- . bind ( & tuple. 0 ) ; // should not get "temporary value is freed at the end of this statement" here
386
-
387
- let result = query. fetch_one ( & mut conn) . await ?;
388
-
389
- let column_0: String = result. try_get ( 0 ) ?;
390
-
391
- assert_eq ! ( column_0, string) ;
392
- }
393
-
394
- {
395
- let mut query = sqlx:: query ( SQL ) ;
396
-
397
- let query = || -> Result < _ , BoxDynError > {
398
- // validate flexibility of lifetimes
399
- query. try_bind ( & string) ?;
400
- query. try_bind ( & string[ ..] ) ?;
401
- query. try_bind ( Some ( & string) ) ?;
402
- query. try_bind ( Some ( & string[ ..] ) ) ?;
403
- query. try_bind ( & Option :: < String > :: None ) ?;
404
- query. try_bind ( & string. clone ( ) ) ?;
405
- query. try_bind ( & tuple. 0 ) ?;
406
-
407
- Ok ( query)
408
- } ( )
409
- . map_err ( Error :: Encode ) ?;
410
-
411
- let result = query. fetch_one ( & mut conn) . await ?;
412
-
413
- let column_0: String = result. try_get ( 0 ) ?;
414
-
415
- assert_eq ! ( column_0, string) ;
416
- }
417
-
418
- =======
419
- >>>>>>> Stashed changes
420
257
Ok ( ( ) )
421
258
}
0 commit comments