drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 1 | # 2002 March 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 | # This file implements regression tests for SQLite library. |
| 12 | # |
| 13 | # This file implements tests for the PRAGMA command. |
| 14 | # |
danielk1977 | 838cce4 | 2009-01-12 14:01:45 +0000 | [diff] [blame] | 15 | # $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $ |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 19 | set testprefix pragma |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 20 | |
dan | 68928b6 | 2010-06-22 13:46:43 +0000 | [diff] [blame] | 21 | # Do not use a codec for tests in this file, as the database file is |
| 22 | # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 23 | # |
| 24 | do_not_use_codec |
| 25 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 26 | # Test organization: |
| 27 | # |
| 28 | # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. |
| 29 | # pragma-2.*: Test synchronous on attached db. |
| 30 | # pragma-3.*: Test detection of table/index inconsistency by integrity_check. |
| 31 | # pragma-4.*: Test cache_size and default_cache_size on attached db. |
| 32 | # pragma-5.*: Test that pragma synchronous may not be used inside of a |
| 33 | # transaction. |
danielk1977 | cc6bd38 | 2005-01-10 02:48:49 +0000 | [diff] [blame] | 34 | # pragma-6.*: Test schema-query pragmas. |
| 35 | # pragma-7.*: Miscellaneous tests. |
| 36 | # pragma-8.*: Test user_version and schema_version pragmas. |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 37 | # pragma-9.*: Test temp_store and temp_store_directory. |
danielk1977 | cc6bd38 | 2005-01-10 02:48:49 +0000 | [diff] [blame] | 38 | # pragma-10.*: Test the count_changes pragma in the presence of triggers. |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 39 | # pragma-11.*: Test the collation_list pragma. |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 40 | # pragma-14.*: Test the page_count pragma. |
danielk1977 | 8cf6c55 | 2008-06-23 16:53:46 +0000 | [diff] [blame] | 41 | # pragma-15.*: Test that the value set using the cache_size pragma is not |
| 42 | # reset when the schema is reloaded. |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 43 | # pragma-16.*: Test proxy locking |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 44 | # pragma-20.*: Test data_store_directory. |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 45 | # pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db" |
| 46 | # directive - if it is present. |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 47 | # |
| 48 | |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 49 | ifcapable !pragma { |
| 50 | finish_test |
| 51 | return |
| 52 | } |
| 53 | |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 54 | # Capture the output of a pragma in a TEMP table. |
| 55 | # |
| 56 | proc capture_pragma {db tabname sql} { |
| 57 | $db eval "DROP TABLE IF EXISTS temp.$tabname" |
| 58 | set once 1 |
| 59 | $db eval $sql x { |
| 60 | if {$once} { |
| 61 | set once 0 |
| 62 | set ins "INSERT INTO $tabname VALUES" |
| 63 | set crtab "CREATE TEMP TABLE $tabname " |
| 64 | set sep "(" |
| 65 | foreach col $x(*) { |
| 66 | append ins ${sep}\$x($col) |
| 67 | append crtab ${sep}\"$col\" |
| 68 | set sep , |
| 69 | } |
| 70 | append ins ) |
| 71 | append crtab ) |
| 72 | $db eval $crtab |
| 73 | } |
| 74 | $db eval $ins |
| 75 | } |
| 76 | } |
| 77 | |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 78 | # Delete the preexisting database to avoid the special setup |
| 79 | # that the "all.test" script does. |
| 80 | # |
| 81 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 82 | delete_file test.db test.db-journal |
| 83 | delete_file test3.db test3.db-journal |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 84 | sqlite3 db test.db; set DB [sqlite3_connection_pointer db] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 85 | |
drh | b3366b9 | 2015-09-11 20:54:44 +0000 | [diff] [blame] | 86 | # EVIDENCE-OF: R-13861-56665 PRAGMA schema.cache_size; PRAGMA |
| 87 | # schema.cache_size = pages; PRAGMA schema.cache_size = -kibibytes; |
drh | 9d356fb | 2015-02-27 20:28:08 +0000 | [diff] [blame] | 88 | # Query or change the suggested maximum number of database disk pages |
| 89 | # that SQLite will hold in memory at once per open database file. |
| 90 | # |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 91 | ifcapable pager_pragmas { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 92 | set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] |
| 93 | set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 94 | do_test pragma-1.1 { |
| 95 | execsql { |
| 96 | PRAGMA cache_size; |
| 97 | PRAGMA default_cache_size; |
| 98 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 99 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 100 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 101 | do_test pragma-1.2 { |
drh | 9d356fb | 2015-02-27 20:28:08 +0000 | [diff] [blame] | 102 | # EVIDENCE-OF: R-42059-47211 If the argument N is positive then the |
| 103 | # suggested cache size is set to N. |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 104 | execsql { |
drh | eb43e5c | 2005-05-22 20:30:39 +0000 | [diff] [blame] | 105 | PRAGMA synchronous=OFF; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 106 | PRAGMA cache_size=1234; |
| 107 | PRAGMA cache_size; |
| 108 | PRAGMA default_cache_size; |
| 109 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 110 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 111 | } [list 1234 $DFLT_CACHE_SZ 0] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 112 | do_test pragma-1.3 { |
| 113 | db close |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 114 | sqlite3 db test.db |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 115 | execsql { |
| 116 | PRAGMA cache_size; |
| 117 | PRAGMA default_cache_size; |
| 118 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 119 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 120 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 121 | do_test pragma-1.4 { |
| 122 | execsql { |
| 123 | PRAGMA synchronous=OFF; |
| 124 | PRAGMA cache_size; |
| 125 | PRAGMA default_cache_size; |
| 126 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 127 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 128 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 129 | do_test pragma-1.5 { |
| 130 | execsql { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 131 | PRAGMA cache_size=-4321; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 132 | PRAGMA cache_size; |
| 133 | PRAGMA default_cache_size; |
| 134 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 135 | } |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 136 | } [list -4321 $DFLT_CACHE_SZ 0] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 137 | do_test pragma-1.6 { |
| 138 | execsql { |
| 139 | PRAGMA synchronous=ON; |
| 140 | PRAGMA cache_size; |
| 141 | PRAGMA default_cache_size; |
| 142 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 143 | } |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 144 | } [list -4321 $DFLT_CACHE_SZ 1] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 145 | do_test pragma-1.7 { |
| 146 | db close |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 147 | sqlite3 db test.db |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 148 | execsql { |
| 149 | PRAGMA cache_size; |
| 150 | PRAGMA default_cache_size; |
| 151 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 152 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 153 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 154 | do_test pragma-1.8 { |
| 155 | execsql { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 156 | PRAGMA default_cache_size=-123; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 157 | PRAGMA cache_size; |
| 158 | PRAGMA default_cache_size; |
| 159 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 160 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 161 | } {123 123 2} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 162 | do_test pragma-1.9.1 { |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 163 | db close |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 164 | sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 165 | execsql { |
| 166 | PRAGMA cache_size; |
| 167 | PRAGMA default_cache_size; |
| 168 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 169 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 170 | } {123 123 2} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 171 | ifcapable vacuum { |
| 172 | do_test pragma-1.9.2 { |
| 173 | execsql { |
| 174 | VACUUM; |
| 175 | PRAGMA cache_size; |
| 176 | PRAGMA default_cache_size; |
| 177 | PRAGMA synchronous; |
| 178 | } |
| 179 | } {123 123 2} |
| 180 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 181 | do_test pragma-1.10 { |
drh | 5a38705 | 2003-01-11 14:19:51 +0000 | [diff] [blame] | 182 | execsql { |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 183 | PRAGMA synchronous=NORMAL; |
| 184 | PRAGMA cache_size; |
| 185 | PRAGMA default_cache_size; |
| 186 | PRAGMA synchronous; |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 187 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 188 | } {123 123 1} |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 189 | do_test pragma-1.11.1 { |
| 190 | execsql { |
| 191 | PRAGMA synchronous=EXTRA; |
| 192 | PRAGMA cache_size; |
| 193 | PRAGMA default_cache_size; |
| 194 | PRAGMA synchronous; |
| 195 | } |
| 196 | } {123 123 3} |
| 197 | do_test pragma-1.11.2 { |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 198 | execsql { |
| 199 | PRAGMA synchronous=FULL; |
| 200 | PRAGMA cache_size; |
| 201 | PRAGMA default_cache_size; |
| 202 | PRAGMA synchronous; |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 203 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 204 | } {123 123 2} |
| 205 | do_test pragma-1.12 { |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 206 | db close |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 207 | sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 208 | execsql { |
| 209 | PRAGMA cache_size; |
| 210 | PRAGMA default_cache_size; |
| 211 | PRAGMA synchronous; |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 212 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 213 | } {123 123 2} |
| 214 | |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 215 | # Make sure the pragma handler understands numeric values in addition |
| 216 | # to keywords like "off" and "full". |
| 217 | # |
| 218 | do_test pragma-1.13 { |
| 219 | execsql { |
| 220 | PRAGMA synchronous=0; |
| 221 | PRAGMA synchronous; |
| 222 | } |
| 223 | } {0} |
| 224 | do_test pragma-1.14 { |
| 225 | execsql { |
| 226 | PRAGMA synchronous=2; |
| 227 | PRAGMA synchronous; |
| 228 | } |
| 229 | } {2} |
drh | 59ac655 | 2015-04-16 16:04:39 +0000 | [diff] [blame] | 230 | do_test pragma-1.14.1 { |
| 231 | execsql { |
| 232 | PRAGMA synchronous=4; |
| 233 | PRAGMA synchronous; |
| 234 | } |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 235 | } {4} |
drh | 59ac655 | 2015-04-16 16:04:39 +0000 | [diff] [blame] | 236 | do_test pragma-1.14.2 { |
| 237 | execsql { |
drh | d99d283 | 2015-04-17 15:58:33 +0000 | [diff] [blame] | 238 | PRAGMA synchronous=3; |
| 239 | PRAGMA synchronous; |
| 240 | } |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 241 | } {3} |
drh | d99d283 | 2015-04-17 15:58:33 +0000 | [diff] [blame] | 242 | do_test pragma-1.14.3 { |
| 243 | execsql { |
drh | 6841b1c | 2016-02-03 19:20:15 +0000 | [diff] [blame] | 244 | PRAGMA synchronous=8; |
| 245 | PRAGMA synchronous; |
| 246 | } |
| 247 | } {0} |
| 248 | do_test pragma-1.14.4 { |
| 249 | execsql { |
drh | 59ac655 | 2015-04-16 16:04:39 +0000 | [diff] [blame] | 250 | PRAGMA synchronous=10; |
| 251 | PRAGMA synchronous; |
| 252 | } |
| 253 | } {2} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 254 | } ;# ifcapable pager_pragmas |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 255 | |
| 256 | # Test turning "flag" pragmas on and off. |
| 257 | # |
danielk1977 | 6338c76 | 2007-05-17 16:38:30 +0000 | [diff] [blame] | 258 | ifcapable debug { |
| 259 | # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG |
| 260 | # |
| 261 | do_test pragma-1.15 { |
| 262 | execsql { |
| 263 | PRAGMA vdbe_listing=YES; |
| 264 | PRAGMA vdbe_listing; |
| 265 | } |
| 266 | } {1} |
| 267 | do_test pragma-1.16 { |
| 268 | execsql { |
| 269 | PRAGMA vdbe_listing=NO; |
| 270 | PRAGMA vdbe_listing; |
| 271 | } |
| 272 | } {0} |
| 273 | } |
| 274 | |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 275 | do_test pragma-1.17 { |
| 276 | execsql { |
| 277 | PRAGMA parser_trace=ON; |
| 278 | PRAGMA parser_trace=OFF; |
| 279 | } |
| 280 | } {} |
| 281 | do_test pragma-1.18 { |
| 282 | execsql { |
| 283 | PRAGMA bogus = -1234; -- Parsing of negative values |
| 284 | } |
| 285 | } {} |
| 286 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 287 | # Test modifying the safety_level of an attached database. |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 288 | ifcapable pager_pragmas&&attach { |
| 289 | do_test pragma-2.1 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 290 | forcedelete test2.db |
| 291 | forcedelete test2.db-journal |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 292 | execsql { |
| 293 | ATTACH 'test2.db' AS aux; |
| 294 | } |
| 295 | } {} |
| 296 | do_test pragma-2.2 { |
| 297 | execsql { |
| 298 | pragma aux.synchronous; |
| 299 | } |
| 300 | } {2} |
| 301 | do_test pragma-2.3 { |
| 302 | execsql { |
| 303 | pragma aux.synchronous = OFF; |
| 304 | pragma aux.synchronous; |
| 305 | pragma synchronous; |
| 306 | } |
| 307 | } {0 2} |
| 308 | do_test pragma-2.4 { |
| 309 | execsql { |
| 310 | pragma aux.synchronous = ON; |
| 311 | pragma synchronous; |
| 312 | pragma aux.synchronous; |
| 313 | } |
| 314 | } {2 1} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 315 | } ;# ifcapable pager_pragmas |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 316 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 317 | # Construct a corrupted index and make sure the integrity_check |
| 318 | # pragma finds it. |
| 319 | # |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 320 | # These tests won't work if the database is encrypted |
| 321 | # |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 322 | do_test pragma-3.1 { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 323 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 324 | forcedelete test.db test.db-journal |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 325 | sqlite3 db test.db |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 326 | execsql { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 327 | PRAGMA auto_vacuum=OFF; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 328 | BEGIN; |
| 329 | CREATE TABLE t2(a,b,c); |
| 330 | CREATE INDEX i2 ON t2(a); |
| 331 | INSERT INTO t2 VALUES(11,2,3); |
| 332 | INSERT INTO t2 VALUES(22,3,4); |
| 333 | COMMIT; |
| 334 | SELECT rowid, * from t2; |
| 335 | } |
| 336 | } {1 11 2 3 2 22 3 4} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 337 | ifcapable attach { |
| 338 | if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { |
| 339 | do_test pragma-3.2 { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 340 | db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break |
| 341 | set pgsz [db eval {PRAGMA page_size}] |
| 342 | # overwrite the header on the rootpage of the index in order to |
| 343 | # make the index appear to be empty. |
| 344 | # |
| 345 | set offset [expr {$pgsz*($rootpage-1)}] |
| 346 | hexio_write test.db $offset 0a00000000040000000000 |
| 347 | db close |
| 348 | sqlite3 db test.db |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 349 | execsql {PRAGMA integrity_check} |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 350 | } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 351 | do_test pragma-3.3 { |
| 352 | execsql {PRAGMA integrity_check=1} |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 353 | } {{row 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 354 | do_test pragma-3.4 { |
| 355 | execsql { |
| 356 | ATTACH DATABASE 'test.db' AS t2; |
| 357 | PRAGMA integrity_check |
| 358 | } |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 359 | } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 360 | do_test pragma-3.5 { |
| 361 | execsql { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 362 | PRAGMA integrity_check=4 |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 363 | } |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 364 | } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 365 | do_test pragma-3.6 { |
| 366 | execsql { |
| 367 | PRAGMA integrity_check=xyz |
| 368 | } |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 369 | } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 370 | do_test pragma-3.7 { |
| 371 | execsql { |
| 372 | PRAGMA integrity_check=0 |
| 373 | } |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 374 | } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 375 | |
| 376 | # Add additional corruption by appending unused pages to the end of |
| 377 | # the database file testerr.db |
| 378 | # |
| 379 | do_test pragma-3.8 { |
| 380 | execsql {DETACH t2} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 381 | forcedelete testerr.db testerr.db-journal |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 382 | set out [open testerr.db w] |
| 383 | fconfigure $out -translation binary |
| 384 | set in [open test.db r] |
| 385 | fconfigure $in -translation binary |
| 386 | puts -nonewline $out [read $in] |
| 387 | seek $in 0 |
| 388 | puts -nonewline $out [read $in] |
| 389 | close $in |
| 390 | close $out |
drh | dd3cd97 | 2010-03-27 17:12:36 +0000 | [diff] [blame] | 391 | hexio_write testerr.db 28 00000000 |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 392 | execsql {REINDEX t2} |
| 393 | execsql {PRAGMA integrity_check} |
| 394 | } {ok} |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 395 | do_test pragma-3.8.1 { |
| 396 | execsql {PRAGMA quick_check} |
| 397 | } {ok} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 398 | do_test pragma-3.8.2 { |
| 399 | execsql {PRAGMA QUICK_CHECK} |
| 400 | } {ok} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 401 | do_test pragma-3.9 { |
| 402 | execsql { |
| 403 | ATTACH 'testerr.db' AS t2; |
| 404 | PRAGMA integrity_check |
| 405 | } |
| 406 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 407 | Page 4 is never used |
| 408 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 409 | Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 410 | do_test pragma-3.10 { |
| 411 | execsql { |
| 412 | PRAGMA integrity_check=1 |
| 413 | } |
| 414 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 415 | Page 4 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 416 | do_test pragma-3.11 { |
| 417 | execsql { |
| 418 | PRAGMA integrity_check=5 |
| 419 | } |
| 420 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 421 | Page 4 is never used |
| 422 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 423 | Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 424 | do_test pragma-3.12 { |
| 425 | execsql { |
| 426 | PRAGMA integrity_check=4 |
| 427 | } |
| 428 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 429 | Page 4 is never used |
| 430 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 431 | Page 6 is never used} {row 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 432 | do_test pragma-3.13 { |
| 433 | execsql { |
| 434 | PRAGMA integrity_check=3 |
| 435 | } |
| 436 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 437 | Page 4 is never used |
| 438 | Page 5 is never used |
| 439 | Page 6 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 440 | do_test pragma-3.14 { |
| 441 | execsql { |
| 442 | PRAGMA integrity_check(2) |
| 443 | } |
| 444 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 445 | Page 4 is never used |
| 446 | Page 5 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 447 | do_test pragma-3.15 { |
| 448 | execsql { |
| 449 | ATTACH 'testerr.db' AS t3; |
| 450 | PRAGMA integrity_check |
| 451 | } |
| 452 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 453 | Page 4 is never used |
| 454 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 455 | Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 456 | Page 4 is never used |
| 457 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 458 | Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 459 | do_test pragma-3.16 { |
| 460 | execsql { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 461 | PRAGMA integrity_check(10) |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 462 | } |
| 463 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 464 | Page 4 is never used |
| 465 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 466 | Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 467 | Page 4 is never used |
| 468 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 469 | Page 6 is never used} {row 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 470 | do_test pragma-3.17 { |
| 471 | execsql { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 472 | PRAGMA integrity_check=8 |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 473 | } |
| 474 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 475 | Page 4 is never used |
| 476 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 477 | Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 478 | Page 4 is never used |
| 479 | Page 5 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 480 | do_test pragma-3.18 { |
| 481 | execsql { |
| 482 | PRAGMA integrity_check=4 |
| 483 | } |
| 484 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 485 | Page 4 is never used |
| 486 | Page 5 is never used |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 487 | Page 6 is never used} {row 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 488 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 489 | do_test pragma-3.19 { |
| 490 | catch {db close} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 491 | forcedelete test.db test.db-journal |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 492 | sqlite3 db test.db |
| 493 | db eval {PRAGMA integrity_check} |
| 494 | } {ok} |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 495 | } |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 496 | |
| 497 | # Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL |
| 498 | # constraint violations. |
| 499 | # |
drh | 6ab91a7 | 2018-11-07 02:17:01 +0000 | [diff] [blame] | 500 | sqlite3_db_config db DEFENSIVE 0 |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 501 | do_execsql_test pragma-3.20 { |
| 502 | CREATE TABLE t1(a,b); |
| 503 | CREATE INDEX t1a ON t1(a); |
| 504 | INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6); |
| 505 | PRAGMA writable_schema=ON; |
| 506 | UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)' |
| 507 | WHERE name='t1a'; |
| 508 | UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)' |
| 509 | WHERE name='t1'; |
| 510 | PRAGMA writable_schema=OFF; |
| 511 | ALTER TABLE t1 RENAME TO t1x; |
| 512 | PRAGMA integrity_check; |
| 513 | } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}} |
| 514 | do_execsql_test pragma-3.21 { |
| 515 | PRAGMA integrity_check(3); |
| 516 | } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}} |
| 517 | do_execsql_test pragma-3.22 { |
| 518 | PRAGMA integrity_check(2); |
| 519 | } {{non-unique entry in index t1a} {NULL value in t1x.a}} |
drh | 7efa426 | 2014-12-16 00:08:31 +0000 | [diff] [blame] | 520 | do_execsql_test pragma-3.23 { |
drh | cefc87f | 2014-08-01 01:40:33 +0000 | [diff] [blame] | 521 | PRAGMA integrity_check(1); |
| 522 | } {{non-unique entry in index t1a}} |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 523 | |
drh | 7efa426 | 2014-12-16 00:08:31 +0000 | [diff] [blame] | 524 | # PRAGMA integrity check (or more specifically the sqlite3BtreeCount() |
| 525 | # interface) used to leave index cursors in an inconsistent state |
| 526 | # which could result in an assertion fault in sqlite3BtreeKey() |
| 527 | # called from saveCursorPosition() if content is removed from the |
| 528 | # index while the integrity_check is still running. This test verifies |
| 529 | # that problem has been fixed. |
| 530 | # |
| 531 | do_test pragma-3.30 { |
| 532 | db close |
| 533 | delete_file test.db |
| 534 | sqlite3 db test.db |
| 535 | db eval { |
| 536 | CREATE TABLE t1(a,b,c); |
| 537 | WITH RECURSIVE |
| 538 | c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) |
| 539 | INSERT INTO t1(a,b,c) SELECT i, printf('xyz%08x',i), 2000-i FROM c; |
| 540 | CREATE INDEX t1a ON t1(a); |
| 541 | CREATE INDEX t1bc ON t1(b,c); |
| 542 | } |
| 543 | db eval {PRAGMA integrity_check} { |
| 544 | db eval {DELETE FROM t1} |
| 545 | } |
| 546 | } {} |
| 547 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 548 | # Test modifying the cache_size of an attached database. |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 549 | ifcapable pager_pragmas&&attach { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 550 | do_test pragma-4.1 { |
| 551 | execsql { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 552 | ATTACH 'test2.db' AS aux; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 553 | pragma aux.cache_size; |
| 554 | pragma aux.default_cache_size; |
| 555 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 556 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 557 | do_test pragma-4.2 { |
| 558 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 559 | pragma aux.cache_size = 50; |
| 560 | pragma aux.cache_size; |
| 561 | pragma aux.default_cache_size; |
| 562 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 563 | } [list 50 $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 564 | do_test pragma-4.3 { |
| 565 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 566 | pragma aux.default_cache_size = 456; |
| 567 | pragma aux.cache_size; |
| 568 | pragma aux.default_cache_size; |
| 569 | } |
| 570 | } {456 456} |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 571 | do_test pragma-4.4 { |
| 572 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 573 | pragma cache_size; |
| 574 | pragma default_cache_size; |
| 575 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 576 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 577 | do_test pragma-4.5 { |
| 578 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 579 | DETACH aux; |
| 580 | ATTACH 'test3.db' AS aux; |
| 581 | pragma aux.cache_size; |
| 582 | pragma aux.default_cache_size; |
| 583 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 584 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 585 | do_test pragma-4.6 { |
| 586 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 587 | DETACH aux; |
| 588 | ATTACH 'test2.db' AS aux; |
| 589 | pragma aux.cache_size; |
| 590 | pragma aux.default_cache_size; |
| 591 | } |
| 592 | } {456 456} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 593 | } ;# ifcapable pager_pragmas |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 594 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 595 | # Test that modifying the sync-level in the middle of a transaction is |
| 596 | # disallowed. |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 597 | ifcapable pager_pragmas { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 598 | do_test pragma-5.0 { |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 599 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 600 | pragma synchronous; |
| 601 | } |
| 602 | } {2} |
| 603 | do_test pragma-5.1 { |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 604 | catchsql { |
| 605 | BEGIN; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 606 | pragma synchronous = OFF; |
| 607 | } |
| 608 | } {1 {Safety level may not be changed inside a transaction}} |
| 609 | do_test pragma-5.2 { |
| 610 | execsql { |
| 611 | pragma synchronous; |
| 612 | } |
| 613 | } {2} |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 614 | catchsql {COMMIT;} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 615 | } ;# ifcapable pager_pragmas |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 616 | |
| 617 | # Test schema-query pragmas |
| 618 | # |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 619 | ifcapable schema_pragmas { |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 620 | ifcapable tempdb&&attach { |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 621 | do_test pragma-6.1 { |
| 622 | set res {} |
| 623 | execsql {SELECT * FROM sqlite_temp_master} |
| 624 | foreach {idx name file} [execsql {pragma database_list}] { |
| 625 | lappend res $idx $name |
| 626 | } |
| 627 | set res |
| 628 | } {0 main 1 temp 2 aux} |
| 629 | } |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 630 | do_test pragma-6.2 { |
| 631 | execsql { |
drh | a6dddd9 | 2016-04-18 15:46:14 +0000 | [diff] [blame] | 632 | CREATE TABLE t2(a TYPE_X, b [TYPE_Y], c "TYPE_Z"); |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 633 | pragma table_info(t2) |
| 634 | } |
drh | a6dddd9 | 2016-04-18 15:46:14 +0000 | [diff] [blame] | 635 | } {0 a TYPE_X 0 {} 0 1 b TYPE_Y 0 {} 0 2 c TYPE_Z 0 {} 0} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 636 | do_test pragma-6.2.1 { |
| 637 | execsql { |
| 638 | pragma table_info; |
| 639 | } |
| 640 | } {} |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 641 | db nullvalue <<NULL>> |
drh | 417ec63 | 2006-08-14 14:23:41 +0000 | [diff] [blame] | 642 | do_test pragma-6.2.2 { |
| 643 | execsql { |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 644 | CREATE TABLE t5( |
| 645 | a TEXT DEFAULT CURRENT_TIMESTAMP, |
| 646 | b DEFAULT (5+3), |
| 647 | c TEXT, |
| 648 | d INTEGER DEFAULT NULL, |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 649 | e TEXT DEFAULT '', |
| 650 | UNIQUE(b,c,d), |
| 651 | PRIMARY KEY(e,b,c) |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 652 | ); |
drh | 417ec63 | 2006-08-14 14:23:41 +0000 | [diff] [blame] | 653 | PRAGMA table_info(t5); |
| 654 | } |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 655 | } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1} |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 656 | db nullvalue {} |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 657 | do_test pragma-6.2.3 { |
| 658 | execsql { |
| 659 | CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c); |
| 660 | pragma table_info(t2_3) |
| 661 | } |
| 662 | } {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0} |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 663 | ifcapable {foreignkey} { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 664 | do_test pragma-6.3.1 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 665 | execsql { |
| 666 | CREATE TABLE t3(a int references t2(b), b UNIQUE); |
| 667 | pragma foreign_key_list(t3); |
| 668 | } |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 669 | } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 670 | do_test pragma-6.3.2 { |
| 671 | execsql { |
| 672 | pragma foreign_key_list; |
| 673 | } |
| 674 | } {} |
| 675 | do_test pragma-6.3.3 { |
| 676 | execsql { |
| 677 | pragma foreign_key_list(t3_bogus); |
| 678 | } |
| 679 | } {} |
| 680 | do_test pragma-6.3.4 { |
| 681 | execsql { |
| 682 | pragma foreign_key_list(t5); |
| 683 | } |
| 684 | } {} |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 685 | do_test pragma-6.4 { |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 686 | capture_pragma db out { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 687 | pragma index_list(t3); |
| 688 | } |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 689 | db eval {SELECT seq, "name", "unique" FROM out ORDER BY seq} |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 690 | } {0 sqlite_autoindex_t3_1 1} |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 691 | } |
| 692 | ifcapable {!foreignkey} { |
| 693 | execsql {CREATE TABLE t3(a,b UNIQUE)} |
| 694 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 695 | do_test pragma-6.5.1 { |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 696 | execsql { |
| 697 | CREATE INDEX t3i1 ON t3(a,b); |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 698 | } |
| 699 | capture_pragma db out { |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 700 | pragma index_info(t3i1); |
| 701 | } |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 702 | db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 703 | } {0 0 a 1 1 b} |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 704 | |
| 705 | # EVIDENCE-OF: R-23114-21695 The auxiliary index-columns are not shown |
| 706 | # by the index_info pragma, but they are listed by the index_xinfo |
| 707 | # pragma. |
| 708 | # |
| 709 | do_test pragma-6.5.1b { |
| 710 | capture_pragma db out {PRAGMA index_xinfo(t3i1)} |
| 711 | db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} |
| 712 | } {0 0 a 1 1 b 2 -1 {}} |
| 713 | |
| 714 | |
drh | b3366b9 | 2015-09-11 20:54:44 +0000 | [diff] [blame] | 715 | # EVIDENCE-OF: R-29448-60346 PRAGMA schema.index_info(index-name); This |
| 716 | # pragma returns one row for each key column in the named index. |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 717 | # |
| 718 | # (The first column of output from PRAGMA index_info is...) |
| 719 | # EVIDENCE-OF: R-34186-52914 The rank of the column within the index. (0 |
| 720 | # means left-most.) |
| 721 | # |
| 722 | # (The second column of output from PRAGMA index_info is...) |
| 723 | # EVIDENCE-OF: R-65019-08383 The rank of the column within the table |
| 724 | # being indexed. |
| 725 | # |
| 726 | # (The third column of output from PRAGMA index_info is...) |
| 727 | # EVIDENCE-OF: R-09773-34266 The name of the column being indexed. |
| 728 | # |
| 729 | do_execsql_test pragma-6.5.1c { |
| 730 | CREATE INDEX t3i2 ON t3(b,a); |
| 731 | PRAGMA index_info='t3i2'; |
| 732 | DROP INDEX t3i2; |
| 733 | } {0 1 b 1 0 a} |
| 734 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 735 | do_test pragma-6.5.2 { |
| 736 | execsql { |
| 737 | pragma index_info(t3i1_bogus); |
| 738 | } |
| 739 | } {} |
danielk1977 | 260d8a6 | 2008-08-20 16:34:24 +0000 | [diff] [blame] | 740 | |
| 741 | ifcapable tempdb { |
| 742 | # Test for ticket #3320. When a temp table of the same name exists, make |
| 743 | # sure the schema of the main table can still be queried using |
| 744 | # "pragma table_info": |
| 745 | do_test pragma-6.6.1 { |
| 746 | execsql { |
| 747 | CREATE TABLE trial(col_main); |
| 748 | CREATE TEMP TABLE trial(col_temp); |
| 749 | } |
| 750 | } {} |
| 751 | do_test pragma-6.6.2 { |
| 752 | execsql { |
| 753 | PRAGMA table_info(trial); |
| 754 | } |
| 755 | } {0 col_temp {} 0 {} 0} |
| 756 | do_test pragma-6.6.3 { |
| 757 | execsql { |
| 758 | PRAGMA temp.table_info(trial); |
| 759 | } |
| 760 | } {0 col_temp {} 0 {} 0} |
| 761 | do_test pragma-6.6.4 { |
| 762 | execsql { |
| 763 | PRAGMA main.table_info(trial); |
| 764 | } |
| 765 | } {0 col_main {} 0 {} 0} |
| 766 | } |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 767 | |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 768 | do_test pragma-6.7 { |
| 769 | execsql { |
| 770 | CREATE TABLE test_table( |
| 771 | one INT NOT NULL DEFAULT -1, |
| 772 | two text, |
| 773 | three VARCHAR(45, 65) DEFAULT 'abcde', |
| 774 | four REAL DEFAULT X'abcdef', |
| 775 | five DEFAULT CURRENT_TIME |
| 776 | ); |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 777 | } |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 778 | capture_pragma db out {PRAGMA table_info(test_table)} |
| 779 | db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out |
| 780 | ORDER BY cid} |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 781 | } [concat \ |
| 782 | {0 one INT 1 -1 0} \ |
| 783 | {1 two text 0 {} 0} \ |
| 784 | {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ |
| 785 | {3 four REAL 0 X'abcdef' 0} \ |
| 786 | {4 five {} 0 CURRENT_TIME 0} \ |
| 787 | ] |
drh | 1b67896 | 2015-04-15 07:19:27 +0000 | [diff] [blame] | 788 | do_test pragma-6.8 { |
| 789 | execsql { |
| 790 | CREATE TABLE t68(a,b,c,PRIMARY KEY(a,b,a,c)); |
| 791 | PRAGMA table_info(t68); |
| 792 | } |
| 793 | } [concat \ |
| 794 | {0 a {} 0 {} 1} \ |
| 795 | {1 b {} 0 {} 2} \ |
| 796 | {2 c {} 0 {} 4} \ |
| 797 | ] |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 798 | } ;# ifcapable schema_pragmas |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 799 | # Miscellaneous tests |
| 800 | # |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 801 | ifcapable schema_pragmas { |
drh | b3366b9 | 2015-09-11 20:54:44 +0000 | [diff] [blame] | 802 | # EVIDENCE-OF: R-64103-17776 PRAGMA schema.index_list(table-name); This |
| 803 | # pragma returns one row for each index associated with the given table. |
| 804 | # |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 805 | do_test pragma-7.1.1 { |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 806 | # Make sure a pragma knows to read the schema if it needs to |
| 807 | db close |
| 808 | sqlite3 db test.db |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 809 | capture_pragma db out "PRAGMA index_list(t3)" |
| 810 | db eval {SELECT name, "origin" FROM out ORDER BY name DESC} |
| 811 | } {t3i1 c sqlite_autoindex_t3_1 u} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 812 | do_test pragma-7.1.2 { |
| 813 | execsql { |
| 814 | pragma index_list(t3_bogus); |
| 815 | } |
| 816 | } {} |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 817 | } ;# ifcapable schema_pragmas |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 818 | ifcapable {utf16} { |
dan | cb35460 | 2010-07-08 09:44:42 +0000 | [diff] [blame] | 819 | if {[permutation] == ""} { |
| 820 | do_test pragma-7.2 { |
| 821 | db close |
| 822 | sqlite3 db test.db |
| 823 | catchsql { |
| 824 | pragma encoding=bogus; |
| 825 | } |
| 826 | } {1 {unsupported encoding: bogus}} |
| 827 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 828 | } |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 829 | ifcapable tempdb { |
| 830 | do_test pragma-7.3 { |
| 831 | db close |
| 832 | sqlite3 db test.db |
| 833 | execsql { |
| 834 | pragma lock_status; |
| 835 | } |
| 836 | } {main unlocked temp closed} |
| 837 | } else { |
| 838 | do_test pragma-7.3 { |
| 839 | db close |
| 840 | sqlite3 db test.db |
| 841 | execsql { |
| 842 | pragma lock_status; |
| 843 | } |
| 844 | } {main unlocked} |
| 845 | } |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 846 | |
| 847 | |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 848 | #---------------------------------------------------------------------- |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 849 | # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA |
| 850 | # user_version" statements. |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 851 | # |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 852 | # pragma-8.1: PRAGMA schema_version |
| 853 | # pragma-8.2: PRAGMA user_version |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 854 | # |
| 855 | |
danielk1977 | 11cf9fb | 2004-11-23 11:16:42 +0000 | [diff] [blame] | 856 | ifcapable schema_version { |
| 857 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 858 | # First check that we can set the schema version and then retrieve the |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 859 | # same value. |
| 860 | do_test pragma-8.1.1 { |
| 861 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 862 | PRAGMA schema_version = 105; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 863 | } |
| 864 | } {} |
| 865 | do_test pragma-8.1.2 { |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 866 | execsql2 { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 867 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 868 | } |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 869 | } {schema_version 105} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 870 | do_test pragma-8.1.3 { |
| 871 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 872 | PRAGMA schema_version = 106; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 873 | } |
| 874 | } {} |
| 875 | do_test pragma-8.1.4 { |
| 876 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 877 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 878 | } |
| 879 | } 106 |
| 880 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 881 | # Check that creating a table modifies the schema-version (this is really |
| 882 | # to verify that the value being read is in fact the schema version). |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 883 | do_test pragma-8.1.5 { |
| 884 | execsql { |
| 885 | CREATE TABLE t4(a, b, c); |
| 886 | INSERT INTO t4 VALUES(1, 2, 3); |
| 887 | SELECT * FROM t4; |
| 888 | } |
| 889 | } {1 2 3} |
| 890 | do_test pragma-8.1.6 { |
| 891 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 892 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 893 | } |
| 894 | } 107 |
| 895 | |
| 896 | # Now open a second connection to the database. Ensure that changing the |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 897 | # schema-version using the first connection forces the second connection |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 898 | # to reload the schema. This has to be done using the C-API test functions, |
| 899 | # because the TCL API accounts for SCHEMA_ERROR and retries the query. |
| 900 | do_test pragma-8.1.7 { |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 901 | sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 902 | execsql { |
| 903 | SELECT * FROM t4; |
| 904 | } db2 |
| 905 | } {1 2 3} |
| 906 | do_test pragma-8.1.8 { |
| 907 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 908 | PRAGMA schema_version = 108; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 909 | } |
| 910 | } {} |
| 911 | do_test pragma-8.1.9 { |
| 912 | set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] |
| 913 | sqlite3_step $::STMT |
| 914 | } SQLITE_ERROR |
| 915 | do_test pragma-8.1.10 { |
| 916 | sqlite3_finalize $::STMT |
| 917 | } SQLITE_SCHEMA |
| 918 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 919 | # Make sure the schema-version can be manipulated in an attached database. |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 920 | forcedelete test2.db |
| 921 | forcedelete test2.db-journal |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 922 | ifcapable attach { |
| 923 | do_test pragma-8.1.11 { |
| 924 | execsql { |
| 925 | ATTACH 'test2.db' AS aux; |
| 926 | CREATE TABLE aux.t1(a, b, c); |
| 927 | PRAGMA aux.schema_version = 205; |
| 928 | } |
| 929 | } {} |
| 930 | do_test pragma-8.1.12 { |
| 931 | execsql { |
| 932 | PRAGMA aux.schema_version; |
| 933 | } |
| 934 | } 205 |
| 935 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 936 | do_test pragma-8.1.13 { |
| 937 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 938 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 939 | } |
| 940 | } 108 |
| 941 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 942 | # And check that modifying the schema-version in an attached database |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 943 | # forces the second connection to reload the schema. |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 944 | ifcapable attach { |
| 945 | do_test pragma-8.1.14 { |
| 946 | sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] |
| 947 | execsql { |
| 948 | ATTACH 'test2.db' AS aux; |
| 949 | SELECT * FROM aux.t1; |
| 950 | } db2 |
| 951 | } {} |
| 952 | do_test pragma-8.1.15 { |
| 953 | execsql { |
| 954 | PRAGMA aux.schema_version = 206; |
| 955 | } |
| 956 | } {} |
| 957 | do_test pragma-8.1.16 { |
| 958 | set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] |
| 959 | sqlite3_step $::STMT |
| 960 | } SQLITE_ERROR |
| 961 | do_test pragma-8.1.17 { |
| 962 | sqlite3_finalize $::STMT |
| 963 | } SQLITE_SCHEMA |
| 964 | do_test pragma-8.1.18 { |
| 965 | db2 close |
| 966 | } {} |
| 967 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 968 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 969 | # Now test that the user-version can be read and written (and that we aren't |
| 970 | # accidentally manipulating the schema-version instead). |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 971 | do_test pragma-8.2.1 { |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 972 | execsql2 { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 973 | PRAGMA user_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 974 | } |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 975 | } {user_version 0} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 976 | do_test pragma-8.2.2 { |
| 977 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 978 | PRAGMA user_version = 2; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 979 | } |
| 980 | } {} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 981 | do_test pragma-8.2.3.1 { |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 982 | execsql2 { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 983 | PRAGMA user_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 984 | } |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 985 | } {user_version 2} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 986 | do_test pragma-8.2.3.2 { |
| 987 | db close |
| 988 | sqlite3 db test.db |
| 989 | execsql { |
| 990 | PRAGMA user_version; |
| 991 | } |
| 992 | } {2} |
| 993 | do_test pragma-8.2.4.1 { |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 994 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 995 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 996 | } |
| 997 | } {108} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 998 | ifcapable vacuum { |
| 999 | do_test pragma-8.2.4.2 { |
| 1000 | execsql { |
| 1001 | VACUUM; |
| 1002 | PRAGMA user_version; |
| 1003 | } |
| 1004 | } {2} |
| 1005 | do_test pragma-8.2.4.3 { |
| 1006 | execsql { |
| 1007 | PRAGMA schema_version; |
| 1008 | } |
| 1009 | } {109} |
| 1010 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1011 | |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 1012 | ifcapable attach { |
| 1013 | db eval {ATTACH 'test2.db' AS aux} |
| 1014 | |
| 1015 | # Check that the user-version in the auxilary database can be manipulated ( |
| 1016 | # and that we aren't accidentally manipulating the same in the main db). |
| 1017 | do_test pragma-8.2.5 { |
| 1018 | execsql { |
| 1019 | PRAGMA aux.user_version; |
| 1020 | } |
| 1021 | } {0} |
| 1022 | do_test pragma-8.2.6 { |
| 1023 | execsql { |
| 1024 | PRAGMA aux.user_version = 3; |
| 1025 | } |
| 1026 | } {} |
| 1027 | do_test pragma-8.2.7 { |
| 1028 | execsql { |
| 1029 | PRAGMA aux.user_version; |
| 1030 | } |
| 1031 | } {3} |
| 1032 | do_test pragma-8.2.8 { |
| 1033 | execsql { |
| 1034 | PRAGMA main.user_version; |
| 1035 | } |
| 1036 | } {2} |
| 1037 | |
| 1038 | # Now check that a ROLLBACK resets the user-version if it has been modified |
| 1039 | # within a transaction. |
| 1040 | do_test pragma-8.2.9 { |
| 1041 | execsql { |
| 1042 | BEGIN; |
| 1043 | PRAGMA aux.user_version = 10; |
| 1044 | PRAGMA user_version = 11; |
| 1045 | } |
| 1046 | } {} |
| 1047 | do_test pragma-8.2.10 { |
| 1048 | execsql { |
| 1049 | PRAGMA aux.user_version; |
| 1050 | } |
| 1051 | } {10} |
| 1052 | do_test pragma-8.2.11 { |
| 1053 | execsql { |
| 1054 | PRAGMA main.user_version; |
| 1055 | } |
| 1056 | } {11} |
| 1057 | do_test pragma-8.2.12 { |
| 1058 | execsql { |
| 1059 | ROLLBACK; |
| 1060 | PRAGMA aux.user_version; |
| 1061 | } |
| 1062 | } {3} |
| 1063 | do_test pragma-8.2.13 { |
| 1064 | execsql { |
| 1065 | PRAGMA main.user_version; |
| 1066 | } |
| 1067 | } {2} |
| 1068 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1069 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1070 | # Try a negative value for the user-version |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1071 | do_test pragma-8.2.14 { |
| 1072 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1073 | PRAGMA user_version = -450; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1074 | } |
| 1075 | } {} |
| 1076 | do_test pragma-8.2.15 { |
| 1077 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 1078 | PRAGMA user_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 1079 | } |
| 1080 | } {-450} |
danielk1977 | d9c847d | 2005-01-07 10:42:48 +0000 | [diff] [blame] | 1081 | } ; # ifcapable schema_version |
| 1082 | |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1083 | # Check to see if TEMP_STORE is memory or disk. Return strings |
| 1084 | # "memory" or "disk" as appropriate. |
| 1085 | # |
| 1086 | proc check_temp_store {} { |
dan | 9131ab9 | 2016-04-06 18:20:51 +0000 | [diff] [blame] | 1087 | db eval { |
| 1088 | PRAGMA temp.cache_size = 1; |
| 1089 | CREATE TEMP TABLE IF NOT EXISTS a(b); |
| 1090 | DELETE FROM a; |
| 1091 | INSERT INTO a VALUES(randomblob(1000)); |
| 1092 | INSERT INTO a SELECT * FROM a; |
| 1093 | INSERT INTO a SELECT * FROM a; |
| 1094 | INSERT INTO a SELECT * FROM a; |
| 1095 | INSERT INTO a SELECT * FROM a; |
| 1096 | INSERT INTO a SELECT * FROM a; |
| 1097 | INSERT INTO a SELECT * FROM a; |
| 1098 | INSERT INTO a SELECT * FROM a; |
| 1099 | INSERT INTO a SELECT * FROM a; |
| 1100 | } |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1101 | db eval {PRAGMA database_list} { |
| 1102 | if {$name=="temp"} { |
danielk1977 | 17b90b5 | 2008-06-06 11:11:25 +0000 | [diff] [blame] | 1103 | set bt [btree_from_db db 1] |
| 1104 | if {[btree_ismemdb $bt]} { |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1105 | return "memory" |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1106 | } |
danielk1977 | 17b90b5 | 2008-06-06 11:11:25 +0000 | [diff] [blame] | 1107 | return "disk" |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | return "unknown" |
| 1111 | } |
| 1112 | |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 1113 | # Application_ID |
| 1114 | # |
| 1115 | do_test pragma-8.3.1 { |
| 1116 | execsql { |
| 1117 | PRAGMA application_id; |
| 1118 | } |
| 1119 | } {0} |
| 1120 | do_test pragma-8.3.2 { |
| 1121 | execsql {PRAGMA Application_ID(12345); PRAGMA application_id;} |
| 1122 | } {12345} |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1123 | |
| 1124 | # Test temp_store and temp_store_directory pragmas |
| 1125 | # |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1126 | ifcapable pager_pragmas { |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1127 | do_test pragma-9.1 { |
| 1128 | db close |
| 1129 | sqlite3 db test.db |
| 1130 | execsql { |
| 1131 | PRAGMA temp_store; |
| 1132 | } |
| 1133 | } {0} |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1134 | if {$TEMP_STORE<=1} { |
| 1135 | do_test pragma-9.1.1 { |
| 1136 | check_temp_store |
| 1137 | } {disk} |
| 1138 | } else { |
| 1139 | do_test pragma-9.1.1 { |
| 1140 | check_temp_store |
| 1141 | } {memory} |
| 1142 | } |
| 1143 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1144 | do_test pragma-9.2 { |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1145 | db close |
| 1146 | sqlite3 db test.db |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1147 | execsql { |
| 1148 | PRAGMA temp_store=file; |
| 1149 | PRAGMA temp_store; |
| 1150 | } |
| 1151 | } {1} |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1152 | if {$TEMP_STORE==3} { |
| 1153 | # When TEMP_STORE is 3, always use memory regardless of pragma settings. |
| 1154 | do_test pragma-9.2.1 { |
| 1155 | check_temp_store |
| 1156 | } {memory} |
| 1157 | } else { |
| 1158 | do_test pragma-9.2.1 { |
| 1159 | check_temp_store |
| 1160 | } {disk} |
| 1161 | } |
| 1162 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1163 | do_test pragma-9.3 { |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1164 | db close |
| 1165 | sqlite3 db test.db |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1166 | execsql { |
| 1167 | PRAGMA temp_store=memory; |
| 1168 | PRAGMA temp_store; |
| 1169 | } |
| 1170 | } {2} |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 1171 | if {$TEMP_STORE==0} { |
| 1172 | # When TEMP_STORE is 0, always use the disk regardless of pragma settings. |
| 1173 | do_test pragma-9.3.1 { |
| 1174 | check_temp_store |
| 1175 | } {disk} |
| 1176 | } else { |
| 1177 | do_test pragma-9.3.1 { |
| 1178 | check_temp_store |
| 1179 | } {memory} |
| 1180 | } |
| 1181 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1182 | do_test pragma-9.4 { |
| 1183 | execsql { |
| 1184 | PRAGMA temp_store_directory; |
| 1185 | } |
| 1186 | } {} |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1187 | ifcapable wsd { |
| 1188 | do_test pragma-9.5 { |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 1189 | set pwd [string map {' ''} [file nativename [get_pwd]]] |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1190 | execsql " |
| 1191 | PRAGMA temp_store_directory='$pwd'; |
| 1192 | " |
| 1193 | } {} |
| 1194 | do_test pragma-9.6 { |
| 1195 | execsql { |
| 1196 | PRAGMA temp_store_directory; |
| 1197 | } |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 1198 | } [list [file nativename [get_pwd]]] |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1199 | do_test pragma-9.7 { |
| 1200 | catchsql { |
| 1201 | PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; |
| 1202 | } |
| 1203 | } {1 {not a writable directory}} |
| 1204 | do_test pragma-9.8 { |
| 1205 | execsql { |
| 1206 | PRAGMA temp_store_directory=''; |
| 1207 | } |
| 1208 | } {} |
| 1209 | if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { |
| 1210 | ifcapable tempdb { |
| 1211 | do_test pragma-9.9 { |
| 1212 | execsql { |
| 1213 | PRAGMA temp_store_directory; |
| 1214 | PRAGMA temp_store=FILE; |
| 1215 | CREATE TEMP TABLE temp_store_directory_test(a integer); |
| 1216 | INSERT INTO temp_store_directory_test values (2); |
| 1217 | SELECT * FROM temp_store_directory_test; |
| 1218 | } |
| 1219 | } {2} |
| 1220 | do_test pragma-9.10 { |
| 1221 | catchsql " |
| 1222 | PRAGMA temp_store_directory='$pwd'; |
| 1223 | SELECT * FROM temp_store_directory_test; |
| 1224 | " |
| 1225 | } {1 {no such table: temp_store_directory_test}} |
| 1226 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1227 | } |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1228 | } |
danielk1977 | 95b289b | 2007-03-30 17:11:12 +0000 | [diff] [blame] | 1229 | do_test pragma-9.11 { |
| 1230 | execsql { |
| 1231 | PRAGMA temp_store = 0; |
| 1232 | PRAGMA temp_store; |
| 1233 | } |
| 1234 | } {0} |
| 1235 | do_test pragma-9.12 { |
| 1236 | execsql { |
| 1237 | PRAGMA temp_store = 1; |
| 1238 | PRAGMA temp_store; |
| 1239 | } |
| 1240 | } {1} |
| 1241 | do_test pragma-9.13 { |
| 1242 | execsql { |
| 1243 | PRAGMA temp_store = 2; |
| 1244 | PRAGMA temp_store; |
| 1245 | } |
| 1246 | } {2} |
| 1247 | do_test pragma-9.14 { |
| 1248 | execsql { |
| 1249 | PRAGMA temp_store = 3; |
| 1250 | PRAGMA temp_store; |
| 1251 | } |
| 1252 | } {0} |
danielk1977 | 95b289b | 2007-03-30 17:11:12 +0000 | [diff] [blame] | 1253 | do_test pragma-9.15 { |
| 1254 | catchsql { |
| 1255 | BEGIN EXCLUSIVE; |
| 1256 | CREATE TEMP TABLE temp_table(t); |
| 1257 | INSERT INTO temp_table VALUES('valuable data'); |
| 1258 | PRAGMA temp_store = 1; |
| 1259 | } |
| 1260 | } {1 {temporary storage cannot be changed from within a transaction}} |
| 1261 | do_test pragma-9.16 { |
| 1262 | execsql { |
| 1263 | SELECT * FROM temp_table; |
| 1264 | COMMIT; |
| 1265 | } |
| 1266 | } {{valuable data}} |
danielk1977 | 983e230 | 2008-07-08 07:35:51 +0000 | [diff] [blame] | 1267 | |
| 1268 | do_test pragma-9.17 { |
| 1269 | execsql { |
| 1270 | INSERT INTO temp_table VALUES('valuable data II'); |
| 1271 | SELECT * FROM temp_table; |
| 1272 | } |
| 1273 | } {{valuable data} {valuable data II}} |
| 1274 | |
| 1275 | do_test pragma-9.18 { |
| 1276 | set rc [catch { |
| 1277 | db eval {SELECT t FROM temp_table} { |
| 1278 | execsql {pragma temp_store = 1} |
| 1279 | } |
| 1280 | } msg] |
| 1281 | list $rc $msg |
| 1282 | } {1 {temporary storage cannot be changed from within a transaction}} |
| 1283 | |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1284 | } ;# ifcapable pager_pragmas |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1285 | |
danielk1977 | cc6bd38 | 2005-01-10 02:48:49 +0000 | [diff] [blame] | 1286 | ifcapable trigger { |
| 1287 | |
| 1288 | do_test pragma-10.0 { |
| 1289 | catchsql { |
| 1290 | DROP TABLE main.t1; |
| 1291 | } |
| 1292 | execsql { |
| 1293 | PRAGMA count_changes = 1; |
| 1294 | |
| 1295 | CREATE TABLE t1(a PRIMARY KEY); |
| 1296 | CREATE TABLE t1_mirror(a); |
| 1297 | CREATE TABLE t1_mirror2(a); |
| 1298 | CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN |
| 1299 | INSERT INTO t1_mirror VALUES(new.a); |
| 1300 | END; |
| 1301 | CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN |
| 1302 | INSERT INTO t1_mirror2 VALUES(new.a); |
| 1303 | END; |
| 1304 | CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN |
| 1305 | UPDATE t1_mirror SET a = new.a WHERE a = old.a; |
| 1306 | END; |
| 1307 | CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN |
| 1308 | UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; |
| 1309 | END; |
| 1310 | CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN |
| 1311 | DELETE FROM t1_mirror WHERE a = old.a; |
| 1312 | END; |
| 1313 | CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN |
| 1314 | DELETE FROM t1_mirror2 WHERE a = old.a; |
| 1315 | END; |
| 1316 | } |
| 1317 | } {} |
| 1318 | |
| 1319 | do_test pragma-10.1 { |
| 1320 | execsql { |
| 1321 | INSERT INTO t1 VALUES(randstr(10,10)); |
| 1322 | } |
| 1323 | } {1} |
| 1324 | do_test pragma-10.2 { |
| 1325 | execsql { |
| 1326 | UPDATE t1 SET a = randstr(10,10); |
| 1327 | } |
| 1328 | } {1} |
| 1329 | do_test pragma-10.3 { |
| 1330 | execsql { |
| 1331 | DELETE FROM t1; |
| 1332 | } |
| 1333 | } {1} |
| 1334 | |
| 1335 | } ;# ifcapable trigger |
| 1336 | |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1337 | ifcapable schema_pragmas { |
| 1338 | do_test pragma-11.1 { |
| 1339 | execsql2 { |
| 1340 | pragma collation_list; |
| 1341 | } |
drh | 2d82331 | 2014-11-20 23:11:30 +0000 | [diff] [blame] | 1342 | } {seq 0 name RTRIM seq 1 name NOCASE seq 2 name BINARY} |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1343 | do_test pragma-11.2 { |
| 1344 | db collate New_Collation blah... |
| 1345 | execsql { |
| 1346 | pragma collation_list; |
| 1347 | } |
drh | 2d82331 | 2014-11-20 23:11:30 +0000 | [diff] [blame] | 1348 | } {0 New_Collation 1 RTRIM 2 NOCASE 3 BINARY} |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 1351 | ifcapable schema_pragmas&&tempdb { |
| 1352 | do_test pragma-12.1 { |
| 1353 | sqlite3 db2 test.db |
| 1354 | execsql { |
| 1355 | PRAGMA temp.table_info('abc'); |
| 1356 | } db2 |
| 1357 | } {} |
| 1358 | db2 close |
| 1359 | |
| 1360 | do_test pragma-12.2 { |
| 1361 | sqlite3 db2 test.db |
| 1362 | execsql { |
| 1363 | PRAGMA temp.default_cache_size = 200; |
| 1364 | PRAGMA temp.default_cache_size; |
| 1365 | } db2 |
| 1366 | } {200} |
| 1367 | db2 close |
| 1368 | |
| 1369 | do_test pragma-12.3 { |
| 1370 | sqlite3 db2 test.db |
| 1371 | execsql { |
| 1372 | PRAGMA temp.cache_size = 400; |
| 1373 | PRAGMA temp.cache_size; |
| 1374 | } db2 |
| 1375 | } {400} |
| 1376 | db2 close |
| 1377 | } |
| 1378 | |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 1379 | ifcapable bloblit { |
| 1380 | |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 1381 | do_test pragma-13.1 { |
| 1382 | execsql { |
| 1383 | DROP TABLE IF EXISTS t4; |
| 1384 | PRAGMA vdbe_trace=on; |
| 1385 | PRAGMA vdbe_listing=on; |
| 1386 | PRAGMA sql_trace=on; |
| 1387 | CREATE TABLE t4(a INTEGER PRIMARY KEY,b); |
| 1388 | INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); |
| 1389 | INSERT INTO t4(b) VALUES(randstr(30,30)); |
| 1390 | INSERT INTO t4(b) VALUES(1.23456); |
| 1391 | INSERT INTO t4(b) VALUES(NULL); |
| 1392 | INSERT INTO t4(b) VALUES(0); |
| 1393 | INSERT INTO t4(b) SELECT b||b||b||b FROM t4; |
| 1394 | SELECT * FROM t4; |
| 1395 | } |
| 1396 | execsql { |
| 1397 | PRAGMA vdbe_trace=off; |
| 1398 | PRAGMA vdbe_listing=off; |
| 1399 | PRAGMA sql_trace=off; |
| 1400 | } |
| 1401 | } {} |
| 1402 | |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 1403 | } ;# ifcapable bloblit |
| 1404 | |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1405 | ifcapable pager_pragmas { |
| 1406 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1407 | forcedelete test.db |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1408 | sqlite3 db test.db |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1409 | |
drh | b3366b9 | 2015-09-11 20:54:44 +0000 | [diff] [blame] | 1410 | # EVIDENCE-OF: R-15672-33611 PRAGMA schema.page_count; Return the total |
| 1411 | # number of pages in the database file. |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1412 | # |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1413 | do_test pragma-14.1 { |
| 1414 | execsql { pragma auto_vacuum = 0 } |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1415 | execsql { pragma page_count; pragma main.page_count } |
| 1416 | } {0 0} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1417 | |
| 1418 | do_test pragma-14.2 { |
| 1419 | execsql { |
| 1420 | CREATE TABLE abc(a, b, c); |
| 1421 | PRAGMA page_count; |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1422 | PRAGMA main.page_count; |
| 1423 | PRAGMA temp.page_count; |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1424 | } |
drh | 51a74d4 | 2015-02-28 01:04:27 +0000 | [diff] [blame] | 1425 | } {2 2 0} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 1426 | do_test pragma-14.2uc { |
| 1427 | execsql {pragma PAGE_COUNT} |
| 1428 | } {2} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1429 | |
| 1430 | do_test pragma-14.3 { |
| 1431 | execsql { |
| 1432 | BEGIN; |
| 1433 | CREATE TABLE def(a, b, c); |
| 1434 | PRAGMA page_count; |
| 1435 | } |
| 1436 | } {3} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 1437 | do_test pragma-14.3uc { |
| 1438 | execsql {pragma PAGE_COUNT} |
| 1439 | } {3} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1440 | |
| 1441 | do_test pragma-14.4 { |
| 1442 | set page_size [db one {pragma page_size}] |
| 1443 | expr [file size test.db] / $page_size |
| 1444 | } {2} |
| 1445 | |
| 1446 | do_test pragma-14.5 { |
| 1447 | execsql { |
| 1448 | ROLLBACK; |
| 1449 | PRAGMA page_count; |
| 1450 | } |
| 1451 | } {2} |
| 1452 | |
| 1453 | do_test pragma-14.6 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1454 | forcedelete test2.db |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1455 | sqlite3 db2 test2.db |
| 1456 | execsql { |
| 1457 | PRAGMA auto_vacuum = 0; |
| 1458 | CREATE TABLE t1(a, b, c); |
| 1459 | CREATE TABLE t2(a, b, c); |
| 1460 | CREATE TABLE t3(a, b, c); |
| 1461 | CREATE TABLE t4(a, b, c); |
| 1462 | } db2 |
| 1463 | db2 close |
| 1464 | execsql { |
| 1465 | ATTACH 'test2.db' AS aux; |
| 1466 | PRAGMA aux.page_count; |
| 1467 | } |
| 1468 | } {5} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 1469 | do_test pragma-14.6uc { |
| 1470 | execsql {pragma AUX.PAGE_COUNT} |
| 1471 | } {5} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
danielk1977 | 8cf6c55 | 2008-06-23 16:53:46 +0000 | [diff] [blame] | 1474 | # Test that the value set using the cache_size pragma is not reset when the |
| 1475 | # schema is reloaded. |
| 1476 | # |
| 1477 | ifcapable pager_pragmas { |
| 1478 | db close |
| 1479 | sqlite3 db test.db |
| 1480 | do_test pragma-15.1 { |
| 1481 | execsql { |
| 1482 | PRAGMA cache_size=59; |
| 1483 | PRAGMA cache_size; |
| 1484 | } |
| 1485 | } {59} |
| 1486 | do_test pragma-15.2 { |
| 1487 | sqlite3 db2 test.db |
| 1488 | execsql { |
| 1489 | CREATE TABLE newtable(a, b, c); |
| 1490 | } db2 |
| 1491 | db2 close |
| 1492 | } {} |
| 1493 | do_test pragma-15.3 { |
| 1494 | # Evaluating this statement will cause the schema to be reloaded (because |
| 1495 | # the schema was changed by another connection in pragma-15.2). At one |
| 1496 | # point there was a bug that reset the cache_size to its default value |
| 1497 | # when this happened. |
| 1498 | execsql { SELECT * FROM sqlite_master } |
| 1499 | execsql { PRAGMA cache_size } |
| 1500 | } {59} |
| 1501 | } |
| 1502 | |
danielk1977 | 5558a8a | 2005-01-17 07:53:44 +0000 | [diff] [blame] | 1503 | # Reset the sqlite3_temp_directory variable for the next run of tests: |
| 1504 | sqlite3 dbX :memory: |
| 1505 | dbX eval {PRAGMA temp_store_directory = ""} |
| 1506 | dbX close |
| 1507 | |
danielk1977 | 838cce4 | 2009-01-12 14:01:45 +0000 | [diff] [blame] | 1508 | ifcapable lock_proxy_pragmas&&prefer_proxy_locking { |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1509 | set sqlite_hostid_num 1 |
| 1510 | |
| 1511 | set using_proxy 0 |
| 1512 | foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { |
| 1513 | set using_proxy $value |
| 1514 | } |
| 1515 | |
| 1516 | # Test the lock_proxy_file pragmas. |
| 1517 | # |
| 1518 | db close |
| 1519 | set env(SQLITE_FORCE_PROXY_LOCKING) "0" |
| 1520 | |
| 1521 | sqlite3 db test.db |
| 1522 | do_test pragma-16.1 { |
| 1523 | execsql { |
| 1524 | PRAGMA lock_proxy_file="mylittleproxy"; |
| 1525 | select * from sqlite_master; |
| 1526 | } |
| 1527 | execsql { |
| 1528 | PRAGMA lock_proxy_file; |
| 1529 | } |
| 1530 | } {mylittleproxy} |
| 1531 | |
| 1532 | do_test pragma-16.2 { |
| 1533 | sqlite3 db2 test.db |
| 1534 | execsql { |
| 1535 | PRAGMA lock_proxy_file="mylittleproxy"; |
| 1536 | } db2 |
| 1537 | } {} |
| 1538 | |
| 1539 | db2 close |
| 1540 | do_test pragma-16.2.1 { |
| 1541 | sqlite3 db2 test.db |
| 1542 | execsql { |
| 1543 | PRAGMA lock_proxy_file=":auto:"; |
| 1544 | select * from sqlite_master; |
| 1545 | } db2 |
| 1546 | execsql { |
| 1547 | PRAGMA lock_proxy_file; |
| 1548 | } db2 |
| 1549 | } {mylittleproxy} |
| 1550 | |
| 1551 | db2 close |
| 1552 | do_test pragma-16.3 { |
| 1553 | sqlite3 db2 test.db |
| 1554 | execsql { |
| 1555 | PRAGMA lock_proxy_file="myotherproxy"; |
| 1556 | } db2 |
| 1557 | catchsql { |
| 1558 | select * from sqlite_master; |
| 1559 | } db2 |
| 1560 | } {1 {database is locked}} |
| 1561 | |
| 1562 | do_test pragma-16.4 { |
| 1563 | db2 close |
| 1564 | db close |
| 1565 | sqlite3 db2 test.db |
| 1566 | execsql { |
| 1567 | PRAGMA lock_proxy_file="myoriginalproxy"; |
| 1568 | PRAGMA lock_proxy_file="myotherproxy"; |
| 1569 | PRAGMA lock_proxy_file; |
| 1570 | } db2 |
| 1571 | } {myotherproxy} |
| 1572 | |
| 1573 | db2 close |
| 1574 | set env(SQLITE_FORCE_PROXY_LOCKING) "1" |
| 1575 | do_test pragma-16.5 { |
| 1576 | sqlite3 db2 test.db |
| 1577 | execsql { |
| 1578 | PRAGMA lock_proxy_file=":auto:"; |
| 1579 | PRAGMA lock_proxy_file; |
| 1580 | } db2 |
| 1581 | } {myotherproxy} |
| 1582 | |
| 1583 | do_test pragma-16.6 { |
| 1584 | db2 close |
| 1585 | sqlite3 db2 test2.db |
| 1586 | set lockpath [execsql { |
| 1587 | PRAGMA lock_proxy_file=":auto:"; |
| 1588 | PRAGMA lock_proxy_file; |
| 1589 | } db2] |
| 1590 | string match "*test2.db:auto:" $lockpath |
| 1591 | } {1} |
| 1592 | |
| 1593 | set sqlite_hostid_num 2 |
| 1594 | do_test pragma-16.7 { |
dan | 14d1460 | 2010-10-06 16:42:52 +0000 | [diff] [blame] | 1595 | list [catch { |
| 1596 | sqlite3 db test2.db |
| 1597 | execsql { |
| 1598 | PRAGMA lock_proxy_file=":auto:"; |
| 1599 | select * from sqlite_master; |
| 1600 | } |
| 1601 | } msg] $msg |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1602 | } {1 {database is locked}} |
| 1603 | db close |
| 1604 | |
| 1605 | do_test pragma-16.8 { |
dan | 14d1460 | 2010-10-06 16:42:52 +0000 | [diff] [blame] | 1606 | list [catch { |
| 1607 | sqlite3 db test2.db |
| 1608 | execsql { select * from sqlite_master } |
| 1609 | } msg] $msg |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1610 | } {1 {database is locked}} |
| 1611 | |
| 1612 | db2 close |
| 1613 | do_test pragma-16.8.1 { |
| 1614 | execsql { |
| 1615 | PRAGMA lock_proxy_file="yetanotherproxy"; |
| 1616 | PRAGMA lock_proxy_file; |
| 1617 | } |
| 1618 | } {yetanotherproxy} |
| 1619 | do_test pragma-16.8.2 { |
| 1620 | execsql { |
| 1621 | create table mine(x); |
| 1622 | } |
| 1623 | } {} |
| 1624 | |
| 1625 | db close |
| 1626 | do_test pragma-16.9 { |
| 1627 | sqlite3 db proxytest.db |
| 1628 | set lockpath2 [execsql { |
| 1629 | PRAGMA lock_proxy_file=":auto:"; |
| 1630 | PRAGMA lock_proxy_file; |
| 1631 | } db] |
| 1632 | string match "*proxytest.db:auto:" $lockpath2 |
| 1633 | } {1} |
| 1634 | |
| 1635 | set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy |
| 1636 | set sqlite_hostid_num 0 |
| 1637 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1638 | |
| 1639 | # Parsing of auto_vacuum settings. |
| 1640 | # |
| 1641 | foreach {autovac_setting val} { |
| 1642 | 0 0 |
| 1643 | 1 1 |
| 1644 | 2 2 |
| 1645 | 3 0 |
| 1646 | -1 0 |
| 1647 | none 0 |
| 1648 | NONE 0 |
| 1649 | NoNe 0 |
| 1650 | full 1 |
| 1651 | FULL 1 |
| 1652 | incremental 2 |
| 1653 | INCREMENTAL 2 |
| 1654 | -1234 0 |
| 1655 | 1234 0 |
| 1656 | } { |
| 1657 | do_test pragma-17.1.$autovac_setting { |
| 1658 | catch {db close} |
| 1659 | sqlite3 db :memory: |
| 1660 | execsql " |
| 1661 | PRAGMA auto_vacuum=$::autovac_setting; |
| 1662 | PRAGMA auto_vacuum; |
| 1663 | " |
| 1664 | } $val |
| 1665 | } |
| 1666 | |
| 1667 | # Parsing of temp_store settings. |
| 1668 | # |
| 1669 | foreach {temp_setting val} { |
| 1670 | 0 0 |
| 1671 | 1 1 |
| 1672 | 2 2 |
| 1673 | 3 0 |
| 1674 | -1 0 |
| 1675 | file 1 |
| 1676 | FILE 1 |
| 1677 | fIlE 1 |
| 1678 | memory 2 |
| 1679 | MEMORY 2 |
| 1680 | MeMoRy 2 |
| 1681 | } { |
| 1682 | do_test pragma-18.1.$temp_setting { |
| 1683 | catch {db close} |
| 1684 | sqlite3 db :memory: |
| 1685 | execsql " |
| 1686 | PRAGMA temp_store=$::temp_setting; |
| 1687 | PRAGMA temp_store=$::temp_setting; |
| 1688 | PRAGMA temp_store; |
| 1689 | " |
| 1690 | } $val |
| 1691 | } |
| 1692 | |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1693 | # The SQLITE_FCNTL_PRAGMA logic, with error handling. |
| 1694 | # |
| 1695 | db close |
| 1696 | testvfs tvfs |
| 1697 | sqlite3 db test.db -vfs tvfs |
| 1698 | do_test pragma-19.1 { |
| 1699 | catchsql {PRAGMA error} |
drh | a690ff3 | 2017-07-07 19:43:23 +0000 | [diff] [blame] | 1700 | } {1 {SQL logic error}} |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1701 | do_test pragma-19.2 { |
| 1702 | catchsql {PRAGMA error='This is the error message'} |
| 1703 | } {1 {This is the error message}} |
| 1704 | do_test pragma-19.3 { |
| 1705 | catchsql {PRAGMA error='7 This is the error message'} |
| 1706 | } {1 {This is the error message}} |
| 1707 | do_test pragma-19.4 { |
| 1708 | catchsql {PRAGMA error=7} |
| 1709 | } {1 {out of memory}} |
drh | c8517f6 | 2012-02-22 20:08:49 +0000 | [diff] [blame] | 1710 | do_test pragma-19.5 { |
mistachkin | 5b04454 | 2012-03-02 22:41:06 +0000 | [diff] [blame] | 1711 | file tail [lindex [execsql {PRAGMA filename}] 0] |
drh | c8517f6 | 2012-02-22 20:08:49 +0000 | [diff] [blame] | 1712 | } {test.db} |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1713 | |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1714 | if {$tcl_platform(platform)=="windows"} { |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1715 | # Test data_store_directory pragma |
| 1716 | # |
| 1717 | db close |
| 1718 | sqlite3 db test.db |
| 1719 | file mkdir data_dir |
| 1720 | do_test pragma-20.1 { |
| 1721 | catchsql {PRAGMA data_store_directory} |
| 1722 | } {0 {}} |
| 1723 | do_test pragma-20.2 { |
| 1724 | set pwd [string map {' ''} [file nativename [get_pwd]]] |
| 1725 | catchsql "PRAGMA data_store_directory='$pwd';" |
| 1726 | } {0 {}} |
| 1727 | do_test pragma-20.3 { |
| 1728 | catchsql {PRAGMA data_store_directory} |
| 1729 | } [list 0 [list [file nativename [get_pwd]]]] |
| 1730 | do_test pragma-20.4 { |
| 1731 | set pwd [string map {' ''} [file nativename \ |
| 1732 | [file join [get_pwd] data_dir]]] |
| 1733 | catchsql "PRAGMA data_store_directory='$pwd';" |
| 1734 | } {0 {}} |
| 1735 | do_test pragma-20.5 { |
| 1736 | sqlite3 db2 test2.db |
| 1737 | catchsql "PRAGMA database_list;" db2 |
| 1738 | } [list 0 [list 0 main [file nativename \ |
| 1739 | [file join [get_pwd] data_dir test2.db]]]] |
| 1740 | catch {db2 close} |
| 1741 | do_test pragma-20.6 { |
| 1742 | sqlite3 db2 [file join [get_pwd] test2.db] |
| 1743 | catchsql "PRAGMA database_list;" db2 |
| 1744 | } [list 0 [list 0 main [file nativename \ |
| 1745 | [file join [get_pwd] test2.db]]]] |
| 1746 | catch {db2 close} |
| 1747 | do_test pragma-20.7 { |
| 1748 | catchsql "PRAGMA data_store_directory='';" |
| 1749 | } {0 {}} |
| 1750 | do_test pragma-20.8 { |
| 1751 | catchsql {PRAGMA data_store_directory} |
| 1752 | } {0 {}} |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1753 | |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1754 | forcedelete data_dir |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1755 | } ;# endif windows |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 1756 | |
dan | 1fed5da | 2014-02-25 21:01:25 +0000 | [diff] [blame] | 1757 | database_may_be_corrupt |
drh | 7da56b4 | 2016-03-14 18:34:42 +0000 | [diff] [blame] | 1758 | if {![nonzero_reserved_bytes]} { |
dan | 1fed5da | 2014-02-25 21:01:25 +0000 | [diff] [blame] | 1759 | |
drh | 7da56b4 | 2016-03-14 18:34:42 +0000 | [diff] [blame] | 1760 | do_test 21.1 { |
| 1761 | # Create a corrupt database in testerr.db. And a non-corrupt at test.db. |
| 1762 | # |
| 1763 | db close |
| 1764 | forcedelete test.db |
| 1765 | sqlite3 db test.db |
| 1766 | execsql { |
| 1767 | PRAGMA page_size = 1024; |
| 1768 | PRAGMA auto_vacuum = 0; |
| 1769 | CREATE TABLE t1(a PRIMARY KEY, b); |
| 1770 | INSERT INTO t1 VALUES(1, 1); |
| 1771 | } |
| 1772 | for {set i 0} {$i < 10} {incr i} { |
| 1773 | execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } |
| 1774 | } |
| 1775 | db close |
| 1776 | forcecopy test.db testerr.db |
| 1777 | hexio_write testerr.db 15000 [string repeat 55 100] |
| 1778 | } {100} |
| 1779 | |
| 1780 | set mainerr {*** in database main *** |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1781 | Multiple uses for byte 672 of page 15} |
drh | 7da56b4 | 2016-03-14 18:34:42 +0000 | [diff] [blame] | 1782 | set auxerr {*** in database aux *** |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1783 | Multiple uses for byte 672 of page 15} |
drh | 7da56b4 | 2016-03-14 18:34:42 +0000 | [diff] [blame] | 1784 | |
| 1785 | set mainerr {/{\*\*\* in database main \*\*\* |
dan | 597515d | 2014-02-28 18:39:51 +0000 | [diff] [blame] | 1786 | Multiple uses for byte 672 of page 15}.*/} |
drh | 7da56b4 | 2016-03-14 18:34:42 +0000 | [diff] [blame] | 1787 | set auxerr {/{\*\*\* in database aux \*\*\* |
dan | 597515d | 2014-02-28 18:39:51 +0000 | [diff] [blame] | 1788 | Multiple uses for byte 672 of page 15}.*/} |
drh | 7da56b4 | 2016-03-14 18:34:42 +0000 | [diff] [blame] | 1789 | |
| 1790 | do_test 22.2 { |
| 1791 | catch { db close } |
| 1792 | sqlite3 db testerr.db |
| 1793 | execsql { PRAGMA integrity_check } |
| 1794 | } $mainerr |
| 1795 | |
| 1796 | do_test 22.3.1 { |
| 1797 | catch { db close } |
| 1798 | sqlite3 db test.db |
| 1799 | execsql { |
| 1800 | ATTACH 'testerr.db' AS 'aux'; |
| 1801 | PRAGMA integrity_check; |
| 1802 | } |
| 1803 | } $auxerr |
| 1804 | do_test 22.3.2 { |
| 1805 | execsql { PRAGMA main.integrity_check; } |
| 1806 | } {ok} |
| 1807 | do_test 22.3.3 { |
| 1808 | execsql { PRAGMA aux.integrity_check; } |
| 1809 | } $auxerr |
| 1810 | |
| 1811 | do_test 22.4.1 { |
| 1812 | catch { db close } |
| 1813 | sqlite3 db testerr.db |
| 1814 | execsql { |
| 1815 | ATTACH 'test.db' AS 'aux'; |
| 1816 | PRAGMA integrity_check; |
| 1817 | } |
| 1818 | } $mainerr |
| 1819 | do_test 22.4.2 { |
| 1820 | execsql { PRAGMA main.integrity_check; } |
| 1821 | } $mainerr |
| 1822 | do_test 22.4.3 { |
| 1823 | execsql { PRAGMA aux.integrity_check; } |
| 1824 | } {ok} |
| 1825 | } |
| 1826 | |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1827 | db close |
| 1828 | forcedelete test.db test.db-wal test.db-journal |
| 1829 | sqlite3 db test.db |
| 1830 | sqlite3 db2 test.db |
| 1831 | do_test 23.1 { |
| 1832 | db eval { |
| 1833 | CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d); |
| 1834 | CREATE INDEX i1 ON t1(b,c); |
| 1835 | CREATE INDEX i2 ON t1(c,d); |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1836 | CREATE INDEX i2x ON t1(d COLLATE nocase, c DESC); |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1837 | CREATE TABLE t2(x INTEGER REFERENCES t1); |
| 1838 | } |
| 1839 | db2 eval {SELECT name FROM sqlite_master} |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1840 | } {t1 i1 i2 i2x t2} |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1841 | do_test 23.2a { |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1842 | db eval { |
| 1843 | DROP INDEX i2; |
| 1844 | CREATE INDEX i2 ON t1(c,d,b); |
| 1845 | } |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1846 | capture_pragma db2 out {PRAGMA index_info(i2)} |
drh | 5e7028c | 2015-03-05 14:29:02 +0000 | [diff] [blame] | 1847 | db2 eval {SELECT cid, name, '|' FROM out ORDER BY seqno} |
| 1848 | } {2 c | 3 d | 1 b |} |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1849 | |
drh | b3366b9 | 2015-09-11 20:54:44 +0000 | [diff] [blame] | 1850 | # EVIDENCE-OF: R-56143-29319 PRAGMA schema.index_xinfo(index-name); This |
| 1851 | # pragma returns information about every column in an index. |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1852 | # |
| 1853 | # EVIDENCE-OF: R-45970-35618 Unlike this index_info pragma, this pragma |
| 1854 | # returns information about every column in the index, not just the key |
| 1855 | # columns. |
| 1856 | # |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1857 | do_test 23.2b { |
| 1858 | capture_pragma db2 out {PRAGMA index_xinfo(i2)} |
| 1859 | db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} |
| 1860 | } {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |} |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1861 | |
| 1862 | # (The first column of output from PRAGMA index_xinfo is...) |
| 1863 | # EVIDENCE-OF: R-00197-14279 The rank of the column within the index. (0 |
| 1864 | # means left-most. Key columns come before auxiliary columns.) |
| 1865 | # |
| 1866 | # (The second column of output from PRAGMA index_xinfo is...) |
| 1867 | # EVIDENCE-OF: R-40889-06838 The rank of the column within the table |
| 1868 | # being indexed, or -1 if the index-column is the rowid of the table |
| 1869 | # being indexed. |
| 1870 | # |
| 1871 | # (The third column of output from PRAGMA index_xinfo is...) |
| 1872 | # EVIDENCE-OF: R-22751-28901 The name of the column being indexed, or |
| 1873 | # NULL if the index-column is the rowid of the table being indexed. |
| 1874 | # |
| 1875 | # (The fourth column of output from PRAGMA index_xinfo is...) |
| 1876 | # EVIDENCE-OF: R-11847-09179 1 if the index-column is sorted in reverse |
| 1877 | # (DESC) order by the index and 0 otherwise. |
| 1878 | # |
| 1879 | # (The fifth column of output from PRAGMA index_xinfo is...) |
| 1880 | # EVIDENCE-OF: R-15313-19540 The name for the collating sequence used to |
| 1881 | # compare values in the index-column. |
| 1882 | # |
| 1883 | # (The sixth column of output from PRAGMA index_xinfo is...) |
| 1884 | # EVIDENCE-OF: R-14310-64553 1 if the index-column is a key column and 0 |
| 1885 | # if the index-column is an auxiliary column. |
| 1886 | # |
| 1887 | do_test 23.2c { |
| 1888 | db2 eval {PRAGMA index_xinfo(i2)} |
| 1889 | } {0 2 c 0 BINARY 1 1 3 d 0 BINARY 1 2 1 b 0 BINARY 1 3 -1 {} 0 BINARY 0} |
| 1890 | do_test 23.2d { |
| 1891 | db2 eval {PRAGMA index_xinfo(i2x)} |
| 1892 | } {0 3 d 0 nocase 1 1 2 c 1 BINARY 1 2 -1 {} 0 BINARY 0} |
| 1893 | |
drh | b3366b9 | 2015-09-11 20:54:44 +0000 | [diff] [blame] | 1894 | # EVIDENCE-OF: R-64103-17776 PRAGMA schema.index_list(table-name); This |
| 1895 | # pragma returns one row for each index associated with the given table. |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1896 | # |
| 1897 | # (The first column of output from PRAGMA index_list is...) |
| 1898 | # EVIDENCE-OF: R-02753-24748 A sequence number assigned to each index |
| 1899 | # for internal tracking purposes. |
| 1900 | # |
| 1901 | # (The second column of output from PRAGMA index_list is...) |
| 1902 | # EVIDENCE-OF: R-35496-03635 The name of the index. |
| 1903 | # |
| 1904 | # (The third column of output from PRAGMA index_list is...) |
| 1905 | # EVIDENCE-OF: R-57301-64506 "1" if the index is UNIQUE and "0" if not. |
| 1906 | # |
| 1907 | # (The fourth column of output from PRAGMA index_list is...) |
| 1908 | # EVIDENCE-OF: R-36609-39554 "c" if the index was created by a CREATE |
| 1909 | # INDEX statement, "u" if the index was created by a UNIQUE constraint, |
| 1910 | # or "pk" if the index was created by a PRIMARY KEY constraint. |
| 1911 | # |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1912 | do_test 23.3 { |
| 1913 | db eval { |
| 1914 | CREATE INDEX i3 ON t1(d,b,c); |
| 1915 | } |
drh | c228be5 | 2015-01-31 02:00:01 +0000 | [diff] [blame] | 1916 | capture_pragma db2 out {PRAGMA index_list(t1)} |
drh | 7be0fd9 | 2015-03-05 15:34:15 +0000 | [diff] [blame] | 1917 | db2 eval {SELECT seq, name, "unique", origin, '|' FROM out ORDER BY seq} |
| 1918 | } {0 i3 0 c | 1 i2 0 c | 2 i2x 0 c | 3 i1 0 c |} |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1919 | do_test 23.4 { |
| 1920 | db eval { |
| 1921 | ALTER TABLE t1 ADD COLUMN e; |
| 1922 | } |
| 1923 | db2 eval { |
| 1924 | PRAGMA table_info(t1); |
| 1925 | } |
| 1926 | } {/4 e {} 0 {} 0/} |
| 1927 | do_test 23.5 { |
| 1928 | db eval { |
| 1929 | DROP TABLE t2; |
| 1930 | CREATE TABLE t2(x, y INTEGER REFERENCES t1); |
| 1931 | } |
| 1932 | db2 eval { |
| 1933 | PRAGMA foreign_key_list(t2); |
| 1934 | } |
| 1935 | } {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE} |
drh | 3e1e14d | 2017-09-12 00:24:45 +0000 | [diff] [blame] | 1936 | db2 close |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1937 | |
drh | efeaec3 | 2017-10-23 16:34:07 +0000 | [diff] [blame] | 1938 | ifcapable !has_codec { |
| 1939 | reset_db |
| 1940 | do_execsql_test 24.0 { |
| 1941 | PRAGMA page_size = 1024; |
| 1942 | CREATE TABLE t1(a, b, c); |
| 1943 | CREATE INDEX i1 ON t1(b); |
| 1944 | INSERT INTO t1 VALUES('a', 'b', 'c'); |
| 1945 | PRAGMA integrity_check; |
| 1946 | } {ok} |
| 1947 | |
| 1948 | set r [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1'}] |
| 1949 | db close |
| 1950 | hexio_write test.db [expr $r*1024 - 16] 000000000000000701040f0f1f616263 |
| 1951 | |
| 1952 | sqlite3 db test.db |
| 1953 | do_catchsql_test 24.1 { |
| 1954 | SELECT * FROM t1; |
| 1955 | } {1 {database disk image is malformed}} |
| 1956 | do_catchsql_test 24.2 { |
| 1957 | PRAGMA integrity_check; |
| 1958 | } {0 {{database disk image is malformed}}} |
| 1959 | } |
dan | 1fed5da | 2014-02-25 21:01:25 +0000 | [diff] [blame] | 1960 | database_never_corrupt |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 1961 | finish_test |