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 / shrink.test

55 lines · 1465 bytes Raw Blame History
1# 2011 November 16
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#
12# This file contains test cases for sqlite3_db_release_memory and
13# the PRAGMA shrink_memory statement.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18test_set_config_pagecache 0 0
19
20if {[sqlite3_memory_used]==0} {
21 # SQLITE_DEFAULT_MEMSTATUS=0 build.
22 finish_test
23 return
24}
25
26
27unset -nocomplain baseline
28do_test shrink-1.1 {
29 db eval {
30 PRAGMA cache_size = 2000;
31 CREATE TABLE t1(x,y);
32 INSERT INTO t1 VALUES(randomblob(1000000),1);
33 }
34 set ::baseline [sqlite3_memory_used]
35 # EVIDENCE-OF: R-58814-63508 The sqlite3_db_release_memory(D) interface
36 # attempts to free as much heap memory as possible from database
37 # connection D.
38 sqlite3_db_release_memory db
39 expr {$::baseline > [sqlite3_memory_used]+500000}
40} {1}
41do_test shrink-1.2 {
42 set baseline [sqlite3_memory_used]
43 db eval {
44 UPDATE t1 SET y=y+1;
45 }
46 expr {$::baseline+500000 < [sqlite3_memory_used]}
47} {1}
48do_test shrink-1.3 {
49 set baseline [sqlite3_memory_used]
50 db eval {PRAGMA shrink_memory}
51 expr {$::baseline > [sqlite3_memory_used]+500000}
52} {1}
53
54test_restore_config_pagecache
55finish_test