interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / autovacuum2.test

87 lines · 2275 bytes Raw Blame History
1# 2021-10-15
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is testing the sqlite3_autovacuum_pages() interface
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18# If this build of the library does not support auto-vacuum, omit this
19# whole file.
20ifcapable {!autovacuum || !pragma} {
21 finish_test
22 return
23}
24
25# Demonstrate basic sqlite3_autovacuum_pages functionality
26#
27do_execsql_test autovacuum2-1.0 {
28 PRAGMA page_size=1024;
29 PRAGMA auto_vacuum=FULL;
30 CREATE TABLE t1(x);
31 VACUUM;
32 INSERT INTO t1(x) VALUES(zeroblob(10000));
33 PRAGMA page_count;
34} {12}
35proc 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}]
39}
40sqlite3_autovacuum_pages db autovac_page_callback
41set autovac_callback_data {}
42do_execsql_test autovacuum2-1.1 {
43 BEGIN;
44 DELETE FROM t1;
45 PRAGMA freelist_count;
46 PRAGMA page_count;
47} {9 12}
48do_execsql_test autovacuum2-1.2 {
49 COMMIT;
50} {}
51do_test autovacuum2-1.3 {
52 set autovac_callback_data
53} {main 12 9 1024}
54do_execsql_test autovacuum2-1.4 {
55 PRAGMA freelist_count;
56 PRAGMA page_count;
57} {5 8}
58do_execsql_test autovacuum2-1.5 {
59 PRAGMA integrity_check;
60} {ok}
61
62# Disable the autovacuum-pages callback. Then do any transaction.
63# The database should shrink to minimal size
64#
65sqlite3_autovacuum_pages db
66do_execsql_test autovacuum2-1.10 {
67 CREATE TABLE t2(x);
68 PRAGMA freelist_count;
69} {0}
70
71# Rig the autovacuum-pages callback to always return zero. No
72# autovacuum will happen.
73#
74proc autovac_page_callback_off {schema filesize freesize pagesize} {
75 return 0
76}
77sqlite3_autovacuum_pages db autovac_page_callback_off
78do_execsql_test autovacuum2-1.20 {
79 BEGIN;
80 INSERT INTO t1(x) VALUES(zeroblob(10000));
81 DELETE FROM t1;
82 PRAGMA freelist_count;
83 COMMIT;
84 PRAGMA freelist_count;
85} {9 9}
86
87finish_test