limit.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # 2001 November 6
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. # This file implements regression tests for SQLite library. The
  12. # focus of this file is testing the LIMIT ... OFFSET ... clause
  13. # of SELECT statements.
  14. #
  15. # $Id: limit.test,v 1.3 2002/06/14 22:38:43 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # Build some test data
  19. #
  20. set fd [open data1.txt w]
  21. for {set i 1} {$i<=32} {incr i} {
  22. for {set j 0} {pow(2,$j)<$i} {incr j} {}
  23. puts $fd "[expr {32-$i}]\t[expr {10-$j}]"
  24. }
  25. close $fd
  26. execsql {
  27. CREATE TABLE t1(x int, y int);
  28. COPY t1 FROM 'data1.txt'
  29. }
  30. file delete data1.txt
  31. do_test limit-1.0 {
  32. execsql {SELECT count(*) FROM t1}
  33. } {32}
  34. do_test limit-1.1 {
  35. execsql {SELECT count(*) FROM t1 LIMIT 5}
  36. } {32}
  37. do_test limit-1.2 {
  38. execsql {SELECT x FROM t1 ORDER BY x LIMIT 5}
  39. } {0 1 2 3 4}
  40. do_test limit-1.3 {
  41. execsql {SELECT x FROM t1 ORDER BY x LIMIT 5 OFFSET 5}
  42. } {5 6 7 8 9}
  43. do_test limit-1.4 {
  44. execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 30}
  45. } {30 31}
  46. do_test limit-1.5 {
  47. execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 50}
  48. } {}
  49. do_test limit-1.6 {
  50. execsql {SELECT * FROM t1 AS a, t1 AS b ORDER BY a.x, b.x LIMIT 5}
  51. } {0 5 0 5 0 5 1 5 0 5 2 5 0 5 3 5 0 5 4 5}
  52. do_test limit-1.7 {
  53. execsql {SELECT * FROM t1 AS a, t1 AS b ORDER BY a.x, b.x LIMIT 5 OFFSET 32}
  54. } {1 5 0 5 1 5 1 5 1 5 2 5 1 5 3 5 1 5 4 5}
  55. do_test limit-2.1 {
  56. execsql {
  57. CREATE VIEW v1 AS SELECT * FROM t1 LIMIT 2;
  58. SELECT count(*) FROM (SELECT * FROM v1);
  59. }
  60. } 2
  61. do_test limit-2.2 {
  62. execsql {
  63. CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 2;
  64. SELECT count(*) FROM t2;
  65. }
  66. } 2
  67. do_test limit-2.3 {
  68. execsql {
  69. SELECT count(*) FROM t1 WHERE rowid IN (SELECT rowid FROM t1 LIMIT 2);
  70. }
  71. } 2
  72. finish_test