1
0

select8.test 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # 2001 September 15
  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.
  12. #
  13. # The focus of this file is testing that LIMIT and OFFSET work for
  14. # unusual combinations SELECT statements.
  15. #
  16. # $Id: select8.test,v 1.1 2008/01/12 12:48:09 drh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. execsql {
  20. CREATE TABLE songs(songid, artist, timesplayed);
  21. INSERT INTO songs VALUES(1,'one',1);
  22. INSERT INTO songs VALUES(2,'one',2);
  23. INSERT INTO songs VALUES(3,'two',3);
  24. INSERT INTO songs VALUES(4,'three',5);
  25. INSERT INTO songs VALUES(5,'one',7);
  26. INSERT INTO songs VALUES(6,'two',11);
  27. }
  28. set result [execsql {
  29. SELECT DISTINCT artist,sum(timesplayed) AS total
  30. FROM songs
  31. GROUP BY LOWER(artist)
  32. }]
  33. puts result=$result
  34. do_test select8-1.1 {
  35. execsql {
  36. SELECT DISTINCT artist,sum(timesplayed) AS total
  37. FROM songs
  38. GROUP BY LOWER(artist)
  39. LIMIT 1 OFFSET 1
  40. }
  41. } [lrange $result 2 3]
  42. do_test select8-1.2 {
  43. execsql {
  44. SELECT DISTINCT artist,sum(timesplayed) AS total
  45. FROM songs
  46. GROUP BY LOWER(artist)
  47. LIMIT 2 OFFSET 1
  48. }
  49. } [lrange $result 2 5]
  50. do_test select8-1.3 {
  51. execsql {
  52. SELECT DISTINCT artist,sum(timesplayed) AS total
  53. FROM songs
  54. GROUP BY LOWER(artist)
  55. LIMIT -1 OFFSET 2
  56. }
  57. } [lrange $result 4 end]
  58. finish_test