drh | 191b690 | 2000-06-08 11:13:01 +0000 | [diff] [blame^] | 1 | # Copyright (c) 1999, 2000 D. Richard Hipp |
| 2 | # |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public |
| 5 | # License as published by the Free Software Foundation; either |
| 6 | # version 2 of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | # General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public |
| 14 | # License along with this library; if not, write to the |
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | # Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | # Author contact information: |
| 19 | # drh@hwaci.com |
| 20 | # http://www.hwaci.com/drh/ |
| 21 | # |
| 22 | #*********************************************************************** |
| 23 | # This file implements regression tests for SQLite library. The |
| 24 | # focus of this file is testing aggregate functions and the |
| 25 | # GROUP BY and HAVING clauses of SELECT statements. |
| 26 | # |
| 27 | # $Id: select5.test,v 1.1 2000/06/08 11:13:02 drh Exp $ |
| 28 | |
| 29 | set testdir [file dirname $argv0] |
| 30 | source $testdir/tester.tcl |
| 31 | |
| 32 | # Build some test data |
| 33 | # |
| 34 | set fd [open data1.txt w] |
| 35 | for {set i 1} {$i<32} {incr i} { |
| 36 | for {set j 0} {pow(2,$j)<$i} {incr j} {} |
| 37 | puts $fd "[expr {32-$i}]\t[expr {10-$j}]" |
| 38 | } |
| 39 | close $fd |
| 40 | execsql { |
| 41 | CREATE TABLE t1(x int, y int); |
| 42 | COPY t1 FROM 'data1.txt' |
| 43 | } |
| 44 | file delete data1.txt |
| 45 | |
| 46 | do_test select5-1.0 { |
| 47 | execsql {SELECT DISTINCT y FROM t1 ORDER BY y} |
| 48 | } {5 6 7 8 9 10} |
| 49 | |
| 50 | # Sort by an aggregate function. |
| 51 | # |
| 52 | do_test select5-1.1 { |
| 53 | execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY y} |
| 54 | } {5 15 6 8 7 4 8 2 9 1 10 1} |
| 55 | do_test select5-1.2 { |
| 56 | execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY count(*), y} |
| 57 | } {9 1 10 1 8 2 7 4 6 8 5 15} |
| 58 | |
| 59 | finish_test |