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/ext/session/sessionfault3.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 / ext / session / sessionfault3.test` 195 lines ยท 4736 bytes Raw Blame History 1 # 2016 October 6 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 # The focus of this file is testing the session module. 13 # 14 15 if {![info exists testdir]} { 16 set testdir [file join [file dirname [info script]] .. .. test] 17 } 18 source [file join [file dirname [info script]] session_common.tcl] 19 source $testdir/tester.tcl 20 ifcapable !session {finish_test; return} 21 set testprefix sessionfault3 22 23 do_execsql_test 1.0 { 24 CREATE TABLE t1(a, b, PRIMARY KEY(a)); 25 INSERT INTO t1 VALUES(1, 2); 26 INSERT INTO t1 VALUES(3, 4); 27 INSERT INTO t1 VALUES('five', 'six'); 28 } 29 30 set C1 [changeset_from_sql { 31 INSERT INTO t1 VALUES('seven', 'eight'); 32 UPDATE t1 SET b=6 WHERE a='five'; 33 DELETE FROM t1 WHERE a=1; 34 }] 35 36 do_execsql_test 1.1 { 37 ALTER TABLE t1 ADD COLUMN d DEFAULT 123; 38 ALTER TABLE t1 ADD COLUMN e DEFAULT 'string'; 39 } 40 41 set C2 [changeset_from_sql { 42 UPDATE t1 SET e='new value' WHERE a='seven'; 43 INSERT INTO t1 VALUES(0, 0, 0, 0); 44 }] 45 46 do_faultsim_test 1.2 -faults oom* -prep { 47 sqlite3changegroup G 48 } -body { 49 G schema db main 50 G add $::C1 51 G add $::C2 52 G output 53 set {} {} 54 } -test { 55 catch { G delete } 56 faultsim_test_result {0 {}} {1 SQLITE_NOMEM} 57 } 58 59 do_faultsim_test 1.3 -faults oom* -prep { 60 sqlite3changegroup G 61 } -body { 62 G schema db main 63 G change_begin INSERT t1 0 64 G change_int64 new 0 12345 65 G change_int64 new 1 67890 66 G output 67 set {} {} 68 } -test { 69 catch { G delete } 70 faultsim_test_result \ 71 {0 {}} \ 72 {1 SQLITE_NOMEM} \ 73 {1 {SQLITE_NOMEM - no such table: t1}} 74 } 75 76 #------------------------------------------------------------------------- 77 reset_db 78 do_execsql_test 2.0 { 79 CREATE TABLE t1(a INTEGER PRIMARY KEY, b); 80 INSERT INTO t1 VALUES(1, 'one'); 81 INSERT INTO t1 VALUES(2, 'two'); 82 ALTER TABLE t1 ADD COLUMN c DEFAULT 'abcdefghijklmnopqrstuvwxyz'; 83 } 84 faultsim_save_and_close 85 86 do_faultsim_test 2 -faults oom-t* -prep { 87 faultsim_restore_and_reopen 88 db eval {SELECT * FROM sqlite_schema} 89 } -body { 90 sqlite3session S db main 91 S attach * 92 execsql { 93 DELETE FROM t1 WHERE a = 1; 94 } 95 } -test { 96 faultsim_test_result {0 {}} {1 SQLITE_NOMEM} 97 catch { S delete } 98 } 99 100 #------------------------------------------------------------------------- 101 reset_db 102 do_execsql_test 3.0 { 103 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); 104 INSERT INTO t1 VALUES(1, 'one'); 105 INSERT INTO t1 VALUES(2, 'two'); 106 INSERT INTO t1 VALUES(3, 'three'); 107 INSERT INTO t1 VALUES(4, 'four'); 108 INSERT INTO t1 VALUES(5, 'five'); 109 } 110 faultsim_save_and_close 111 faultsim_restore_and_reopen 112 113 set C [changeset_from_sql { 114 UPDATE t1 SET b=NULL WHERE a IN (1, 3, 5); 115 UPDATE t1 SET b='three' WHERE a=1; 116 UPDATE t1 SET b='five' WHERE a=3; 117 UPDATE t1 SET b='one' WHERE a=5; 118 }] 119 120 do_execsql_test 3.1 { 121 SELECT * FROM t1 122 } { 123 1 three 2 two 3 five 4 four 5 one 124 } 125 126 proc xConflict {args} { 127 lappend ::conflict_list $args 128 return "OMIT" 129 } 130 131 do_faultsim_test 3 -faults oom* -prep { 132 faultsim_restore_and_reopen 133 db eval {SELECT * FROM sqlite_schema} 134 } -body { 135 sqlite3changeset_apply_v2 db $::C xConflict 136 set {} {} 137 } -test { 138 faultsim_test_result {0 {}} {1 SQLITE_NOMEM} 139 } 140 141 #------------------------------------------------------------------------- 142 # Test that an OOM in change_begin() or a change_xxx() function does not 143 # leave a partially constructed change behind. 144 # 145 # Report: https://sqlite.org/bugs/forumpost/`875fb2b46f` 146 # 147 reset_db 148 do_execsql_test 4.0 { 149 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); 150 } 151 152 do_faultsim_test 4 -faults oom* -prep { 153 sqlite3changegroup G 154 G schema db main 155 G change_begin INSERT t1 0 156 G change_finish 1 157 } -body { 158 G change_begin UPDATE t1 0 159 } -test { 160 faultsim_test_result {0 {}} {1 SQLITE_NOMEM} 161 if {$testrc} { G change_begin UPDATE t1 0 } 162 G change_finish 1 163 G delete 164 } 165 166 do_faultsim_test 5 -faults oom* -prep { 167 sqlite3changegroup G 168 G schema db main 169 G change_begin INSERT t1 0 170 G change_int64 new 0 1 171 G change_int64 new 1 1 172 G change_null new 2 173 G change_null new 3 174 G change_finish 0 175 G change_begin INSERT t1 0 176 G change_int64 new 0 2 177 G change_null new 2 178 G change_null new 3 179 } -body { 180 G change_blob new 1 [binary format x400] 181 } -test { 182 faultsim_test_result {0 {}} {1 SQLITE_NOMEM} 183 set rc [catch { G change_finish 0 } msg] 184 G delete 185 if {$testrc} { 186 set expect {1 {SQLITE_ERROR - invalid change: column 1 is undefined}} 187 } else { 188 set expect {0 {}} 189 } 190 if {[list $rc $msg]!=$expect} { 191 error "change_finish returned: [list $rc $msg]" 192 } 193 } 194 195 finish_test