Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

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

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 magic ROWID column that is 12 # focus of this file is testing the magic ROWID column that is
13 # found on all tables. 13 # found on all tables.
14 # 14 #
15 # $Id: rowid.test,v 1.21 2009/06/26 15:14:55 drh Exp $ 15 # EVIDENCE-OF: R-36924-43758 By default, every row in SQLite has a
16 # special column, usually called the "rowid", that uniquely identifies
17 # that row within the table.
16 18
17 set testdir [file dirname $argv0] 19 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl 20 source $testdir/tester.tcl
19 21
20 # Basic ROWID functionality tests. 22 # Basic ROWID functionality tests.
21 # 23 #
22 do_test rowid-1.1 { 24 do_test rowid-1.1 {
23 execsql { 25 execsql {
24 CREATE TABLE t1(x int, y int); 26 CREATE TABLE t1(x int, y int);
25 INSERT INTO t1 VALUES(1,2); 27 INSERT INTO t1 VALUES(1,2);
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 do_test rowid-11.3 { 652 do_test rowid-11.3 {
651 execsql {SELECT rowid, a FROM t5 WHERE rowid<'abc'} 653 execsql {SELECT rowid, a FROM t5 WHERE rowid<'abc'}
652 } {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8} 654 } {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}
653 do_test rowid-11.4 { 655 do_test rowid-11.4 {
654 execsql {SELECT rowid, a FROM t5 WHERE rowid<='abc'} 656 execsql {SELECT rowid, a FROM t5 WHERE rowid<='abc'}
655 } {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8} 657 } {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}
656 658
657 # Test the automatic generation of rowids when the table already contains 659 # Test the automatic generation of rowids when the table already contains
658 # a rowid with the maximum value. 660 # a rowid with the maximum value.
659 # 661 #
660 # Once the the maximum rowid is taken, rowids are normally chosen at 662 # Once the maximum rowid is taken, rowids are normally chosen at
661 # random. By by reseting the random number generator, we can cause 663 # random. By by reseting the random number generator, we can cause
662 # the rowid guessing loop to collide with prior rowids, and test the 664 # the rowid guessing loop to collide with prior rowids, and test the
663 # loop out to its limit of 100 iterations. After 100 collisions, the 665 # loop out to its limit of 100 iterations. After 100 collisions, the
664 # rowid guesser gives up and reports SQLITE_FULL. 666 # rowid guesser gives up and reports SQLITE_FULL.
665 # 667 #
666 do_test rowid-12.1 { 668 do_test rowid-12.1 {
667 execsql { 669 execsql {
668 CREATE TABLE t7(x INTEGER PRIMARY KEY, y); 670 CREATE TABLE t7(x INTEGER PRIMARY KEY, y);
669 CREATE TABLE t7temp(a INTEGER PRIMARY KEY); 671 CREATE TABLE t7temp(a INTEGER PRIMARY KEY);
670 INSERT INTO t7 VALUES(9223372036854775807,'a'); 672 INSERT INTO t7 VALUES(9223372036854775807,'a');
671 SELECT y FROM t7; 673 SELECT y FROM t7;
672 } 674 }
673 } {a} 675 } {a}
674 do_test rowid-12.2 { 676 do_test rowid-12.2 {
675 db close 677 db close
676 sqlite3 db test.db 678 sqlite3 db test.db
677 save_prng_state 679 save_prng_state
678 execsql { 680 execsql {
679 INSERT INTO t7 VALUES(NULL,'b'); 681 INSERT INTO t7 VALUES(NULL,'b');
680 SELECT x, y FROM t7; 682 SELECT x, y FROM t7 ORDER BY x;
681 } 683 }
682 } {1 b 9223372036854775807 a} 684 } {/\d+ b 9223372036854775807 a/}
683 execsql {INSERT INTO t7 VALUES(2,'y');} 685 execsql {INSERT INTO t7 VALUES(2,'y');}
684 for {set i 1} {$i<100} {incr i} { 686 for {set i 1} {$i<100} {incr i} {
685 do_test rowid-12.3.$i { 687 do_test rowid-12.3.$i {
686 db eval {DELETE FROM t7temp; INSERT INTO t7temp VALUES(1);} 688 db eval {DELETE FROM t7temp; INSERT INTO t7temp VALUES(1);}
687 restore_prng_state 689 restore_prng_state
688 execsql { 690 execsql {
689 INSERT INTO t7 VALUES(NULL,'x'); 691 INSERT INTO t7 VALUES(NULL,'x');
690 SELECT count(*) FROM t7 WHERE y=='x'; 692 SELECT count(*) FROM t7 WHERE y=='x';
691 } 693 }
692 } $i 694 } $i
693 } 695 }
694 do_test rowid-12.4 { 696 do_test rowid-12.4 {
695 db eval {DELETE FROM t7temp; INSERT INTO t7temp VALUES(1);} 697 db eval {DELETE FROM t7temp; INSERT INTO t7temp VALUES(1);}
696 restore_prng_state 698 restore_prng_state
697 catchsql { 699 catchsql {
698 INSERT INTO t7 VALUES(NULL,'x'); 700 INSERT INTO t7 VALUES(NULL,'x');
699 } 701 }
700 } {1 {database or disk is full}} 702 } {1 {database or disk is full}}
701 703
704 # INSERTs that happen inside of nested function calls are recorded
705 # by last_insert_rowid.
706 #
707 proc rowid_addrow_func {n} {
708 db eval {INSERT INTO t13(rowid,x) VALUES($n,$n*$n)}
709 return [db last_insert_rowid]
710 }
711 db function addrow rowid_addrow_func
712 do_execsql_test rowid-13.1 {
713 CREATE TABLE t13(x);
714 INSERT INTO t13(rowid,x) VALUES(1234,5);
715 SELECT rowid, x, addrow(rowid+1000), '|' FROM t13 LIMIT 3;
716 SELECT last_insert_rowid();
717 } {1234 5 2234 | 2234 4990756 3234 | 3234 10458756 4234 | 4234}
702 718
703 finish_test 719 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698