@@ -457,7 +457,7 @@ async fn test_batch() {
457457 . await
458458 . unwrap ( ) ;
459459
460- // TODO: Add API, that supports binding values to statements in batch creation process,
460+ // TODO: Add API that supports binding values to statements in batch creation process,
461461 // to avoid problem of statements/values count mismatch
462462 use crate :: batch:: Batch ;
463463 let mut batch: Batch = Default :: default ( ) ;
@@ -537,6 +537,42 @@ async fn test_batch() {
537537 assert_eq ! ( results, vec![ ( 4 , 20 , String :: from( "foobar" ) ) ] ) ;
538538}
539539
540+ // This is a regression test for #1134.
541+ #[ tokio:: test]
542+ async fn test_batch_to_multiple_tables ( ) {
543+ setup_tracing ( ) ;
544+ let session = create_new_session_builder ( ) . build ( ) . await . unwrap ( ) ;
545+ let ks = unique_keyspace_name ( ) ;
546+
547+ session. ddl ( format ! ( "CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}" , ks) ) . await . unwrap ( ) ;
548+ session. use_keyspace ( & ks, true ) . await . unwrap ( ) ;
549+ session
550+ . ddl ( "CREATE TABLE IF NOT EXISTS t_batch1 (a int, b int, c text, primary key (a, b))" )
551+ . await
552+ . unwrap ( ) ;
553+ session
554+ . ddl ( "CREATE TABLE IF NOT EXISTS t_batch2 (a int, b int, c text, primary key (a, b))" )
555+ . await
556+ . unwrap ( ) ;
557+
558+ let prepared_statement = session
559+ . prepare (
560+ "
561+ BEGIN BATCH
562+ INSERT INTO t_batch1 (a, b, c) VALUES (?, ?, ?);
563+ INSERT INTO t_batch2 (a, b, c) VALUES (?, ?, ?);
564+ APPLY BATCH;
565+ " ,
566+ )
567+ . await
568+ . unwrap ( ) ;
569+
570+ session
571+ . execute_unpaged ( & prepared_statement, ( 1 , 2 , "ala" , 4 , 5 , "ma" ) )
572+ . await
573+ . unwrap ( ) ;
574+ }
575+
540576#[ tokio:: test]
541577async fn test_token_calculation ( ) {
542578 setup_tracing ( ) ;
0 commit comments