123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- # 2001 November 6
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library. The
- # focus of this file is testing the LIMIT ... OFFSET ... clause
- # of SELECT statements.
- #
- # $Id: limit.test,v 1.3 2002/06/14 22:38:43 drh Exp $
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- # Build some test data
- #
- set fd [open data1.txt w]
- for {set i 1} {$i<=32} {incr i} {
- for {set j 0} {pow(2,$j)<$i} {incr j} {}
- puts $fd "[expr {32-$i}]\t[expr {10-$j}]"
- }
- close $fd
- execsql {
- CREATE TABLE t1(x int, y int);
- COPY t1 FROM 'data1.txt'
- }
- file delete data1.txt
- do_test limit-1.0 {
- execsql {SELECT count(*) FROM t1}
- } {32}
- do_test limit-1.1 {
- execsql {SELECT count(*) FROM t1 LIMIT 5}
- } {32}
- do_test limit-1.2 {
- execsql {SELECT x FROM t1 ORDER BY x LIMIT 5}
- } {0 1 2 3 4}
- do_test limit-1.3 {
- execsql {SELECT x FROM t1 ORDER BY x LIMIT 5 OFFSET 5}
- } {5 6 7 8 9}
- do_test limit-1.4 {
- execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 30}
- } {30 31}
- do_test limit-1.5 {
- execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 50}
- } {}
- do_test limit-1.6 {
- execsql {SELECT * FROM t1 AS a, t1 AS b ORDER BY a.x, b.x LIMIT 5}
- } {0 5 0 5 0 5 1 5 0 5 2 5 0 5 3 5 0 5 4 5}
- do_test limit-1.7 {
- execsql {SELECT * FROM t1 AS a, t1 AS b ORDER BY a.x, b.x LIMIT 5 OFFSET 32}
- } {1 5 0 5 1 5 1 5 1 5 2 5 1 5 3 5 1 5 4 5}
- do_test limit-2.1 {
- execsql {
- CREATE VIEW v1 AS SELECT * FROM t1 LIMIT 2;
- SELECT count(*) FROM (SELECT * FROM v1);
- }
- } 2
- do_test limit-2.2 {
- execsql {
- CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 2;
- SELECT count(*) FROM t2;
- }
- } 2
- do_test limit-2.3 {
- execsql {
- SELECT count(*) FROM t1 WHERE rowid IN (SELECT rowid FROM t1 LIMIT 2);
- }
- } 2
- finish_test
|