OLD | NEW |
1 # 2006 November 08 | 1 # 2006 November 08 |
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. | 11 # This file implements regression tests for SQLite library. |
12 # | 12 # |
13 # This is a copy of the capi3.test file that has been adapted to | 13 # This is a copy of the capi3.test file that has been adapted to |
14 # test the new sqlite3_prepare_v2 interface. | 14 # test the new sqlite3_prepare_v2 interface. |
15 # | 15 # |
16 # $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 danielk1977 Exp $ | 16 # $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 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 # Do not use a codec for tests in this file, as the database file is |
| 23 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 24 # |
| 25 do_not_use_codec |
| 26 |
22 # Return the UTF-16 representation of the supplied UTF-8 string $str. | 27 # Return the UTF-16 representation of the supplied UTF-8 string $str. |
23 # If $nt is true, append two 0x00 bytes as a nul terminator. | 28 # If $nt is true, append two 0x00 bytes as a nul terminator. |
24 proc utf16 {str {nt 1}} { | 29 proc utf16 {str {nt 1}} { |
25 set r [encoding convertto unicode $str] | 30 set r [encoding convertto unicode $str] |
26 if {$nt} { | 31 if {$nt} { |
27 append r "\x00\x00" | 32 append r "\x00\x00" |
28 } | 33 } |
29 return $r | 34 return $r |
30 } | 35 } |
31 | 36 |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 sqlite3_finalize $STMT | 604 sqlite3_finalize $STMT |
600 } SQLITE_OK | 605 } SQLITE_OK |
601 | 606 |
602 | 607 |
603 set ::ENC [execsql {pragma encoding}] | 608 set ::ENC [execsql {pragma encoding}] |
604 db close | 609 db close |
605 | 610 |
606 do_test capi3c-6.0 { | 611 do_test capi3c-6.0 { |
607 sqlite3 db test.db | 612 sqlite3 db test.db |
608 set DB [sqlite3_connection_pointer db] | 613 set DB [sqlite3_connection_pointer db] |
609 sqlite3_key $DB xyzzy | 614 if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy } |
610 set sql {SELECT a FROM t1 order by rowid} | 615 set sql {SELECT a FROM t1 order by rowid} |
611 set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] | 616 set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] |
612 expr 0 | 617 expr 0 |
613 } {0} | 618 } {0} |
614 do_test capi3c-6.1 { | 619 do_test capi3c-6.1 { |
615 db cache flush | 620 db cache flush |
616 sqlite3_close $DB | 621 sqlite3_close $DB |
617 } {SQLITE_BUSY} | 622 } {SQLITE_BUSY} |
618 do_test capi3c-6.2 { | 623 do_test capi3c-6.2 { |
619 sqlite3_step $STMT | 624 sqlite3_step $STMT |
(...skipping 26 matching lines...) Expand all Loading... |
646 proc get_file_format {{fname test.db}} { | 651 proc get_file_format {{fname test.db}} { |
647 return [hexio_get_int [hexio_read $fname 44 4]] | 652 return [hexio_get_int [hexio_read $fname 44 4]] |
648 } | 653 } |
649 | 654 |
650 if {![sqlite3 -has-codec]} { | 655 if {![sqlite3 -has-codec]} { |
651 # Test what happens when the library encounters a newer file format. | 656 # Test what happens when the library encounters a newer file format. |
652 do_test capi3c-7.1 { | 657 do_test capi3c-7.1 { |
653 set_file_format 5 | 658 set_file_format 5 |
654 } {} | 659 } {} |
655 do_test capi3c-7.2 { | 660 do_test capi3c-7.2 { |
656 sqlite3 db test.db | 661 catch { sqlite3 db test.db } |
657 catchsql { | 662 catchsql { |
658 SELECT * FROM sqlite_master; | 663 SELECT * FROM sqlite_master; |
659 } | 664 } |
660 } {1 {unsupported file format}} | 665 } {1 {unsupported file format}} |
661 db close | 666 db close |
662 } | 667 } |
663 | 668 |
664 if {![sqlite3 -has-codec]} { | 669 if {![sqlite3 -has-codec]} { |
665 # Now test that the library correctly handles bogus entries in the | 670 # Now test that the library correctly handles bogus entries in the |
666 # sqlite_master table (schema corruption). | 671 # sqlite_master table (schema corruption). |
667 do_test capi3c-8.1 { | 672 do_test capi3c-8.1 { |
668 file delete -force test.db test.db-journal | 673 file delete -force test.db test.db-journal |
669 sqlite3 db test.db | 674 sqlite3 db test.db |
670 execsql { | 675 execsql { |
671 CREATE TABLE t1(a); | 676 CREATE TABLE t1(a); |
672 } | 677 } |
673 db close | 678 db close |
674 } {} | 679 } {} |
675 do_test capi3c-8.2 { | 680 do_test capi3c-8.2 { |
676 sqlite3 db test.db | 681 sqlite3 db test.db |
677 execsql { | 682 execsql { |
678 PRAGMA writable_schema=ON; | 683 PRAGMA writable_schema=ON; |
679 INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL); | 684 INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL); |
680 } | 685 } |
681 db close | 686 db close |
682 } {} | 687 } {} |
683 do_test capi3c-8.3 { | 688 do_test capi3c-8.3 { |
684 sqlite3 db test.db | 689 catch { sqlite3 db test.db } |
685 catchsql { | 690 catchsql { |
686 SELECT * FROM sqlite_master; | 691 SELECT * FROM sqlite_master; |
687 } | 692 } |
688 } {1 {malformed database schema (?)}} | 693 } {1 {malformed database schema (?)}} |
689 do_test capi3c-8.4 { | 694 do_test capi3c-8.4 { |
690 # Build a 5-field row record. The first field is a string 'table', and | 695 # Build a 5-field row record. The first field is a string 'table', and |
691 # subsequent fields are all NULL. | 696 # subsequent fields are all NULL. |
692 db close | 697 db close |
693 file delete -force test.db test.db-journal | 698 file delete -force test.db test.db-journal |
694 sqlite3 db test.db | 699 sqlite3 db test.db |
695 execsql { | 700 execsql { |
696 CREATE TABLE t1(a); | 701 CREATE TABLE t1(a); |
697 PRAGMA writable_schema=ON; | 702 PRAGMA writable_schema=ON; |
698 INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL); | 703 INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL); |
699 } | 704 } |
700 db close | 705 db close |
701 } {}; | 706 } {}; |
702 do_test capi3c-8.5 { | 707 do_test capi3c-8.5 { |
703 sqlite3 db test.db | 708 catch { sqlite3 db test.db } |
704 catchsql { | 709 catchsql { |
705 SELECT * FROM sqlite_master; | 710 SELECT * FROM sqlite_master; |
706 } | 711 } |
707 } {1 {malformed database schema (?)}} | 712 } {1 {malformed database schema (?)}} |
708 db close | 713 db close |
709 } | 714 } |
710 file delete -force test.db | 715 file delete -force test.db |
711 file delete -force test.db-journal | 716 file delete -force test.db-journal |
712 | 717 |
713 | 718 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 do_test capi3c-19.2 { | 1174 do_test capi3c-19.2 { |
1170 sqlite3_column_int $STMT 0 | 1175 sqlite3_column_int $STMT 0 |
1171 } 1 | 1176 } 1 |
1172 do_test capi3c-19.3 { | 1177 do_test capi3c-19.3 { |
1173 sqlite3_step $STMT | 1178 sqlite3_step $STMT |
1174 } SQLITE_DONE | 1179 } SQLITE_DONE |
1175 do_test capi3c-19.4 { | 1180 do_test capi3c-19.4 { |
1176 sqlite3_reset $STMT | 1181 sqlite3_reset $STMT |
1177 db eval {DROP TABLE t3} | 1182 db eval {DROP TABLE t3} |
1178 sqlite3_step $STMT | 1183 sqlite3_step $STMT |
1179 } SQLITE_SCHEMA | 1184 } SQLITE_ERROR |
1180 do_test capi3c-19.4.1 { | 1185 do_test capi3c-19.4.1 { |
1181 sqlite3_errmsg $DB | 1186 sqlite3_errmsg $DB |
1182 } {no such table: t3} | 1187 } {no such table: t3} |
1183 ifcapable deprecated { | 1188 ifcapable deprecated { |
1184 do_test capi3c-19.4.2 { | 1189 do_test capi3c-19.4.2 { |
1185 sqlite3_expired $STMT | 1190 sqlite3_expired $STMT |
1186 } 1 | 1191 } 1 |
1187 } | 1192 } |
1188 do_test capi3c-19.4.3 { | 1193 do_test capi3c-19.4.3 { |
1189 sqlite3_errmsg $DB | 1194 sqlite3_errmsg $DB |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 decltype { | 1354 decltype { |
1350 SELECT (SELECT x FROM (SELECT c AS x)) | 1355 SELECT (SELECT x FROM (SELECT c AS x)) |
1351 FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b | 1356 FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b |
1352 } | 1357 } |
1353 } {DATETIME} | 1358 } {DATETIME} |
1354 do_test capi3c-24.3 { | 1359 do_test capi3c-24.3 { |
1355 decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5} | 1360 decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5} |
1356 } {INTEGER} | 1361 } {INTEGER} |
1357 | 1362 |
1358 finish_test | 1363 finish_test |
OLD | NEW |