@@ -37,6 +37,7 @@ use crate::routing::partitioner::PartitionerName;
3737use crate :: routing:: { Shard , ShardAwarePortRange } ;
3838use crate :: statement:: batch:: batch_values;
3939use crate :: statement:: batch:: { Batch , BatchStatement } ;
40+ use crate :: statement:: bound:: BoundStatement ;
4041use crate :: statement:: prepared:: { PartitionKeyError , PreparedStatement } ;
4142use crate :: statement:: unprepared:: Statement ;
4243use crate :: statement:: { Consistency , PageSize , StatementConfig } ;
@@ -46,7 +47,7 @@ use futures::future::try_join_all;
4647use itertools:: Itertools ;
4748use scylla_cql:: frame:: response:: NonErrorResponse ;
4849use scylla_cql:: serialize:: batch:: BatchValues ;
49- use scylla_cql:: serialize:: row:: { SerializeRow , SerializedValues } ;
50+ use scylla_cql:: serialize:: row:: SerializeRow ;
5051use std:: borrow:: Borrow ;
5152use std:: future:: Future ;
5253use std:: net:: { IpAddr , SocketAddr } ;
@@ -637,7 +638,8 @@ impl Session {
637638 prepared : & PreparedStatement ,
638639 values : impl SerializeRow ,
639640 ) -> Result < QueryResult , ExecutionError > {
640- self . do_execute_unpaged ( prepared, values) . await
641+ let bound = prepared. bind ( & values) ?;
642+ self . do_execute_unpaged ( & bound) . await
641643 }
642644
643645 /// Executes a prepared statement, restricting results to single page.
@@ -702,8 +704,8 @@ impl Session {
702704 values : impl SerializeRow ,
703705 paging_state : PagingState ,
704706 ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
705- self . do_execute_single_page ( prepared , values, paging_state )
706- . await
707+ let bound = prepared . bind ( & values) ? ;
708+ self . do_execute_single_page ( & bound , paging_state ) . await
707709 }
708710
709711 /// Execute a prepared statement with paging.\
@@ -750,7 +752,8 @@ impl Session {
750752 prepared : impl Into < PreparedStatement > ,
751753 values : impl SerializeRow ,
752754 ) -> Result < QueryPager , PagerExecutionError > {
753- self . do_execute_iter ( prepared. into ( ) , values) . await
755+ let bound = prepared. into ( ) . into_bind ( & values) ?;
756+ self . do_execute_iter ( bound) . await
754757 }
755758
756759 /// Execute a batch statement\
@@ -1083,12 +1086,11 @@ impl Session {
10831086 . and_then ( QueryResponse :: into_non_error_query_response)
10841087 } else {
10851088 let prepared = connection. prepare ( statement) . await ?;
1086- let serialized = prepared. serialize_values ( values_ref) ?;
1087- span_ref. record_request_size ( serialized . buffer_size ( ) ) ;
1089+ let bound = prepared. bind ( values_ref) ?;
1090+ span_ref. record_request_size ( bound . values . buffer_size ( ) ) ;
10881091 connection
10891092 . execute_raw_with_consistency (
1090- & prepared,
1091- & serialized,
1093+ & bound,
10921094 consistency,
10931095 serial_consistency,
10941096 page_size,
@@ -1181,11 +1183,9 @@ impl Session {
11811183 // Making QueryPager::new_for_query work with values is too hard (if even possible)
11821184 // so instead of sending one prepare to a specific connection on each iterator query,
11831185 // we fully prepare a statement beforehand.
1184- let prepared = self . prepare ( statement) . await ?;
1185- let values = prepared. serialize_values ( & values) ?;
1186+ let bound = self . prepare ( statement) . await ?. into_bind ( & values) ?;
11861187 QueryPager :: new_for_prepared_statement ( PreparedPagerConfig {
1187- prepared,
1188- values,
1188+ bound,
11891189 execution_profile,
11901190 cluster_state : self . cluster . get_state ( ) ,
11911191 #[ cfg( feature = "metrics" ) ]
@@ -1293,13 +1293,9 @@ impl Session {
12931293
12941294 async fn do_execute_unpaged (
12951295 & self ,
1296- prepared : & PreparedStatement ,
1297- values : impl SerializeRow ,
1296+ bound : & BoundStatement < ' _ > ,
12981297 ) -> Result < QueryResult , ExecutionError > {
1299- let serialized_values = prepared. serialize_values ( & values) ?;
1300- let ( result, paging_state) = self
1301- . execute ( prepared, & serialized_values, None , PagingState :: start ( ) )
1302- . await ?;
1298+ let ( result, paging_state) = self . execute ( bound, None , PagingState :: start ( ) ) . await ?;
13031299 if !paging_state. finished ( ) {
13041300 error ! ( "Unpaged prepared query returned a non-empty paging state! This is a driver-side or server-side bug." ) ;
13051301 return Err ( ExecutionError :: LastAttemptError (
@@ -1311,14 +1307,11 @@ impl Session {
13111307
13121308 async fn do_execute_single_page (
13131309 & self ,
1314- prepared : & PreparedStatement ,
1315- values : impl SerializeRow ,
1310+ bound : & BoundStatement < ' _ > ,
13161311 paging_state : PagingState ,
13171312 ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1318- let serialized_values = prepared. serialize_values ( & values) ?;
1319- let page_size = prepared. get_validated_page_size ( ) ;
1320- self . execute ( prepared, & serialized_values, Some ( page_size) , paging_state)
1321- . await
1313+ let page_size = bound. prepared . get_validated_page_size ( ) ;
1314+ self . execute ( bound, Some ( page_size) , paging_state) . await
13221315 }
13231316
13241317 /// Sends a prepared request to the database, optionally continuing from a saved point.
@@ -1333,44 +1326,45 @@ impl Session {
13331326 /// should be made.
13341327 async fn execute (
13351328 & self ,
1336- prepared : & PreparedStatement ,
1337- serialized_values : & SerializedValues ,
1329+ bound : & BoundStatement < ' _ > ,
13381330 page_size : Option < PageSize > ,
13391331 paging_state : PagingState ,
13401332 ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1341- let values_ref = & serialized_values;
13421333 let paging_state_ref = & paging_state;
13431334
1344- let ( partition_key, token) = prepared
1345- . extract_partition_key_and_calculate_token ( prepared . get_partitioner_name ( ) , values_ref )
1335+ let ( partition_key, token) = bound
1336+ . pk_and_token ( )
13461337 . map_err ( PartitionKeyError :: into_execution_error) ?
13471338 . unzip ( ) ;
13481339
1349- let execution_profile = prepared
1340+ let execution_profile = bound
1341+ . prepared
13501342 . get_execution_profile_handle ( )
13511343 . unwrap_or_else ( || self . get_default_execution_profile_handle ( ) )
13521344 . access ( ) ;
13531345
1354- let table_spec = prepared. get_table_spec ( ) ;
1346+ let table_spec = bound . prepared . get_table_spec ( ) ;
13551347
13561348 let statement_info = RoutingInfo {
1357- consistency : prepared
1349+ consistency : bound
1350+ . prepared
13581351 . config
13591352 . consistency
13601353 . unwrap_or ( execution_profile. consistency ) ,
1361- serial_consistency : prepared
1354+ serial_consistency : bound
1355+ . prepared
13621356 . config
13631357 . serial_consistency
13641358 . unwrap_or ( execution_profile. serial_consistency ) ,
13651359 token,
13661360 table : table_spec,
1367- is_confirmed_lwt : prepared. is_confirmed_lwt ( ) ,
1361+ is_confirmed_lwt : bound . prepared . is_confirmed_lwt ( ) ,
13681362 } ;
13691363
13701364 let span = RequestSpan :: new_prepared (
13711365 partition_key. as_ref ( ) . map ( |pk| pk. iter ( ) ) ,
13721366 token,
1373- serialized_values . buffer_size ( ) ,
1367+ bound . values . buffer_size ( ) ,
13741368 ) ;
13751369
13761370 if !span. span ( ) . is_disabled ( ) {
@@ -1384,20 +1378,20 @@ impl Session {
13841378 let run_request_result: RunRequestResult < NonErrorQueryResponse > = self
13851379 . run_request (
13861380 statement_info,
1387- & prepared. config ,
1381+ & bound . prepared . config ,
13881382 execution_profile,
13891383 |connection : Arc < Connection > ,
13901384 consistency : Consistency ,
13911385 execution_profile : & ExecutionProfileInner | {
1392- let serial_consistency = prepared
1386+ let serial_consistency = bound
1387+ . prepared
13931388 . config
13941389 . serial_consistency
13951390 . unwrap_or ( execution_profile. serial_consistency ) ;
13961391 async move {
13971392 connection
13981393 . execute_raw_with_consistency (
1399- prepared,
1400- values_ref,
1394+ bound,
14011395 consistency,
14021396 serial_consistency,
14031397 page_size,
@@ -1432,19 +1426,16 @@ impl Session {
14321426
14331427 async fn do_execute_iter (
14341428 & self ,
1435- prepared : PreparedStatement ,
1436- values : impl SerializeRow ,
1429+ bound : BoundStatement < ' static > ,
14371430 ) -> Result < QueryPager , PagerExecutionError > {
1438- let serialized_values = prepared. serialize_values ( & values) ?;
1439-
1440- let execution_profile = prepared
1431+ let execution_profile = bound
1432+ . prepared
14411433 . get_execution_profile_handle ( )
14421434 . unwrap_or_else ( || self . get_default_execution_profile_handle ( ) )
14431435 . access ( ) ;
14441436
14451437 QueryPager :: new_for_prepared_statement ( PreparedPagerConfig {
1446- prepared,
1447- values : serialized_values,
1438+ bound,
14481439 execution_profile,
14491440 cluster_state : self . cluster . get_state ( ) ,
14501441 #[ cfg( feature = "metrics" ) ]
0 commit comments