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 #*************************************************************************
12 # Tests for the secure_delete pragma.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix securedel2
19 # Generate 1000 pseudo-random 64-bit blobs.
21 for {set i 1} {$i <= 1000} {incr i} {
22 set aBlob($i) [string range [db one {SELECT quote(randomblob(8))}] 2 end-1]
25 proc detect_blob_prepare {zFile} {
26 set nByte [file size $zFile]
27 set ::detect_blob_data [hexio_read $zFile 0 $nByte]
30 proc detect_blob {zFile iBlob} {
31 if {$zFile != ""} { detect_blob_prepare $zFile }
32 string match "*$::aBlob($iBlob)*" $::detect_blob_data
36 execsql { PRAGMA secure_delete = 1 }
37 execsql { PRAGMA auto_vacuum = 0 }
38 execsql { CREATE TABLE t1(x, y) }
39 for {set i 1} {$i <= 1000} {incr i} {
40 set x "X'[string repeat $aBlob($i) 1]'"
41 set y "X'[string repeat $aBlob($i) 500]'"
42 execsql "INSERT INTO t1 VALUES($x, $y)"
46 do_test 1.2 { detect_blob test.db 1 } {1}
48 forcecopy test.db test.db.bak
49 do_execsql_test 1.3.1 { PRAGMA secure_delete = 0 } {0}
50 do_execsql_test 1.3.2 { DELETE FROM t1 WHERE rowid = 1 }
51 do_test 1.3.3 { detect_blob test.db 1 } {1}
54 forcecopy test.db.bak test.db
56 do_execsql_test 1.4.1 { PRAGMA secure_delete = 1 } {1}
57 do_execsql_test 1.4.2 { DELETE FROM t1 WHERE rowid = 1 }
58 do_test 1.4.3 { detect_blob test.db 1 } {0}
60 do_execsql_test 1.5.1 { DELETE FROM t1 WHERE rowid>850 } {}
63 detect_blob_prepare test.db
64 for {set i 851} {$i <= 1000} {incr i 5} {
65 incr n [detect_blob {} $i]
74 PRAGMA cache_size = 200;
75 PRAGMA secure_delete = 1;
79 for {set i 100} {$i < 5000} {incr i} {
80 execsql { INSERT INTO t2 VALUES(randomblob($i)) }
82 execsql { DELETE FROM t1 }
87 detect_blob_prepare test.db
88 for {set i 2} {$i <= 850} {incr i 5} {
89 incr n [detect_blob {} $i]