@@ -1302,6 +1302,7 @@ pub enum TransactionStatus {
1302
1302
1303
1303
type UserResult = Result < TransactionStatus , Box < dyn Error > > ;
1304
1304
1305
+ #[ derive( Debug ) ]
1305
1306
enum CallBackError {
1306
1307
// the callback returned an error
1307
1308
ApplicationError ( Box < dyn Error > ) ,
@@ -1390,11 +1391,11 @@ extern "C" fn fn_callback(tptoken: u64, errstr: *mut ydb_buffer_t, tpfnparm: *mu
1390
1391
/// use yottadb::simple_api::{Key, tp_st};
1391
1392
///
1392
1393
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
1393
- /// let var = Key::variable("tpRollbackTest");
1394
+ /// let var = Key::variable("^ tpRollbackTest");
1394
1395
/// var.set_st(TpToken::default(), Vec::new(), "initial value")?;
1395
1396
/// let maybe_err = tp_st(TpToken::default(), Vec::new(), |tptoken| {
1396
- /// fallible_operation()?;
1397
1397
/// var.set_st(tptoken, Vec::new(), "new value")?;
1398
+ /// fallible_operation()?;
1398
1399
/// Ok(TransactionStatus::Ok)
1399
1400
/// }, "BATCH", &[]);
1400
1401
/// let expected_val: &[_] = if maybe_err.is_ok() {
@@ -1457,7 +1458,7 @@ where
1457
1458
let mut err_buffer_t = Key :: make_out_buffer_t ( & mut err_buffer) ;
1458
1459
1459
1460
let mut locals: Vec < ConstYDBBuffer > = Vec :: with_capacity ( locals_to_reset. len ( ) ) ;
1460
- for local in locals_to_reset. iter ( ) {
1461
+ for & local in locals_to_reset. iter ( ) {
1461
1462
locals. push (
1462
1463
ydb_buffer_t {
1463
1464
buf_addr : local. as_ptr ( ) as * const _ as * mut _ ,
@@ -2580,6 +2581,20 @@ pub(crate) mod tests {
2580
2581
}
2581
2582
}
2582
2583
2584
+ #[ test]
2585
+ fn rollback ( ) {
2586
+ let key = Key :: variable ( "^tpRollbackTest" ) ;
2587
+ key. set_st ( YDB_NOTTP , Vec :: new ( ) , "initial" ) . unwrap ( ) ;
2588
+ let set_inner = |tptoken| {
2589
+ key. set_st ( tptoken, Vec :: new ( ) , "val" ) ?;
2590
+ Ok ( TransactionStatus :: Rollback )
2591
+ } ;
2592
+ let err = tp_st ( YDB_NOTTP , Vec :: new ( ) , set_inner, "BATCH" , & [ ] ) . unwrap_err ( ) ;
2593
+ let status = err. downcast :: < YDBError > ( ) . unwrap ( ) . status ;
2594
+ assert_eq ! ( status, craw:: YDB_TP_ROLLBACK ) ;
2595
+ assert_eq ! ( key. get_st( YDB_NOTTP , Vec :: new( ) ) . unwrap( ) , b"initial" ) ;
2596
+ }
2597
+
2583
2598
#[ test]
2584
2599
#[ should_panic]
2585
2600
fn panic_in_cb ( ) {
0 commit comments