@@ -38,6 +38,7 @@ use crate::routing::partitioner::PartitionerName;
3838use crate :: routing:: { Shard , ShardAwarePortRange } ;
3939use crate :: statement:: batch:: batch_values;
4040use crate :: statement:: batch:: { Batch , BatchStatement } ;
41+ use crate :: statement:: bound:: BoundStatement ;
4142use crate :: statement:: prepared:: { PartitionKeyError , PreparedStatement } ;
4243use crate :: statement:: unprepared:: Statement ;
4344use crate :: statement:: { Consistency , PageSize , StatementConfig } ;
@@ -47,7 +48,7 @@ use futures::future::try_join_all;
4748use itertools:: Itertools ;
4849use scylla_cql:: frame:: response:: NonErrorResponse ;
4950use scylla_cql:: serialize:: batch:: BatchValues ;
50- use scylla_cql:: serialize:: row:: { SerializeRow , SerializedValues } ;
51+ use scylla_cql:: serialize:: row:: SerializeRow ;
5152use std:: borrow:: Borrow ;
5253use std:: future:: Future ;
5354use std:: net:: { IpAddr , SocketAddr } ;
@@ -640,7 +641,8 @@ impl Session {
640641 prepared : & PreparedStatement ,
641642 values : impl SerializeRow ,
642643 ) -> Result < QueryResult , ExecutionError > {
643- self . do_execute_unpaged ( prepared, values) . await
644+ let bound = prepared. bind ( & values) ?;
645+ self . do_execute_unpaged ( & bound) . await
644646 }
645647
646648 /// Executes a prepared statement, restricting results to single page.
@@ -705,8 +707,8 @@ impl Session {
705707 values : impl SerializeRow ,
706708 paging_state : PagingState ,
707709 ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
708- self . do_execute_single_page ( prepared , values, paging_state )
709- . await
710+ let bound = prepared . bind ( & values) ? ;
711+ self . do_execute_single_page ( & bound , paging_state ) . await
710712 }
711713
712714 /// Execute a prepared statement with paging.\
@@ -753,7 +755,8 @@ impl Session {
753755 prepared : impl Into < PreparedStatement > ,
754756 values : impl SerializeRow ,
755757 ) -> Result < QueryPager , PagerExecutionError > {
756- self . do_execute_iter ( prepared. into ( ) , values) . await
758+ let bound = prepared. into ( ) . into_bind ( & values) ?;
759+ self . do_execute_iter ( bound) . await
757760 }
758761
759762 /// Execute a batch statement\
@@ -1085,12 +1088,11 @@ impl Session {
10851088 . and_then ( QueryResponse :: into_non_error_query_response)
10861089 } else {
10871090 let prepared = connection. prepare ( statement) . await ?;
1088- let serialized = prepared. serialize_values ( values_ref) ?;
1089- span_ref. record_request_size ( serialized . buffer_size ( ) ) ;
1091+ let bound = prepared. bind ( values_ref) ?;
1092+ span_ref. record_request_size ( bound . values . buffer_size ( ) ) ;
10901093 connection
10911094 . execute_raw_with_consistency (
1092- & prepared,
1093- & serialized,
1095+ & bound,
10941096 consistency,
10951097 serial_consistency,
10961098 page_size,
@@ -1187,11 +1189,9 @@ impl Session {
11871189 // Making QueryPager::new_for_query work with values is too hard (if even possible)
11881190 // so instead of sending one prepare to a specific connection on each iterator query,
11891191 // we fully prepare a statement beforehand.
1190- let prepared = self . prepare_nongeneric ( & statement) . await ?;
1191- let values = prepared. serialize_values ( & values) ?;
1192+ let bound = self . prepare_nongeneric ( & statement) . await ?. into_bind ( & values) ?;
11921193 QueryPager :: new_for_prepared_statement ( PreparedPagerConfig {
1193- prepared,
1194- values,
1194+ bound,
11951195 execution_profile,
11961196 cluster_state : self . cluster . get_state ( ) ,
11971197 #[ cfg( feature = "metrics" ) ]
@@ -1360,13 +1360,9 @@ impl Session {
13601360
13611361 async fn do_execute_unpaged (
13621362 & self ,
1363- prepared : & PreparedStatement ,
1364- values : impl SerializeRow ,
1363+ bound : & BoundStatement < ' _ > ,
13651364 ) -> Result < QueryResult , ExecutionError > {
1366- let serialized_values = prepared. serialize_values ( & values) ?;
1367- let ( result, paging_state) = self
1368- . execute ( prepared, & serialized_values, None , PagingState :: start ( ) )
1369- . await ?;
1365+ let ( result, paging_state) = self . execute ( bound, None , PagingState :: start ( ) ) . await ?;
13701366 if !paging_state. finished ( ) {
13711367 error ! ( "Unpaged prepared query returned a non-empty paging state! This is a driver-side or server-side bug." ) ;
13721368 return Err ( ExecutionError :: LastAttemptError (
@@ -1378,14 +1374,11 @@ impl Session {
13781374
13791375 async fn do_execute_single_page (
13801376 & self ,
1381- prepared : & PreparedStatement ,
1382- values : impl SerializeRow ,
1377+ bound : & BoundStatement < ' _ > ,
13831378 paging_state : PagingState ,
13841379 ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1385- let serialized_values = prepared. serialize_values ( & values) ?;
1386- let page_size = prepared. get_validated_page_size ( ) ;
1387- self . execute ( prepared, & serialized_values, Some ( page_size) , paging_state)
1388- . await
1380+ let page_size = bound. prepared . get_validated_page_size ( ) ;
1381+ self . execute ( bound, Some ( page_size) , paging_state) . await
13891382 }
13901383
13911384 /// Sends a prepared request to the database, optionally continuing from a saved point.
@@ -1400,44 +1393,45 @@ impl Session {
14001393 /// should be made.
14011394 async fn execute (
14021395 & self ,
1403- prepared : & PreparedStatement ,
1404- serialized_values : & SerializedValues ,
1396+ bound : & BoundStatement < ' _ > ,
14051397 page_size : Option < PageSize > ,
14061398 paging_state : PagingState ,
14071399 ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1408- let values_ref = & serialized_values;
14091400 let paging_state_ref = & paging_state;
14101401
1411- let ( partition_key, token) = prepared
1412- . extract_partition_key_and_calculate_token ( prepared . get_partitioner_name ( ) , values_ref )
1402+ let ( partition_key, token) = bound
1403+ . pk_and_token ( )
14131404 . map_err ( PartitionKeyError :: into_execution_error) ?
14141405 . unzip ( ) ;
14151406
1416- let execution_profile = prepared
1407+ let execution_profile = bound
1408+ . prepared
14171409 . get_execution_profile_handle ( )
14181410 . unwrap_or_else ( || self . get_default_execution_profile_handle ( ) )
14191411 . access ( ) ;
14201412
1421- let table_spec = prepared. get_table_spec ( ) ;
1413+ let table_spec = bound . prepared . get_table_spec ( ) ;
14221414
14231415 let statement_info = RoutingInfo {
1424- consistency : prepared
1416+ consistency : bound
1417+ . prepared
14251418 . config
14261419 . consistency
14271420 . unwrap_or ( execution_profile. consistency ) ,
1428- serial_consistency : prepared
1421+ serial_consistency : bound
1422+ . prepared
14291423 . config
14301424 . serial_consistency
14311425 . unwrap_or ( execution_profile. serial_consistency ) ,
14321426 token,
14331427 table : table_spec,
1434- is_confirmed_lwt : prepared. is_confirmed_lwt ( ) ,
1428+ is_confirmed_lwt : bound . prepared . is_confirmed_lwt ( ) ,
14351429 } ;
14361430
14371431 let span = RequestSpan :: new_prepared (
14381432 partition_key. as_ref ( ) . map ( |pk| pk. iter ( ) ) ,
14391433 token,
1440- serialized_values . buffer_size ( ) ,
1434+ bound . values . buffer_size ( ) ,
14411435 ) ;
14421436
14431437 if !span. span ( ) . is_disabled ( ) {
@@ -1454,20 +1448,20 @@ impl Session {
14541448 ) = self
14551449 . run_request (
14561450 statement_info,
1457- & prepared. config ,
1451+ & bound . prepared . config ,
14581452 execution_profile,
14591453 |connection : Arc < Connection > ,
14601454 consistency : Consistency ,
14611455 execution_profile : & ExecutionProfileInner | {
1462- let serial_consistency = prepared
1456+ let serial_consistency = bound
1457+ . prepared
14631458 . config
14641459 . serial_consistency
14651460 . unwrap_or ( execution_profile. serial_consistency ) ;
14661461 async move {
14671462 connection
14681463 . execute_raw_with_consistency (
1469- prepared,
1470- values_ref,
1464+ bound,
14711465 consistency,
14721466 serial_consistency,
14731467 page_size,
@@ -1504,19 +1498,16 @@ impl Session {
15041498
15051499 async fn do_execute_iter (
15061500 & self ,
1507- prepared : PreparedStatement ,
1508- values : impl SerializeRow ,
1501+ bound : BoundStatement < ' static > ,
15091502 ) -> Result < QueryPager , PagerExecutionError > {
1510- let serialized_values = prepared. serialize_values ( & values) ?;
1511-
1512- let execution_profile = prepared
1503+ let execution_profile = bound
1504+ . prepared
15131505 . get_execution_profile_handle ( )
15141506 . unwrap_or_else ( || self . get_default_execution_profile_handle ( ) )
15151507 . access ( ) ;
15161508
15171509 QueryPager :: new_for_prepared_statement ( PreparedPagerConfig {
1518- prepared,
1519- values : serialized_values,
1510+ bound,
15201511 execution_profile,
15211512 cluster_state : self . cluster . get_state ( ) ,
15221513 #[ cfg( feature = "metrics" ) ]
0 commit comments