| OLD | NEW |
| 1 # 2005 February 18 | 1 # 2005 February 18 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #************************************************************************* | 10 #************************************************************************* |
| 11 # This file implements regression tests for SQLite library. The | 11 # This file implements regression tests for SQLite library. The |
| 12 # focus of this script is testing that SQLite can handle a subtle | 12 # focus of this script is testing that SQLite can handle a subtle |
| 13 # file format change that may be used in the future to implement | 13 # file format change that may be used in the future to implement |
| 14 # "ALTER TABLE ... ADD COLUMN". | 14 # "ALTER TABLE ... ADD COLUMN". |
| 15 # | 15 # |
| 16 # $Id: alter2.test,v 1.14 2009/04/07 14:14:22 danielk1977 Exp $ | 16 # $Id: alter2.test,v 1.14 2009/04/07 14:14:22 danielk1977 Exp $ |
| 17 # | 17 # |
| 18 | 18 |
| 19 set testdir [file dirname $argv0] | 19 set testdir [file dirname $argv0] |
| 20 source $testdir/tester.tcl | 20 source $testdir/tester.tcl |
| 21 | 21 |
| 22 # We have to have pragmas in order to do this test | 22 # We have to have pragmas in order to do this test |
| 23 ifcapable {!pragma} return | 23 ifcapable {!pragma} return |
| 24 | 24 |
| 25 # These tests do not work if there is a codec. | 25 # Do not use a codec for tests in this file, as the database file is |
| 26 # manipulated directly using tcl scripts. See proc [set_file_format]. |
| 26 # | 27 # |
| 27 #if {[catch {sqlite3 -has_codec} r] || $r} return | 28 do_not_use_codec |
| 28 | 29 |
| 29 # The file format change affects the way row-records stored in tables (but | 30 # The file format change affects the way row-records stored in tables (but |
| 30 # not indices) are interpreted. Before version 3.1.3, a row-record for a | 31 # not indices) are interpreted. Before version 3.1.3, a row-record for a |
| 31 # table with N columns was guaranteed to contain exactly N fields. As | 32 # table with N columns was guaranteed to contain exactly N fields. As |
| 32 # of version 3.1.3, the record may contain up to N fields. In this case | 33 # of version 3.1.3, the record may contain up to N fields. In this case |
| 33 # the M fields that are present are the values for the left-most M | 34 # the M fields that are present are the values for the left-most M |
| 34 # columns. The (N-M) rightmost columns contain NULL. | 35 # columns. The (N-M) rightmost columns contain NULL. |
| 35 # | 36 # |
| 36 # If any records in the database contain less fields than their table | 37 # If any records in the database contain less fields than their table |
| 37 # has columns, then the file-format meta value should be set to (at least) 2. | 38 # has columns, then the file-format meta value should be set to (at least) 2. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 65 set t [string map {' ''} $tbl] | 66 set t [string map {' ''} $tbl] |
| 66 dbat eval [subst { | 67 dbat eval [subst { |
| 67 PRAGMA writable_schema = 1; | 68 PRAGMA writable_schema = 1; |
| 68 UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table'; | 69 UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table'; |
| 69 PRAGMA writable_schema = 0; | 70 PRAGMA writable_schema = 0; |
| 70 }] | 71 }] |
| 71 dbat close | 72 dbat close |
| 72 set_file_format 2 | 73 set_file_format 2 |
| 73 } | 74 } |
| 74 | 75 |
| 76 # Create bogus application-defined functions for functions used |
| 77 # internally by ALTER TABLE, to ensure that ALTER TABLE falls back |
| 78 # to the built-in functions. |
| 79 # |
| 80 proc failing_app_func {args} {error "bad function"} |
| 81 do_test alter2-1.0 { |
| 82 db func substr failing_app_func |
| 83 db func like failing_app_func |
| 84 db func sqlite_rename_table failing_app_func |
| 85 db func sqlite_rename_trigger failing_app_func |
| 86 db func sqlite_rename_parent failing_app_func |
| 87 catchsql {SELECT substr('abcdefg',1,3)} |
| 88 } {1 {bad function}} |
| 89 |
| 90 |
| 75 #----------------------------------------------------------------------- | 91 #----------------------------------------------------------------------- |
| 76 # Some basic tests to make sure short rows are handled. | 92 # Some basic tests to make sure short rows are handled. |
| 77 # | 93 # |
| 78 do_test alter2-1.1 { | 94 do_test alter2-1.1 { |
| 79 execsql { | 95 execsql { |
| 80 CREATE TABLE abc(a, b); | 96 CREATE TABLE abc(a, b); |
| 81 INSERT INTO abc VALUES(1, 2); | 97 INSERT INTO abc VALUES(1, 2); |
| 82 INSERT INTO abc VALUES(3, 4); | 98 INSERT INTO abc VALUES(3, 4); |
| 83 INSERT INTO abc VALUES(5, 6); | 99 INSERT INTO abc VALUES(5, 6); |
| 84 } | 100 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 242 |
| 227 #--------------------------------------------------------------------- | 243 #--------------------------------------------------------------------- |
| 228 # Check that an error occurs if the database is upgraded to a file | 244 # Check that an error occurs if the database is upgraded to a file |
| 229 # format that SQLite does not support (in this case 5). Note: The | 245 # format that SQLite does not support (in this case 5). Note: The |
| 230 # file format is checked each time the schema is read, so changing the | 246 # file format is checked each time the schema is read, so changing the |
| 231 # file format requires incrementing the schema cookie. | 247 # file format requires incrementing the schema cookie. |
| 232 # | 248 # |
| 233 do_test alter2-4.1 { | 249 do_test alter2-4.1 { |
| 234 db close | 250 db close |
| 235 set_file_format 5 | 251 set_file_format 5 |
| 236 sqlite3 db test.db | 252 catch { sqlite3 db test.db } |
| 253 set {} {} |
| 237 } {} | 254 } {} |
| 238 do_test alter2-4.2 { | 255 do_test alter2-4.2 { |
| 239 # We have to run two queries here because the Tcl interface uses | 256 # We have to run two queries here because the Tcl interface uses |
| 240 # sqlite3_prepare_v2(). In this case, the first query encounters an | 257 # sqlite3_prepare_v2(). In this case, the first query encounters an |
| 241 # SQLITE_SCHEMA error. Then, when trying to recompile the statement, the | 258 # SQLITE_SCHEMA error. Then, when trying to recompile the statement, the |
| 242 # "unsupported file format" error is encountered. So the error code | 259 # "unsupported file format" error is encountered. So the error code |
| 243 # returned is SQLITE_SCHEMA, not SQLITE_ERROR as required by the following | 260 # returned is SQLITE_SCHEMA, not SQLITE_ERROR as required by the following |
| 244 # test case. | 261 # test case. |
| 245 # | 262 # |
| 246 # When the query is attempted a second time, the same error message is | 263 # When the query is attempted a second time, the same error message is |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 458 } |
| 442 } {a b d} | 459 } {a b d} |
| 443 do_test alter2-10.4 { | 460 do_test alter2-10.4 { |
| 444 execsql { | 461 execsql { |
| 445 SELECT count(b) FROM t2 WHERE b = X'ABCD'; | 462 SELECT count(b) FROM t2 WHERE b = X'ABCD'; |
| 446 } | 463 } |
| 447 } {3} | 464 } {3} |
| 448 } | 465 } |
| 449 | 466 |
| 450 finish_test | 467 finish_test |
| OLD | NEW |