CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
autovacuum2.test88 linesDownload Raw Back to test
1# 2021-10-152#3# The author disclaims copyright to this source code.  In place of4# 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.  The12# focus of this file is testing the sqlite3_autovacuum_pages() interface13#14 15set testdir [file dirname $argv0]16source $testdir/tester.tcl17 18# If this build of the library does not support auto-vacuum, omit this19# whole file.20ifcapable {!autovacuum || !pragma} {21  finish_test22  return23}24 25# Demonstrate basic sqlite3_autovacuum_pages functionality26#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_data37  lappend autovac_callback_data $schema $filesize $freesize $pagesize38  return [expr {$freesize/2}]39}40sqlite3_autovacuum_pages db autovac_page_callback41set 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_data53} {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 size64#65sqlite3_autovacuum_pages db66do_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.  No72# autovacuum will happen.73#74proc autovac_page_callback_off {schema filesize freesize pagesize} {75  return 076}77sqlite3_autovacuum_pages db autovac_page_callback_off78do_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_test88