diff --git a/src/main.c b/src/main.c index 6b84674dc7..3530beac55 100644 --- a/src/main.c +++ b/src/main.c @@ -3521,6 +3521,10 @@ static int openDatabase( setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, sqlite3GlobalConfig.nLookaside); + if (strcmp("default", libsql_wal_methods_name(db->pWalMethods)) != 0) { + sqlite3_exec(db, "pragma journal_mode=wal", NULL, NULL, NULL); + } + sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); opendb_out: diff --git a/src/pager.c b/src/pager.c index 6899e03a70..bab3979434 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4893,6 +4893,9 @@ int sqlite3PagerOpen( sqlite3FileSuffix3(zFilename, pPager->zWal); pPtr = (u8*)(pPager->zWal + sqlite3Strlen30(pPager->zWal)+1); #endif + }else{ + pPager->zWal = 0; + } if (pWalMethods->xPreMainDbOpen) { int rc = pWalMethods->xPreMainDbOpen(pWalMethods, zPathname); @@ -4900,10 +4903,6 @@ int sqlite3PagerOpen( return rc; } } - - }else{ - pPager->zWal = 0; - } #endif (void)pPtr; /* Suppress warning about unused pPtr value */ diff --git a/test/rust_suite/src/lib.rs b/test/rust_suite/src/lib.rs index fddd7a1d1d..6514e4d439 100644 --- a/test/rust_suite/src/lib.rs +++ b/test/rust_suite/src/lib.rs @@ -51,6 +51,6 @@ mod tests { let also_steven = person_iter.next().unwrap().unwrap(); println!("Read {:#?}", also_steven); assert!(also_steven == steven); - assert!(person_iter.next() == None) + assert!(person_iter.next().is_none()) } } diff --git a/test/rust_suite/src/virtual_wal.rs b/test/rust_suite/src/virtual_wal.rs index 516f801ac0..06eaaaf237 100644 --- a/test/rust_suite/src/virtual_wal.rs +++ b/test/rust_suite/src/virtual_wal.rs @@ -1,3 +1,4 @@ +#![allow(improper_ctypes)] #[cfg(test)] mod tests { use rusqlite::Connection; @@ -121,8 +122,7 @@ mod tests { db: extern "C" fn(wal: *mut Wal, db: *const c_void), pathname_len: extern "C" fn(orig_len: i32) -> i32, get_pathname: extern "C" fn(buf: *mut u8, orig: *const u8, orig_len: i32), - pre_main_db_open: - extern "C" fn(methods: *mut libsql_wal_methods, name: *const i8) -> i32, + pre_main_db_open: extern "C" fn(methods: *mut libsql_wal_methods, name: *const i8) -> i32, b_uses_shm: i32, name: *const u8, p_next: *const c_void, @@ -165,7 +165,7 @@ mod tests { wal: *mut *const Wal, ) -> i32 { let new_wal = Box::new(Wal { - vfs: vfs, + vfs, db_fd: std::ptr::null(), wal_fd: std::ptr::null(), callback_value: 0, @@ -199,7 +199,7 @@ mod tests { }, min_frame: 0, recalculate_checksums: 0, - wal_name: wal_name, + wal_name, n_checkpoints: 0, lock_error: 0, p_snapshot: std::ptr::null(), @@ -253,12 +253,14 @@ mod tests { return ERR_MISUSE; } let out_buffer = unsafe { std::slice::from_raw_parts_mut(p_out, n_out) }; - out_buffer.copy_from_slice(&data); + out_buffer.copy_from_slice(data); println!("\t\tread {} bytes", data.len()); 0 } - extern "C" fn db_size(_wal: *mut Wal) -> i32 { - ERR_MISUSE + extern "C" fn db_size(wal: *mut Wal) -> i32 { + println!("Db size called"); + let methods = unsafe { &*(*wal).wal_methods }; + methods.pages.len() as i32 } extern "C" fn begin_write(_wal: *mut Wal) -> i32 { println!("Write started"); @@ -300,7 +302,7 @@ mod tests { } .to_vec(); methods.pages.insert(current.pgno, data); - if current.dirty == std::ptr::null() { + if current.dirty.is_null() { break; } current_ptr = current.dirty @@ -334,12 +336,14 @@ mod tests { panic!("Should never be called") } extern "C" fn db(_wal: *mut Wal, _db: *const c_void) {} - extern "C" fn pathname_len(_orig_len: i32) -> i32 { - println!("Returning length 0"); - 0 + extern "C" fn pathname_len(orig_len: i32) -> i32 { + orig_len + 4 } - extern "C" fn get_pathname(_buf: *mut u8, _orig: *const u8, _orig_len: i32) { - panic!("Should never be called") + extern "C" fn get_pathname(buf: *mut u8, orig: *const u8, orig_len: i32) { + unsafe { + std::ptr::copy_nonoverlapping(orig, buf, orig_len as usize); + std::ptr::copy_nonoverlapping(".wal".as_ptr(), buf.offset(orig_len as isize), 4); + } } extern "C" fn pre_main_db_open(_methods: *mut libsql_wal_methods, _name: *const i8) -> i32 { 0 @@ -402,7 +406,11 @@ mod tests { Box::leak(vwal); Connection::from_handle(pdb).unwrap() }; - conn.pragma_update(None, "journal_mode", "wal").unwrap(); + let journal_mode: String = conn + .query_row("PRAGMA journal_mode", [], |r| r.get(0)) + .unwrap(); + println!("Journaling mode: {}", journal_mode); + assert_eq!(journal_mode, "wal".to_string()); conn.execute("CREATE TABLE t(id)", ()).unwrap(); conn.execute("INSERT INTO t(id) VALUES (42)", ()).unwrap(); conn.execute("INSERT INTO t(id) VALUES (zeroblob(8193))", ())