Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -4893,17 +4893,16 @@ 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);
if (rc != SQLITE_OK) {
return rc;
}
}

}else{
pPager->zWal = 0;
}
#endif
(void)pPtr; /* Suppress warning about unused pPtr value */

Expand Down
2 changes: 1 addition & 1 deletion test/rust_suite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
36 changes: 22 additions & 14 deletions test/rust_suite/src/virtual_wal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(improper_ctypes)]
#[cfg(test)]
mod tests {
use rusqlite::Connection;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))", ())
Expand Down