| OLD | NEW |
| (Empty) | |
| 1 # 2012 January 4 {} |
| 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 # Test recover module syntax. |
| 14 # |
| 15 # $Id$ |
| 16 |
| 17 # TODO(shess): Test with attached databases. |
| 18 |
| 19 # TODO(shess): Handle column mismatches? As things stand, the code |
| 20 # only needs to pull the root page, so that may not be completely |
| 21 # feasible. |
| 22 |
| 23 set testdir [file dirname $argv0] |
| 24 source $testdir/tester.tcl |
| 25 |
| 26 db eval { |
| 27 DROP TABLE IF EXISTS backing; |
| 28 CREATE TABLE backing (t TEXT); |
| 29 |
| 30 DROP TABLE IF EXISTS backing2; |
| 31 CREATE TABLE backing2 (id INTEGER PRIMARY KEY, t TEXT); |
| 32 } |
| 33 |
| 34 # Baseline create works. |
| 35 do_test recover-syntax-0.0 { |
| 36 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 37 catchsql { |
| 38 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 39 backing, |
| 40 t TEXT |
| 41 ); |
| 42 } |
| 43 } {0 {}} |
| 44 |
| 45 # Can specify database. |
| 46 do_test recover-syntax-0.1 { |
| 47 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 48 catchsql { |
| 49 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 50 main.backing, |
| 51 t TEXT |
| 52 ); |
| 53 } |
| 54 } {0 {}} |
| 55 |
| 56 # Can specify sqlite_master. |
| 57 do_test recover-syntax-0.2 { |
| 58 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 59 catchsql { |
| 60 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 61 sqlite_master, |
| 62 type TEXT, |
| 63 name TEXT, |
| 64 tbl_name TEXT, |
| 65 rootpage INTEGER, |
| 66 sql TEXT |
| 67 ); |
| 68 } |
| 69 } {0 {}} |
| 70 |
| 71 # Fails if virtual table is not in the temp database. |
| 72 do_test recover-syntax-1.0 { |
| 73 db eval {DROP TABLE IF EXISTS temp.syntax;} |
| 74 catchsql { |
| 75 CREATE VIRTUAL TABLE syntax USING recover( |
| 76 backing, |
| 77 t TEXT |
| 78 ); |
| 79 } |
| 80 } {1 {vtable constructor failed: syntax}} |
| 81 |
| 82 # Fails if mentions missing table. |
| 83 do_test recover-syntax-2.0 { |
| 84 db eval {DROP TABLE IF EXISTS temp.syntax;} |
| 85 catchsql { |
| 86 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 87 snacking, |
| 88 t TEXT |
| 89 ); |
| 90 } |
| 91 } {1 {vtable constructor failed: syntax}} |
| 92 |
| 93 # Fails if mentions missing database. |
| 94 do_test recover-syntax-2.1 { |
| 95 db eval {DROP TABLE IF EXISTS temp.syntax;} |
| 96 catchsql { |
| 97 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 98 db.backing, |
| 99 t TEXT |
| 100 ); |
| 101 } |
| 102 } {1 {vtable constructor failed: syntax}} |
| 103 |
| 104 # Fails if mentions garbage backing. |
| 105 do_test recover-syntax-2.2 { |
| 106 db eval {DROP TABLE IF EXISTS temp.syntax;} |
| 107 catchsql { |
| 108 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 109 main.backing excess, |
| 110 t TEXT |
| 111 ); |
| 112 } |
| 113 } {1 {vtable constructor failed: syntax}} |
| 114 |
| 115 # Manifest typing. |
| 116 do_test recover-syntax-3.0 { |
| 117 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 118 execsql { |
| 119 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 120 backing, |
| 121 t |
| 122 ); |
| 123 PRAGMA table_info(syntax); |
| 124 } |
| 125 } {0 t {} 0 {} 0} |
| 126 |
| 127 # ANY as an alternative for manifest typing. |
| 128 do_test recover-syntax-3.1 { |
| 129 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 130 execsql { |
| 131 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 132 backing, |
| 133 t ANY |
| 134 ); |
| 135 PRAGMA table_info(syntax); |
| 136 } |
| 137 } {0 t {} 0 {} 0} |
| 138 |
| 139 # ANY NOT NULL |
| 140 do_test recover-syntax-3.2 { |
| 141 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 142 execsql { |
| 143 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 144 backing, |
| 145 t ANY NOT NULL |
| 146 ); |
| 147 PRAGMA table_info(syntax); |
| 148 } |
| 149 } {0 t {} 1 {} 0} |
| 150 |
| 151 # ANY STRICT is not sensible. |
| 152 do_test recover-syntax-3.3 { |
| 153 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 154 catchsql { |
| 155 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 156 backing, |
| 157 v ANY STRICT |
| 158 ); |
| 159 PRAGMA table_info(syntax); |
| 160 } |
| 161 } {1 {vtable constructor failed: syntax}} |
| 162 |
| 163 # TEXT column by type works. |
| 164 do_test recover-syntax-4.0 { |
| 165 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 166 execsql { |
| 167 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 168 backing, |
| 169 t TEXT |
| 170 ); |
| 171 PRAGMA table_info(syntax); |
| 172 } |
| 173 } {0 t TEXT 0 {} 0} |
| 174 |
| 175 # TEXT NOT NULL |
| 176 do_test recover-syntax-4.1 { |
| 177 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 178 execsql { |
| 179 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 180 backing, |
| 181 t TEXT NOT NULL |
| 182 ); |
| 183 PRAGMA table_info(syntax); |
| 184 } |
| 185 } {0 t TEXT 1 {} 0} |
| 186 |
| 187 # TEXT STRICT |
| 188 do_test recover-syntax-4.2 { |
| 189 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 190 execsql { |
| 191 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 192 backing, |
| 193 t TEXT STRICT |
| 194 ); |
| 195 PRAGMA table_info(syntax); |
| 196 } |
| 197 } {0 t TEXT 0 {} 0} |
| 198 |
| 199 # TEXT STRICT NOT NULL |
| 200 do_test recover-syntax-4.3 { |
| 201 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 202 execsql { |
| 203 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 204 backing, |
| 205 t TEXT STRICT NOT NULL |
| 206 ); |
| 207 PRAGMA table_info(syntax); |
| 208 } |
| 209 } {0 t TEXT 1 {} 0} |
| 210 |
| 211 # INTEGER |
| 212 do_test recover-syntax-5.0 { |
| 213 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 214 execsql { |
| 215 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 216 backing, |
| 217 i INTEGER |
| 218 ); |
| 219 PRAGMA table_info(syntax); |
| 220 } |
| 221 } {0 i INTEGER 0 {} 0} |
| 222 |
| 223 # INTEGER NOT NULL |
| 224 do_test recover-syntax-5.1 { |
| 225 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 226 execsql { |
| 227 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 228 backing, |
| 229 i INTEGER NOT NULL |
| 230 ); |
| 231 PRAGMA table_info(syntax); |
| 232 } |
| 233 } {0 i INTEGER 1 {} 0} |
| 234 |
| 235 # INTEGER STRICT |
| 236 do_test recover-syntax-5.2 { |
| 237 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 238 execsql { |
| 239 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 240 backing, |
| 241 i INTEGER STRICT |
| 242 ); |
| 243 PRAGMA table_info(syntax); |
| 244 } |
| 245 } {0 i INTEGER 0 {} 0} |
| 246 |
| 247 # INTEGER STRICT NOT NULL |
| 248 do_test recover-syntax-5.3 { |
| 249 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 250 execsql { |
| 251 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 252 backing, |
| 253 i INTEGER STRICT NOT NULL |
| 254 ); |
| 255 PRAGMA table_info(syntax); |
| 256 } |
| 257 } {0 i INTEGER 1 {} 0} |
| 258 |
| 259 # BLOB |
| 260 do_test recover-syntax-6.0 { |
| 261 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 262 execsql { |
| 263 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 264 backing, |
| 265 b BLOB |
| 266 ); |
| 267 PRAGMA table_info(syntax); |
| 268 } |
| 269 } {0 b BLOB 0 {} 0} |
| 270 |
| 271 # BLOB NOT NULL |
| 272 do_test recover-syntax-6.1 { |
| 273 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 274 execsql { |
| 275 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 276 backing, |
| 277 b BLOB NOT NULL |
| 278 ); |
| 279 PRAGMA table_info(syntax); |
| 280 } |
| 281 } {0 b BLOB 1 {} 0} |
| 282 |
| 283 # BLOB STRICT |
| 284 do_test recover-syntax-6.2 { |
| 285 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 286 execsql { |
| 287 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 288 backing, |
| 289 b BLOB STRICT |
| 290 ); |
| 291 PRAGMA table_info(syntax); |
| 292 } |
| 293 } {0 b BLOB 0 {} 0} |
| 294 |
| 295 # BLOB STRICT NOT NULL |
| 296 do_test recover-syntax-6.3 { |
| 297 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 298 execsql { |
| 299 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 300 backing, |
| 301 b BLOB STRICT NOT NULL |
| 302 ); |
| 303 PRAGMA table_info(syntax); |
| 304 } |
| 305 } {0 b BLOB 1 {} 0} |
| 306 |
| 307 # FLOAT |
| 308 do_test recover-syntax-7.0 { |
| 309 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 310 execsql { |
| 311 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 312 backing, |
| 313 f FLOAT |
| 314 ); |
| 315 PRAGMA table_info(syntax); |
| 316 } |
| 317 } {0 f FLOAT 0 {} 0} |
| 318 |
| 319 # FLOAT NOT NULL |
| 320 do_test recover-syntax-7.1 { |
| 321 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 322 execsql { |
| 323 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 324 backing, |
| 325 f FLOAT NOT NULL |
| 326 ); |
| 327 PRAGMA table_info(syntax); |
| 328 } |
| 329 } {0 f FLOAT 1 {} 0} |
| 330 |
| 331 # FLOAT STRICT |
| 332 do_test recover-syntax-7.2 { |
| 333 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 334 execsql { |
| 335 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 336 backing, |
| 337 f FLOAT STRICT |
| 338 ); |
| 339 PRAGMA table_info(syntax); |
| 340 } |
| 341 } {0 f FLOAT 0 {} 0} |
| 342 |
| 343 # FLOAT STRICT NOT NULL |
| 344 do_test recover-syntax-7.3 { |
| 345 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 346 execsql { |
| 347 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 348 backing, |
| 349 f FLOAT STRICT NOT NULL |
| 350 ); |
| 351 PRAGMA table_info(syntax); |
| 352 } |
| 353 } {0 f FLOAT 1 {} 0} |
| 354 |
| 355 # NUMERIC |
| 356 do_test recover-syntax-8.0 { |
| 357 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 358 execsql { |
| 359 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 360 backing, |
| 361 f NUMERIC |
| 362 ); |
| 363 PRAGMA table_info(syntax); |
| 364 } |
| 365 } {0 f NUMERIC 0 {} 0} |
| 366 |
| 367 # NUMERIC NOT NULL |
| 368 do_test recover-syntax-8.1 { |
| 369 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 370 execsql { |
| 371 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 372 backing, |
| 373 f NUMERIC NOT NULL |
| 374 ); |
| 375 PRAGMA table_info(syntax); |
| 376 } |
| 377 } {0 f NUMERIC 1 {} 0} |
| 378 |
| 379 # NUMERIC STRICT |
| 380 do_test recover-syntax-8.2 { |
| 381 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 382 execsql { |
| 383 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 384 backing, |
| 385 f NUMERIC STRICT |
| 386 ); |
| 387 PRAGMA table_info(syntax); |
| 388 } |
| 389 } {0 f NUMERIC 0 {} 0} |
| 390 |
| 391 # NUMERIC STRICT NOT NULL |
| 392 do_test recover-syntax-8.3 { |
| 393 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 394 execsql { |
| 395 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 396 backing, |
| 397 f NUMERIC STRICT NOT NULL |
| 398 ); |
| 399 PRAGMA table_info(syntax); |
| 400 } |
| 401 } {0 f NUMERIC 1 {} 0} |
| 402 |
| 403 # ROWID |
| 404 do_test recover-syntax-9.0 { |
| 405 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 406 execsql { |
| 407 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 408 backing2, |
| 409 id ROWID, |
| 410 v |
| 411 ); |
| 412 PRAGMA table_info(syntax); |
| 413 } |
| 414 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0} |
| 415 |
| 416 # ROWID NOT NULL (is default) |
| 417 do_test recover-syntax-9.1 { |
| 418 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 419 execsql { |
| 420 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 421 backing2, |
| 422 id ROWID NOT NULL, |
| 423 v |
| 424 ); |
| 425 PRAGMA table_info(syntax); |
| 426 } |
| 427 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0} |
| 428 |
| 429 # ROWID STRICT |
| 430 do_test recover-syntax-9.0 { |
| 431 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 432 execsql { |
| 433 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 434 backing2, |
| 435 id ROWID STRICT, |
| 436 v |
| 437 ); |
| 438 PRAGMA table_info(syntax); |
| 439 } |
| 440 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0} |
| 441 |
| 442 # ROWID STRICT NOT NULL (is default) |
| 443 do_test recover-syntax-9.1 { |
| 444 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 445 execsql { |
| 446 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 447 backing2, |
| 448 id ROWID STRICT NOT NULL, |
| 449 v |
| 450 ); |
| 451 PRAGMA table_info(syntax); |
| 452 } |
| 453 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0} |
| 454 |
| 455 # Invalid type info is not ignored. |
| 456 do_test recover-syntax-10.0 { |
| 457 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 458 catchsql { |
| 459 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 460 backing, |
| 461 v GARBAGE |
| 462 ); |
| 463 } |
| 464 } {1 {vtable constructor failed: syntax}} |
| 465 |
| 466 # Extraneous type info is not ignored. |
| 467 do_test recover-syntax-10.1 { |
| 468 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 469 catchsql { |
| 470 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 471 backing, |
| 472 v INTEGER GARBAGE |
| 473 ); |
| 474 } |
| 475 } {1 {vtable constructor failed: syntax}} |
| 476 |
| 477 # Extraneous type info is not ignored. |
| 478 do_test recover-syntax-10.2 { |
| 479 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 480 catchsql { |
| 481 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 482 backing, |
| 483 v INTEGER NOT NULL GARBAGE |
| 484 ); |
| 485 } |
| 486 } {1 {vtable constructor failed: syntax}} |
| 487 |
| 488 # Multiple types don't work. |
| 489 do_test recover-syntax-10.3 { |
| 490 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 491 catchsql { |
| 492 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 493 backing, |
| 494 v INTEGER FLOAT BLOB |
| 495 ); |
| 496 } |
| 497 } {1 {vtable constructor failed: syntax}} |
| 498 |
| 499 # Multiple types don't work. |
| 500 do_test recover-syntax-10.4 { |
| 501 db eval {DROP TABLE IF EXISTS temp.syntax} |
| 502 catchsql { |
| 503 CREATE VIRTUAL TABLE temp.syntax USING recover( |
| 504 backing, |
| 505 v INTEGER NOT NULL TEXT |
| 506 ); |
| 507 } |
| 508 } {1 {vtable constructor failed: syntax}} |
| 509 |
| 510 finish_test |
| OLD | NEW |