@@ -495,7 +495,22 @@ impl Connection {
495495 }
496496
497497 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+ } ;
499514 if rc != 0 {
500515 let err_msg = unsafe { libsql_sys:: ffi:: sqlite3_errmsg ( self . handle ( ) ) } ;
501516 let err_msg = unsafe { std:: ffi:: CStr :: from_ptr ( err_msg) } ;
@@ -505,6 +520,12 @@ impl Connection {
505520 format ! ( "Failed to checkpoint WAL: {}" , err_msg) ,
506521 ) ) ;
507522 }
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+ }
508529 Ok ( ( ) )
509530 }
510531
@@ -596,17 +617,16 @@ impl Connection {
596617 )
597618 } ;
598619
620+ if conflict != 0 {
621+ return Err ( errors:: Error :: WalConflict ) ;
622+ }
599623 if rc != 0 {
600624 return Err ( errors:: Error :: SqliteFailure (
601625 rc as std:: ffi:: c_int ,
602626 "wal_insert_frame failed" . to_string ( ) ,
603627 ) ) ;
604628 }
605629
606- if conflict != 0 {
607- return Err ( errors:: Error :: WalConflict ) ;
608- }
609-
610630 Ok ( ( ) )
611631 }
612632
0 commit comments