3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the sqlite3_autovacuum_pages() interface
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 # If this build of the library does not support auto-vacuum, omit this
20 ifcapable {!autovacuum || !pragma} {
25 # Demonstrate basic sqlite3_autovacuum_pages functionality
27 do_execsql_test autovacuum2-1.0 {
28 PRAGMA page_size=1024;
29 PRAGMA auto_vacuum=FULL;
32 INSERT INTO t1(x) VALUES(zeroblob(10000));
35 proc autovac_page_callback {schema filesize freesize pagesize} {
36 global autovac_callback_data
37 lappend autovac_callback_data $schema $filesize $freesize $pagesize
38 return [expr {$freesize/2}]
40 sqlite3_autovacuum_pages db autovac_page_callback
41 set autovac_callback_data {}
42 do_execsql_test autovacuum2-1.1 {
45 PRAGMA freelist_count;
48 do_execsql_test autovacuum2-1.2 {
51 do_test autovacuum2-1.3 {
52 set autovac_callback_data
54 do_execsql_test autovacuum2-1.4 {
55 PRAGMA freelist_count;
58 do_execsql_test autovacuum2-1.5 {
59 PRAGMA integrity_check;
62 # Disable the autovacuum-pages callback. Then do any transaction.
63 # The database should shrink to minimal size
65 sqlite3_autovacuum_pages db
66 do_execsql_test autovacuum2-1.10 {
68 PRAGMA freelist_count;
71 # Rig the autovacuum-pages callback to always return zero. No
72 # autovacuum will happen.
74 proc autovac_page_callback_off {schema filesize freesize pagesize} {
77 sqlite3_autovacuum_pages db autovac_page_callback_off
78 do_execsql_test autovacuum2-1.20 {
80 INSERT INTO t1(x) VALUES(zeroblob(10000));
82 PRAGMA freelist_count;
84 PRAGMA freelist_count;