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/misc01.sql # 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 / misc01.sql` 422 lines · 12337 bytes Raw Blame History 1 # `7c7dc3813e784515` 2026-11-05T18:09:41Z 2 # OP_SeekRowid converts a key that has both a number and its text from 3 # the text: assertion, and the wrong row with a short fp_d 4 # Alperen Keles 5 # 6 .open :memory: 7 .mode -reset list 8 .testcase 100 9 CREATE TABLE t(a); 10 INSERT INTO t(rowid, a) VALUES 11 (12340,'row 12340'), 12 (12345,'row 12345'), 13 (12350,'row 12350'); 14 .dbconfig fp_digits 4 15 .check 'fp_digits 4' 16 17 .testcase 110 18 SELECT a FROM t WHERE rowid = 12345.0; 19 .check 'row 12345' 20 21 # The sqlar_uncompress() function has the special property 22 # below that the sqlite3_value it returns has both a text 23 # and an equivalent numeric representation at the same time. 24 # 25 .testcase 120 26 SELECT a FROM t WHERE rowid = sqlar_uncompress(12345.0, 9); 27 .check 'row 12345' 28 .testcase 121 29 SELECT a FROM t WHERE rowid = dualrep(12345); 30 .check 'row 12345' 31 .testcase 122 32 SELECT a FROM t WHERE rowid = dualrep(12345.0); 33 .check 'row 12345' 34 35 .testcase 130 36 SELECT a FROM t WHERE +rowid = sqlar_uncompress(12345.0, 9); 37 .check 'row 12345' 38 .testcase 131 39 SELECT a FROM t WHERE +rowid = dualrep(12345); 40 .check 'row 12345' 41 .testcase 132 42 SELECT a FROM t WHERE +rowid = dualrep(12345.0); 43 .check 'row 12345' 44 45 # `45bcbf3580` 2026-11-05T18:08:21Z 46 # A function result that carries a number and its text keeps 47 # the old text after REAL affinity. 48 # 49 .testcase 200 50 .mode quote 51 CREATE TABLE r(x REAL); 52 INSERT INTO r VALUES(dualrep(5)) RETURNING x || ''; 53 .check "'5.0'" 54 55 .testcase 300 56 PRAGMA foreign_keys=ON; 57 CREATE TABLE p(k TEXT UNIQUE); 58 INSERT INTO p VALUES('5.0'); 59 CREATE TABLE c(x REAL REFERENCES p(k)); 60 INSERT INTO c VALUES(5); 61 .check '' 62 .testcase 301 63 INSERT INTO c VALUES(dualrep(5)); 64 .check '' 65 .testcase 302 66 SELECT count(*) FROM c; 67 .check 2 68 69 # `f945de7c4eb73732` 2026-11-06T04:16:54Z 70 # sqlite3's .recover output can smuggle shell commands into the next 71 # sqlite3 run 72 # 73 .if capable('vtab') 74 .testcase 400 75 .open --hexdb 76 | size 8192 pagesize 4096 filename unk.db 77 | page 1 offset 0 78 | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. 79 | 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 02 .....@ ........ 80 | 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ 81 | 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ 82 | 96: 00 00 00 00 0d 00 00 00 01 0f ca 00 0f ca 00 00 ................ 83 | 4032: 00 00 00 00 00 00 00 00 00 00 34 01 06 17 11 11 ..........4..... 84 | 4048: 01 55 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .Utablet1t1.CREA 85 | 4064: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c TE TABLE t1(a,b, 86 | 4080: 63 29 3b 0a 2e 70 72 69 6e 74 20 68 65 6c 6c 6f c);..print hello 87 | page 2 offset 4096 88 | 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ 89 | end unk.db 90 .recover 91 .check <<**END-TEST** 92 .dbconfig defensive off 93 .safe 94 BEGIN; 95 PRAGMA writable_schema = on; 96 PRAGMA foreign_keys = off; 97 PRAGMA encoding = 'UTF-8'; 98 PRAGMA page_size = '4096'; 99 PRAGMA auto_vacuum = '0'; 100 PRAGMA user_version = '0'; 101 PRAGMA application_id = '0'; 102 CREATE TABLE t1(a,b,c); 103 PRAGMA writable_schema = off; 104 COMMIT; 105 **END-TEST** 106 .testcase 401 107 .recover --unsafe 108 .check <<**END-TEST** 109 .dbconfig defensive off 110 BEGIN; 111 PRAGMA writable_schema = on; 112 PRAGMA foreign_keys = off; 113 PRAGMA encoding = 'UTF-8'; 114 PRAGMA page_size = '4096'; 115 PRAGMA auto_vacuum = '0'; 116 PRAGMA user_version = '0'; 117 PRAGMA application_id = '0'; 118 CREATE TABLE t1(a,b,c); 119 PRAGMA writable_schema = off; 120 COMMIT; 121 **END-TEST** 122 .endif /* capable('vtab') */ 123 124 # Follow-up to `f945de7c4eb73732`. The ".recover" command must also omit 125 # extraneous text at the end of the sqlite_schema.sql field for views, 126 # triggers, and non-unique indexes, not just for tables. 127 # 128 .open :memory: 129 CREATE TABLE t1(a,b); 130 CREATE INDEX i1 ON t1(a); 131 CREATE VIEW v1 AS SELECT * FROM t1; 132 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN SELECT 1; END; 133 .dbconfig defensive off 134 .dbconfig writable_schema on 135 UPDATE sqlite_schema 136 SET sql=sql||';'||char(10)||'.print INJECTED_'||name 137 WHERE name IN ('i1','v1','r1'); 138 .testcase 410 139 .recover 140 .check --exact <? AND x? AND x? AND x