Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/autovacuum2.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 18 # If this build of the library does not support auto-vacuum, omit this 19 # whole file. 20 ifcapable {!autovacuum || !pragma} { 21 finish_test 22 return 23 } 24 25 # Demonstrate basic sqlite3_autovacuum_pages functionality 26 # 27 do_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} 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}] 39 } 40 sqlite3_autovacuum_pages db autovac_page_callback 41 set autovac_callback_data {} 42 do_execsql_test autovacuum2-1.1 { 43 BEGIN; 44 DELETE FROM t1; 45 PRAGMA freelist_count; 46 PRAGMA page_count; 47 } {9 12} 48 do_execsql_test autovacuum2-1.2 { 49 COMMIT; 50 } {} 51 do_test autovacuum2-1.3 { 52 set autovac_callback_data 53 } {main 12 9 1024} 54 do_execsql_test autovacuum2-1.4 { 55 PRAGMA freelist_count; 56 PRAGMA page_count; 57 } {5 8} 58 do_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 # 65 sqlite3_autovacuum_pages db 66 do_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 # 74 proc autovac_page_callback_off {schema filesize freesize pagesize} { 75 return 0 76 } 77 sqlite3_autovacuum_pages db autovac_page_callback_off 78 do_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 87 finish_test