Chromium Code Reviews

Side by Side Diff: third_party/sqlite/src/test/table.test

Issue 949043002: Add //third_party/sqlite to dirs_to_snapshot, remove net_sql.patch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « third_party/sqlite/src/test/sysfault.test ('k') | third_party/sqlite/src/test/tableopts.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2001 September 15 1 # 2001 September 15
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 file is testing the CREATE TABLE statement. 12 # focus of this file is testing the CREATE TABLE statement.
13 # 13 #
14 # $Id: table.test,v 1.53 2009/06/05 17:09:12 drh Exp $
15 14
16 set testdir [file dirname $argv0] 15 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl 16 source $testdir/tester.tcl
18 17
19 # Create a basic table and verify it is added to sqlite_master 18 # Create a basic table and verify it is added to sqlite_master
20 # 19 #
21 do_test table-1.1 { 20 do_test table-1.1 {
22 execsql { 21 execsql {
23 CREATE TABLE test1 ( 22 CREATE TABLE test1 (
24 one varchar(10), 23 one varchar(10),
(...skipping 228 matching lines...)
253 do_test table-5.1.2 { 252 do_test table-5.1.2 {
254 catchsql {DROP TABLE IF EXISTS test009} 253 catchsql {DROP TABLE IF EXISTS test009}
255 } {0 {}} 254 } {0 {}}
256 255
257 # Try to drop sqlite_master 256 # Try to drop sqlite_master
258 # 257 #
259 do_test table-5.2 { 258 do_test table-5.2 {
260 catchsql {DROP TABLE IF EXISTS sqlite_master} 259 catchsql {DROP TABLE IF EXISTS sqlite_master}
261 } {1 {table sqlite_master may not be dropped}} 260 } {1 {table sqlite_master may not be dropped}}
262 261
262 # Dropping sqlite_statN tables is OK.
263 #
264 do_test table-5.2.1 {
265 db eval {
266 ANALYZE;
267 DROP TABLE IF EXISTS sqlite_stat1;
268 DROP TABLE IF EXISTS sqlite_stat2;
269 DROP TABLE IF EXISTS sqlite_stat3;
270 DROP TABLE IF EXISTS sqlite_stat4;
271 SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_stat*';
272 }
273 } {}
274
263 # Make sure an EXPLAIN does not really create a new table 275 # Make sure an EXPLAIN does not really create a new table
264 # 276 #
265 do_test table-5.3 { 277 do_test table-5.3 {
266 ifcapable {explain} { 278 ifcapable {explain} {
267 execsql {EXPLAIN CREATE TABLE test1(f1 int)} 279 execsql {EXPLAIN CREATE TABLE test1(f1 int)}
268 } 280 }
269 execsql {SELECT name FROM sqlite_master WHERE type!='meta'} 281 execsql {SELECT name FROM sqlite_master WHERE type!='meta'}
270 } {} 282 } {}
271 283
272 # Make sure an EXPLAIN does not really drop an existing table 284 # Make sure an EXPLAIN does not really drop an existing table
(...skipping 171 matching lines...)
444 } {1 {duplicate column name: a}} 456 } {1 {duplicate column name: a}}
445 457
446 # Check the foreign key syntax. 458 # Check the foreign key syntax.
447 # 459 #
448 ifcapable {foreignkey} { 460 ifcapable {foreignkey} {
449 do_test table-10.1 { 461 do_test table-10.1 {
450 catchsql { 462 catchsql {
451 CREATE TABLE t6(a REFERENCES t4(a) NOT NULL); 463 CREATE TABLE t6(a REFERENCES t4(a) NOT NULL);
452 INSERT INTO t6 VALUES(NULL); 464 INSERT INTO t6 VALUES(NULL);
453 } 465 }
454 } {1 {t6.a may not be NULL}} 466 } {1 {NOT NULL constraint failed: t6.a}}
455 do_test table-10.2 { 467 do_test table-10.2 {
456 catchsql { 468 catchsql {
457 DROP TABLE t6; 469 DROP TABLE t6;
458 CREATE TABLE t6(a REFERENCES t4(a) MATCH PARTIAL); 470 CREATE TABLE t6(a REFERENCES t4(a) MATCH PARTIAL);
459 } 471 }
460 } {0 {}} 472 } {0 {}}
461 do_test table-10.3 { 473 do_test table-10.3 {
462 catchsql { 474 catchsql {
463 DROP TABLE t6; 475 DROP TABLE t6;
464 CREATE TABLE t6(a REFERENCES t4 MATCH FULL ON DELETE SET NULL NOT NULL); 476 CREATE TABLE t6(a REFERENCES t4 MATCH FULL ON DELETE SET NULL NOT NULL);
(...skipping 195 matching lines...)
660 } 672 }
661 } msg 673 } msg
662 ] 674 ]
663 set result [list $rc $msg] 675 set result [list $rc $msg]
664 } {1 {database table is locked}} 676 } {1 {database table is locked}}
665 677
666 ifcapable attach { 678 ifcapable attach {
667 # Now attach a database and ensure that a table can be created in the 679 # Now attach a database and ensure that a table can be created in the
668 # attached database whilst in a callback from a query on the main database. 680 # attached database whilst in a callback from a query on the main database.
669 do_test table-14.3 { 681 do_test table-14.3 {
670 file delete -force test2.db 682 forcedelete test2.db
671 file delete -force test2.db-journal 683 forcedelete test2.db-journal
672 execsql { 684 execsql {
673 ATTACH 'test2.db' as aux; 685 ATTACH 'test2.db' as aux;
674 } 686 }
675 db eval {SELECT * FROM tablet8 LIMIT 1} {} { 687 db eval {SELECT * FROM tablet8 LIMIT 1} {} {
676 db eval {CREATE TABLE aux.t1(a, b, c)} 688 db eval {CREATE TABLE aux.t1(a, b, c)}
677 } 689 }
678 } {} 690 } {}
679 691
680 # On the other hand, it should be impossible to drop a table when any VMs 692 # On the other hand, it should be impossible to drop a table when any VMs
681 # are active. This is because VerifyCookie instructions may have already 693 # are active. This is because VerifyCookie instructions may have already
(...skipping 24 matching lines...)
706 execsql {COMMIT} 718 execsql {COMMIT}
707 } {} 719 } {}
708 do_test table-15.2 { 720 do_test table-15.2 {
709 execsql {BEGIN} 721 execsql {BEGIN}
710 for {set i 0} {$i<2000} {incr i} { 722 for {set i 0} {$i<2000} {incr i} {
711 execsql "DROP TABLE tbl$i" 723 execsql "DROP TABLE tbl$i"
712 } 724 }
713 execsql {COMMIT} 725 execsql {COMMIT}
714 } {} 726 } {}
715 727
728 # Ticket 3a88d85f36704eebe134f7f48aebf00cd6438c1a (2014-08-05)
729 # The following SQL script segfaults while running the INSERT statement:
730 #
731 # CREATE TABLE t1(x DEFAULT(max(1)));
732 # INSERT INTO t1(rowid) VALUES(1);
733 #
734 # The problem appears to be the use of an aggregate function as part of
735 # the default value for a column. This problem has been in the code since
736 # at least 2006-01-01 and probably before that. This problem was detected
737 # and reported on the sqlite-users@sqlite.org mailing list by Zsbán Ambrus.
738 #
739 do_execsql_test table-16.1 {
740 CREATE TABLE t16(x DEFAULT(max(1)));
741 INSERT INTO t16(x) VALUES(123);
742 SELECT rowid, x FROM t16;
743 } {1 123}
744 do_catchsql_test table-16.2 {
745 INSERT INTO t16(rowid) VALUES(4);
746 } {1 {unknown function: max()}}
747 do_execsql_test table-16.3 {
748 DROP TABLE t16;
749 CREATE TABLE t16(x DEFAULT(abs(1)));
750 INSERT INTO t16(rowid) VALUES(4);
751 SELECT rowid, x FROM t16;
752 } {4 1}
753 do_catchsql_test table-16.4 {
754 DROP TABLE t16;
755 CREATE TABLE t16(x DEFAULT(avg(1)));
756 INSERT INTO t16(rowid) VALUES(123);
757 SELECT rowid, x FROM t16;
758 } {1 {unknown function: avg()}}
759 do_catchsql_test table-16.5 {
760 DROP TABLE t16;
761 CREATE TABLE t16(x DEFAULT(count()));
762 INSERT INTO t16(rowid) VALUES(123);
763 SELECT rowid, x FROM t16;
764 } {1 {unknown function: count()}}
765 do_catchsql_test table-16.6 {
766 DROP TABLE t16;
767 CREATE TABLE t16(x DEFAULT(group_concat('x',',')));
768 INSERT INTO t16(rowid) VALUES(123);
769 SELECT rowid, x FROM t16;
770 } {1 {unknown function: group_concat()}}
771 do_catchsql_test table-16.7 {
772 INSERT INTO t16 DEFAULT VALUES;
773 } {1 {unknown function: group_concat()}}
774
775 # Ticket [https://www.sqlite.org/src/info/094d39a4c95ee4abbc417f04214617675ba15c 63]
776 # describes a assertion fault that occurs on a CREATE TABLE .. AS SELECT stateme nt.
777 # the following test verifies that the problem has been fixed.
778 #
779 do_execsql_test table-17.1 {
780 DROP TABLE IF EXISTS t1;
781 CREATE TABLE t1(a TEXT);
782 INSERT INTO t1(a) VALUES(1),(2);
783 DROP TABLE IF EXISTS t2;
784 CREATE TABLE t2(x TEXT, y TEXT);
785 INSERT INTO t2(x,y) VALUES(3,4);
786 DROP TABLE IF EXISTS t3;
787 CREATE TABLE t3 AS
788 SELECT a AS p, coalesce(y,a) AS q FROM t1 LEFT JOIN t2 ON a=x;
789 SELECT p, q, '|' FROM t3 ORDER BY p;
790 } {1 1 | 2 2 |}
791
716 finish_test 792 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/sysfault.test ('k') | third_party/sqlite/src/test/tableopts.test » ('j') | no next file with comments »

Powered by Google App Engine