@@ -38,6 +38,7 @@ use crate::routing::partitioner::PartitionerName;
38
38
use crate :: routing:: { Shard , ShardAwarePortRange } ;
39
39
use crate :: statement:: batch:: batch_values;
40
40
use crate :: statement:: batch:: { Batch , BatchStatement } ;
41
+ use crate :: statement:: bound:: BoundStatement ;
41
42
use crate :: statement:: prepared:: { PartitionKeyError , PreparedStatement } ;
42
43
use crate :: statement:: unprepared:: Statement ;
43
44
use crate :: statement:: { Consistency , PageSize , StatementConfig } ;
@@ -47,7 +48,7 @@ use futures::future::try_join_all;
47
48
use itertools:: Itertools ;
48
49
use scylla_cql:: frame:: response:: NonErrorResponse ;
49
50
use scylla_cql:: serialize:: batch:: BatchValues ;
50
- use scylla_cql:: serialize:: row:: { SerializeRow , SerializedValues } ;
51
+ use scylla_cql:: serialize:: row:: SerializeRow ;
51
52
use std:: borrow:: Borrow ;
52
53
use std:: future:: Future ;
53
54
use std:: net:: { IpAddr , SocketAddr } ;
@@ -640,7 +641,8 @@ impl Session {
640
641
prepared : & PreparedStatement ,
641
642
values : impl SerializeRow ,
642
643
) -> Result < QueryResult , ExecutionError > {
643
- self . do_execute_unpaged ( prepared, values) . await
644
+ let bound = prepared. bind ( & values) ?;
645
+ self . do_execute_unpaged ( & bound) . await
644
646
}
645
647
646
648
/// Executes a prepared statement, restricting results to single page.
@@ -705,8 +707,8 @@ impl Session {
705
707
values : impl SerializeRow ,
706
708
paging_state : PagingState ,
707
709
) -> 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
710
712
}
711
713
712
714
/// Execute a prepared statement with paging.\
@@ -753,7 +755,8 @@ impl Session {
753
755
prepared : impl Into < PreparedStatement > ,
754
756
values : impl SerializeRow ,
755
757
) -> 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
757
760
}
758
761
759
762
/// Execute a batch statement\
@@ -1085,12 +1088,11 @@ impl Session {
1085
1088
. and_then ( QueryResponse :: into_non_error_query_response)
1086
1089
} else {
1087
1090
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 ( ) ) ;
1090
1093
connection
1091
1094
. execute_raw_with_consistency (
1092
- & prepared,
1093
- & serialized,
1095
+ & bound,
1094
1096
consistency,
1095
1097
serial_consistency,
1096
1098
page_size,
@@ -1183,11 +1185,9 @@ impl Session {
1183
1185
// Making QueryPager::new_for_query work with values is too hard (if even possible)
1184
1186
// so instead of sending one prepare to a specific connection on each iterator query,
1185
1187
// we fully prepare a statement beforehand.
1186
- let prepared = self . prepare_nongeneric ( & statement) . await ?;
1187
- let values = prepared. serialize_values ( & values) ?;
1188
+ let bound = self . prepare_nongeneric ( & statement) . await ?. into_bind ( & values) ?;
1188
1189
QueryPager :: new_for_prepared_statement ( PreparedPagerConfig {
1189
- prepared,
1190
- values,
1190
+ bound,
1191
1191
execution_profile,
1192
1192
cluster_state : self . cluster . get_state ( ) ,
1193
1193
#[ cfg( feature = "metrics" ) ]
@@ -1356,13 +1356,9 @@ impl Session {
1356
1356
1357
1357
async fn do_execute_unpaged (
1358
1358
& self ,
1359
- prepared : & PreparedStatement ,
1360
- values : impl SerializeRow ,
1359
+ bound : & BoundStatement < ' _ > ,
1361
1360
) -> Result < QueryResult , ExecutionError > {
1362
- let serialized_values = prepared. serialize_values ( & values) ?;
1363
- let ( result, paging_state) = self
1364
- . execute ( prepared, & serialized_values, None , PagingState :: start ( ) )
1365
- . await ?;
1361
+ let ( result, paging_state) = self . execute ( bound, None , PagingState :: start ( ) ) . await ?;
1366
1362
if !paging_state. finished ( ) {
1367
1363
error ! ( "Unpaged prepared query returned a non-empty paging state! This is a driver-side or server-side bug." ) ;
1368
1364
return Err ( ExecutionError :: LastAttemptError (
@@ -1374,14 +1370,11 @@ impl Session {
1374
1370
1375
1371
async fn do_execute_single_page (
1376
1372
& self ,
1377
- prepared : & PreparedStatement ,
1378
- values : impl SerializeRow ,
1373
+ bound : & BoundStatement < ' _ > ,
1379
1374
paging_state : PagingState ,
1380
1375
) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1381
- let serialized_values = prepared. serialize_values ( & values) ?;
1382
- let page_size = prepared. get_validated_page_size ( ) ;
1383
- self . execute ( prepared, & serialized_values, Some ( page_size) , paging_state)
1384
- . await
1376
+ let page_size = bound. prepared . get_validated_page_size ( ) ;
1377
+ self . execute ( bound, Some ( page_size) , paging_state) . await
1385
1378
}
1386
1379
1387
1380
/// Sends a prepared request to the database, optionally continuing from a saved point.
@@ -1396,44 +1389,45 @@ impl Session {
1396
1389
/// should be made.
1397
1390
async fn execute (
1398
1391
& self ,
1399
- prepared : & PreparedStatement ,
1400
- serialized_values : & SerializedValues ,
1392
+ bound : & BoundStatement < ' _ > ,
1401
1393
page_size : Option < PageSize > ,
1402
1394
paging_state : PagingState ,
1403
1395
) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1404
- let values_ref = & serialized_values;
1405
1396
let paging_state_ref = & paging_state;
1406
1397
1407
- let ( partition_key, token) = prepared
1408
- . extract_partition_key_and_calculate_token ( prepared . get_partitioner_name ( ) , values_ref )
1398
+ let ( partition_key, token) = bound
1399
+ . pk_and_token ( )
1409
1400
. map_err ( PartitionKeyError :: into_execution_error) ?
1410
1401
. unzip ( ) ;
1411
1402
1412
- let execution_profile = prepared
1403
+ let execution_profile = bound
1404
+ . prepared
1413
1405
. get_execution_profile_handle ( )
1414
1406
. unwrap_or_else ( || self . get_default_execution_profile_handle ( ) )
1415
1407
. access ( ) ;
1416
1408
1417
- let table_spec = prepared. get_table_spec ( ) ;
1409
+ let table_spec = bound . prepared . get_table_spec ( ) ;
1418
1410
1419
1411
let statement_info = RoutingInfo {
1420
- consistency : prepared
1412
+ consistency : bound
1413
+ . prepared
1421
1414
. config
1422
1415
. consistency
1423
1416
. unwrap_or ( execution_profile. consistency ) ,
1424
- serial_consistency : prepared
1417
+ serial_consistency : bound
1418
+ . prepared
1425
1419
. config
1426
1420
. serial_consistency
1427
1421
. unwrap_or ( execution_profile. serial_consistency ) ,
1428
1422
token,
1429
1423
table : table_spec,
1430
- is_confirmed_lwt : prepared. is_confirmed_lwt ( ) ,
1424
+ is_confirmed_lwt : bound . prepared . is_confirmed_lwt ( ) ,
1431
1425
} ;
1432
1426
1433
1427
let span = RequestSpan :: new_prepared (
1434
1428
partition_key. as_ref ( ) . map ( |pk| pk. iter ( ) ) ,
1435
1429
token,
1436
- serialized_values . buffer_size ( ) ,
1430
+ bound . values . buffer_size ( ) ,
1437
1431
) ;
1438
1432
1439
1433
if !span. span ( ) . is_disabled ( ) {
@@ -1450,20 +1444,20 @@ impl Session {
1450
1444
) = self
1451
1445
. run_request (
1452
1446
statement_info,
1453
- & prepared. config ,
1447
+ & bound . prepared . config ,
1454
1448
execution_profile,
1455
1449
|connection : Arc < Connection > ,
1456
1450
consistency : Consistency ,
1457
1451
execution_profile : & ExecutionProfileInner | {
1458
- let serial_consistency = prepared
1452
+ let serial_consistency = bound
1453
+ . prepared
1459
1454
. config
1460
1455
. serial_consistency
1461
1456
. unwrap_or ( execution_profile. serial_consistency ) ;
1462
1457
async move {
1463
1458
connection
1464
1459
. execute_raw_with_consistency (
1465
- prepared,
1466
- values_ref,
1460
+ bound,
1467
1461
consistency,
1468
1462
serial_consistency,
1469
1463
page_size,
@@ -1496,19 +1490,16 @@ impl Session {
1496
1490
1497
1491
async fn do_execute_iter (
1498
1492
& self ,
1499
- prepared : PreparedStatement ,
1500
- values : impl SerializeRow ,
1493
+ bound : BoundStatement < ' static > ,
1501
1494
) -> Result < QueryPager , PagerExecutionError > {
1502
- let serialized_values = prepared. serialize_values ( & values) ?;
1503
-
1504
- let execution_profile = prepared
1495
+ let execution_profile = bound
1496
+ . prepared
1505
1497
. get_execution_profile_handle ( )
1506
1498
. unwrap_or_else ( || self . get_default_execution_profile_handle ( ) )
1507
1499
. access ( ) ;
1508
1500
1509
1501
QueryPager :: new_for_prepared_statement ( PreparedPagerConfig {
1510
- prepared,
1511
- values : serialized_values,
1502
+ bound,
1512
1503
execution_profile,
1513
1504
cluster_state : self . cluster . get_state ( ) ,
1514
1505
#[ cfg( feature = "metrics" ) ]
0 commit comments