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