@@ -495,7 +495,22 @@ impl Connection {
495
495
}
496
496
497
497
pub ( crate ) fn wal_checkpoint ( & self , truncate : bool ) -> Result < ( ) > {
498
- let rc = unsafe { libsql_sys:: ffi:: sqlite3_wal_checkpoint_v2 ( self . handle ( ) , std:: ptr:: null ( ) , truncate as i32 , std:: ptr:: null_mut ( ) , std:: ptr:: null_mut ( ) ) } ;
498
+ let mut pn_log = 0i32 ;
499
+ let mut pn_ckpt = 0i32 ;
500
+ let checkpoint_mode = if truncate {
501
+ libsql_sys:: ffi:: SQLITE_CHECKPOINT_TRUNCATE
502
+ } else {
503
+ libsql_sys:: ffi:: SQLITE_CHECKPOINT_PASSIVE
504
+ } ;
505
+ let rc = unsafe {
506
+ libsql_sys:: ffi:: sqlite3_wal_checkpoint_v2 (
507
+ self . handle ( ) ,
508
+ std:: ptr:: null ( ) ,
509
+ checkpoint_mode,
510
+ & mut pn_log,
511
+ & mut pn_ckpt,
512
+ )
513
+ } ;
499
514
if rc != 0 {
500
515
let err_msg = unsafe { libsql_sys:: ffi:: sqlite3_errmsg ( self . handle ( ) ) } ;
501
516
let err_msg = unsafe { std:: ffi:: CStr :: from_ptr ( err_msg) } ;
@@ -505,6 +520,12 @@ impl Connection {
505
520
format ! ( "Failed to checkpoint WAL: {}" , err_msg) ,
506
521
) ) ;
507
522
}
523
+ if truncate && ( pn_log != 0 || pn_ckpt != 0 ) {
524
+ return Err ( crate :: errors:: Error :: SqliteFailure (
525
+ libsql_sys:: ffi:: SQLITE_ERROR ,
526
+ "unable to truncate WAL" . to_string ( ) ,
527
+ ) ) ;
528
+ }
508
529
Ok ( ( ) )
509
530
}
510
531
@@ -596,17 +617,16 @@ impl Connection {
596
617
)
597
618
} ;
598
619
620
+ if conflict != 0 {
621
+ return Err ( errors:: Error :: WalConflict ) ;
622
+ }
599
623
if rc != 0 {
600
624
return Err ( errors:: Error :: SqliteFailure (
601
625
rc as std:: ffi:: c_int ,
602
626
"wal_insert_frame failed" . to_string ( ) ,
603
627
) ) ;
604
628
}
605
629
606
- if conflict != 0 {
607
- return Err ( errors:: Error :: WalConflict ) ;
608
- }
609
-
610
630
Ok ( ( ) )
611
631
}
612
632
0 commit comments