File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,41 @@ fn test_nested_transactions_finish() {
331
331
) ;
332
332
}
333
333
334
+ #[ test]
335
+ fn test_nested_transactions_partial_rollback ( ) {
336
+ let conn = or_panic ! ( Connection :: connect(
337
+ "postgres://postgres@localhost:5433" ,
338
+ TlsMode :: None ,
339
+ ) ) ;
340
+ or_panic ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)" , & [ ] ) ) ;
341
+
342
+ or_panic ! ( conn. execute( "INSERT INTO foo (id) VALUES ($1)" , & [ & 1i32 ] ) ) ;
343
+
344
+ {
345
+ let trans = or_panic ! ( conn. transaction( ) ) ;
346
+ or_panic ! ( trans. execute( "INSERT INTO foo (id) VALUES ($1)" , & [ & 2i32 ] ) ) ;
347
+ {
348
+ let trans = or_panic ! ( trans. transaction( ) ) ;
349
+ or_panic ! ( trans. execute( "INSERT INTO foo (id) VALUES ($1)" , & [ & 3i32 ] ) ) ;
350
+ {
351
+ let trans = or_panic ! ( trans. transaction( ) ) ;
352
+ or_panic ! ( trans. execute( "INSERT INTO foo (id) VALUES ($1)" , & [ & 4i32 ] ) ) ;
353
+ drop ( trans) ;
354
+ }
355
+ drop ( trans) ;
356
+ }
357
+ or_panic ! ( trans. commit( ) ) ;
358
+ }
359
+
360
+ let stmt = or_panic ! ( conn. prepare( "SELECT * FROM foo ORDER BY id" ) ) ;
361
+ let result = or_panic ! ( stmt. query( & [ ] ) ) ;
362
+
363
+ assert_eq ! (
364
+ vec![ 1i32 , 2 ] ,
365
+ result. iter( ) . map( |row| row. get( 0 ) ) . collect:: <Vec <i32 >>( )
366
+ ) ;
367
+ }
368
+
334
369
#[ test]
335
370
#[ should_panic( expected = "active transaction" ) ]
336
371
fn test_conn_trans_when_nested ( ) {
You can’t perform that action at this time.
0 commit comments