a9e99aee95
FossilOrigin-Name: 310ac4fbaf0ed63f98bfacb55259960be03b0c8b
121 lines
3.5 KiB
Plaintext
121 lines
3.5 KiB
Plaintext
# 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.5 2002/08/13 23:02:58 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
|
|
|
|
do_test limit-3.1 {
|
|
execsql {
|
|
SELECT z FROM (SELECT y*10+x AS z FROM t1 ORDER BY x LIMIT 10)
|
|
ORDER BY z LIMIT 5;
|
|
}
|
|
} {50 51 52 53 54}
|
|
|
|
do_test limit-4.1 {
|
|
execsql {
|
|
BEGIN;
|
|
CREATE TABLE t3 AS SELECT x FROM t1 ORDER BY x LIMIT 10 OFFSET 1;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
|
|
END;
|
|
SELECT count(*) FROM t3;
|
|
}
|
|
} {10240}
|
|
do_test limit-4.2 {
|
|
execsql {
|
|
SELECT x FROM t3 LIMIT 2 OFFSET 10000
|
|
}
|
|
} {10001 10002}
|
|
do_test limit-4.3 {
|
|
execsql {
|
|
CREATE TABLE t4 AS SELECT x,
|
|
'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
|
|
'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
|
|
'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
|
|
'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
|
|
'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x AS y
|
|
FROM t3 LIMIT 1000;
|
|
SELECT x FROM t4 ORDER BY y DESC LIMIT 1 OFFSET 999;
|
|
}
|
|
} {1000}
|
|
|
|
finish_test
|