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/test/schemareset.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 / test / schemareset.test` 119 lines ยท 3427 bytes Raw Blame History 1 # 2026-10-26 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 implements tests for running DDL or similar statements from 13 # within an application-defined function, such that those statements 14 # cause a schema reset, which then frees the schema out from under 15 # prepared statements that are still using it. 16 # 17 # See bug report https://sqlite.org/bugs/info/`3577bc69c52237a4` 18 # from 2026-10-25. 19 # 20 set testdir [file dirname $argv0] 21 source $testdir/tester.tcl 22 set testprefix schemareset 23 24 ifcapable !vtab { 25 finish_test 26 return 27 } 28 load_static_extension db series 29 load_static_extension db tryeval 30 sqlite3_db_config db DEFENSIVE 0 31 32 do_execsql_test 1.1 { 33 CREATE TABLE t1(a,b); 34 INSERT INTO t1(a,b) SELECT value,value*10 FROM generate_series(1,5); 35 CREATE INDEX t1x ON t1(a); 36 UPDATE t1 37 SET b=coalesce(tryeval('DROP INDEX t1x','SELECT sum(a) FROM t1'),b+1); 38 SELECT * FROM t1 ORDER BY a; 39 } {1 15 2 15 3 15 4 15 5 15} 40 41 do_execsql_test 1.2 { 42 DROP TABLE t1; 43 CREATE TABLE t1(a,b); 44 INSERT INTO t1 VALUES(1,'a'),(2,'b'),(3,'c'); 45 CREATE INDEX t1x ON t1(a); 46 UPDATE t1 47 SET b=coalesce(tryeval('DROP INDEX t1x','SELECT count(*) FROM t1'),'xyz'); 48 SELECT * FROM t1 ORDER BY a; 49 } {1 3 2 3 3 3} 50 51 do_execsql_test 1.3 { 52 DROP TABLE t1; 53 CREATE TABLE t1(a INTEGER PRIMARY KEY, l INT, c INT) STRICT; 54 INSERT INTO t1 VALUES(1,1,1),(2,2,2); 55 UPDATE t1 56 SET c = coalesce(tryeval('PRAGMA schema_version=1000', 57 'SELECT max(l) FROM t'), c+1); 58 SELECT * FROM t1 ORDER BY a; 59 } {1 1 2 2 2 3} 60 61 do_execsql_test 1.4.1 { 62 DROP TABLE t1; 63 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT) STRICT; 64 INSERT INTO t1 VALUES(1,1),(2,2); 65 } 66 do_catchsql_test 1.4.2 { 67 UPDATE t1 68 SET b = coalesce(tryeval('ATTACH ''/no/such/dir/x.db'' AS aux'), b+1); 69 } {1 {database schema has changed}} 70 do_catchsql_test 1.4.3 { 71 SELECT * FROM t1 ORDER BY a; 72 } {0 {1 1 2 2}} 73 74 do_execsql_test 1.5.1 { 75 DROP TABLE t1; 76 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT) STRICT; 77 INSERT INTO t1 VALUES(1,1),(2,2); 78 BEGIN; 79 SAVEPOINT sp; 80 CREATE TABLE zz(x); 81 } 82 do_catchsql_test 1.5.2 { 83 UPDATE t1 84 SET b = coalesce(tryeval('ROLLBACK TO sp', 'SELECT 5'), b+1); 85 } {1 {database schema has changed}} 86 do_execsql_test 1.5.3 { 87 SELECT * FROM t1 ORDER BY a; 88 } {1 1 2 2} 89 catch {db eval ROLLBACK} 90 91 do_execsql_test 1.6.1 { 92 DROP TABLE t1; 93 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT) STRICT; 94 INSERT INTO t1 VALUES(1,1),(2,2); 95 } 96 do_catchsql_test 1.6.2 { 97 UPDATE t1 SET b = coalesce(tryeval('PRAGMA writable_schema=RESET'), b+1); 98 } {1 {database schema has changed}} 99 do_execsql_test 1.6.3 { 100 SELECT * FROM t1 ORDER BY a; 101 } {1 1 2 2} 102 103 do_execsql_test 1.7.1 { 104 DROP TABLE t1; 105 CREATE TABLE t1(a INTEGER PRIMARY KEY, l INT, c INT) STRICT; 106 CREATE TABLE u1(x); 107 INSERT INTO t1 VALUES(1,1,1),(2,2,2); 108 } 109 do_catchsql_test 1.7.2 { 110 UPDATE t1 SET c = coalesce(tryeval('ALTER TABLE u1 ADD COLUMN z'), c+1); 111 } {1 {database schema has changed}} 112 do_execsql_test 1.7.3 { 113 SELECT sql FROM sqlite_master WHERE name='u1'; 114 } {{CREATE TABLE u1(x)}} 115 do_execsql_test 1.7.4 { 116 SELECT * FROM t1 ORDER BY a; 117 } {1 1 1 2 2 2} 118 119 finish_test