1# 2022 September 25 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# Tests for the SQLITE_RECOVER_SLOWINDEXES option. 13# 14 15source [file join [file dirname [info script]] recover_common.tcl] 16set testprefix recoverslowidx 17 18do_execsql_test 1.0 { 19 PRAGMA auto_vacuum = 0; 20 CREATE TABLE t1(a, b); 21 CREATE INDEX i1 ON t1(a); 22 INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4); 23} 24 25proc my_sql_hook {sql} { 26 lappend ::lSql $sql 27 return 0 28} 29 30do_test 1.1 { 31 set lSql [list] 32 set R [sqlite3_recover_init_sql db main my_sql_hook] 33 while {[$R step]==0} { } 34 $R finish 35} {} 36 37do_test 1.2 { 38 set lSql 39} [list {*}{ 40 {BEGIN} 41 {PRAGMA writable_schema = on} 42 {PRAGMA encoding = 'UTF-8'} 43 {PRAGMA page_size = '1024'} 44 {PRAGMA auto_vacuum = '0'} 45 {PRAGMA user_version = '0'} 46 {PRAGMA application_id = '0'} 47 {CREATE TABLE t1(a, b)} 48 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (1, 1, 1)} 49 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (2, 2, 2)} 50 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (3, 3, 3)} 51 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (4, 4, 4)} 52 {CREATE INDEX i1 ON t1(a)} 53 {PRAGMA writable_schema = off} 54 {COMMIT} 55}] 56 57do_test 1.3 { 58 set lSql [list] 59 set R [sqlite3_recover_init_sql db main my_sql_hook] 60 $R config slowindexes 1 61 while {[$R step]==0} { } 62 $R finish 63} {} 64 65do_test 1.4 { 66 set lSql 67} [list {*}{ 68 {BEGIN} 69 {PRAGMA writable_schema = on} 70 {PRAGMA encoding = 'UTF-8'} 71 {PRAGMA page_size = '1024'} 72 {PRAGMA auto_vacuum = '0'} 73 {PRAGMA user_version = '0'} 74 {PRAGMA application_id = '0'} 75 {CREATE TABLE t1(a, b)} 76 {CREATE INDEX i1 ON t1(a)} 77 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (1, 1, 1)} 78 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (2, 2, 2)} 79 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (3, 3, 3)} 80 {INSERT OR IGNORE INTO 't1'(_rowid_, 'a', 'b') VALUES (4, 4, 4)} 81 {PRAGMA writable_schema = off} 82 {COMMIT} 83}] 84 85 86finish_test 87 88