1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Have sqlite3_wal_checkpoint() handle a zero-length string in the same way as a NULL pointer. Fix "PRAGMA wal_checkpoint" so that it checkpoints all attached databases.

FossilOrigin-Name: 7fecd21f45b9ce773ffbcef6c84066474e8cd01c
This commit is contained in:
dan
2010-05-03 15:58:50 +00:00
parent b7e8ea2015
commit af0cfd366a
5 changed files with 77 additions and 23 deletions

View File

@ -1046,6 +1046,68 @@ do_test wal-15.4.6 {
file size test.db
} [expr 1024*2]
catch { db2 close }
catch { db close }
#-------------------------------------------------------------------------
# The following block of tests - wal-16.* - test that if a NULL pointer or
# an empty string is passed as the second argument of the wal_checkpoint()
# API, an attempt is made to checkpoint all attached databases.
#
foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
1 {sqlite3_wal_checkpoint db} SQLITE_OK 1 1
2 {sqlite3_wal_checkpoint db ""} SQLITE_OK 1 1
3 {db eval "PRAGMA wal_checkpoint"} {} 1 1
4 {sqlite3_wal_checkpoint db main} SQLITE_OK 1 0
5 {sqlite3_wal_checkpoint db aux} SQLITE_OK 0 1
6 {sqlite3_wal_checkpoint db temp} SQLITE_OK 0 0
7 {db eval "PRAGMA main.wal_checkpoint"} {} 1 0
8 {db eval "PRAGMA aux.wal_checkpoint"} {} 0 1
9 {db eval "PRAGMA temp.wal_checkpoint"} {} 0 0
} {
do_test wal-16.$tn.1 {
file delete -force test2.db test2.db-wal test2.db-journal
file delete -force test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
ATTACH 'test2.db' AS aux;
PRAGMA main.journal_mode = WAL;
PRAGMA aux.journal_mode = WAL;
PRAGMA synchronous = NORMAL;
}
} {wal wal}
do_test wal-16.$tn.2 {
execsql {
CREATE TABLE main.t1(a, b, PRIMARY KEY(a, b));
CREATE TABLE aux.t2(a, b, PRIMARY KEY(a, b));
INSERT INTO t2 VALUES(1, randomblob(1000));
INSERT INTO t2 VALUES(2, randomblob(1000));
INSERT INTO t1 SELECT * FROM t2;
}
list [file size test.db] [file size test.db-wal]
} [list [expr 1*1024] [log_file_size 10 1024]]
do_test wal-16.$tn.3 {
list [file size test2.db] [file size test2.db-wal]
} [list [expr 1*1024] [log_file_size 16 1024]]
do_test wal-16.$tn.4 [list eval $ckpt_cmd] $ckpt_res
do_test wal-16.$tn.5 {
list [file size test.db] [file size test.db-wal]
} [list [expr ($ckpt_main ? 7 : 1)*1024] [log_file_size 10 1024]]
do_test wal-16.$tn.6 {
list [file size test2.db] [file size test2.db-wal]
} [list [expr ($ckpt_aux ? 7 : 1)*1024] [log_file_size 16 1024]]
catch { db close }
}
catch { db2 close }
catch { db close }
finish_test