]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
:-) (CVS 59)
authordrh <drh@noemail.net>
Tue, 6 Jun 2000 18:00:15 +0000 (18:00 +0000)
committerdrh <drh@noemail.net>
Tue, 6 Jun 2000 18:00:15 +0000 (18:00 +0000)
FossilOrigin-Name: a8fa6719d55b43f8d194aecfcae5af42d17742af

manifest
manifest.uuid
src/select.c
test/select3.test [new file with mode: 0644]

index f47dcae0fbb439e797c0cf93c61ce58195c0be3f..86ea7f9eee7c8378f7113257cd8d5d2cb5b8ffea 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C GROUP\sBY\sand\sHAVING\sinstalled\s(CVS\s58)
-D 2000-06-06T17:27:05
+C :-)\s(CVS\s59)
+D 2000-06-06T18:00:16
 F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
 F Makefile.in 17ba1ccf8d2d40c627796bba8f72952365d6d644
 F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
@@ -14,7 +14,7 @@ F src/expr.c d350fe393e1753aaa733a5d21f0830a23e547400
 F src/insert.c 5e69dd70c3f91cf5ec5090f39fd6cd8e135af9bf
 F src/main.c 93a7ad14bb5a82ad13ad59da23ef674a94b0c3d6
 F src/parse.y 210c888c052f3fde3def6ff1f402e4b4e8ba270d
-F src/select.c 77906ffaae962e49acc9a0c0c39cb710f06e56d8
+F src/select.c 5fd6fbd73f68f0baf1d53a73c4217f7862c37c0e
 F src/shell.c 5fa24c0bb678782ffe9070128e3e160674f297eb
 F src/sqlite.h 58da0a8590133777b741f9836beaef3d58f40268
 F src/sqliteInt.h 267f66d4a851e19adb0f9a3050a3acb62fc70cae
@@ -34,6 +34,7 @@ F test/index.test 9f99dca2d904b8de330863a978587f136e2df65a
 F test/insert.test b4c186ffa4b97a231643726f3bcee29815b24eaf
 F test/select1.test 2311bddd40bca257c27a7d141ed2a359bbdbc906
 F test/select2.test 3cd3c0f9d67e98b1b54af5853679b4a111224410
+F test/select3.test 73ae8c7b80c4e03a9c29d12f2ea1782e28b8e61f
 F test/subselect.test bf8b251a92fb091973c1c469ce499dc9648a41d5
 F test/table.test 85d6f410d127ec508c6640f02d7c40d218414e81
 F test/tester.tcl 44690d463c1dc83a4c76ccde07cc146a988600f6
@@ -49,7 +50,7 @@ F www/c_interface.tcl 8867d76ddd416d2fbd41e4cb3de8efa9cef105a5
 F www/changes.tcl 567cc6066d87460bdedff8e5bbc20f41ddaadf77
 F www/index.tcl f8189a7898f6d06307c34047b9d7e00860026e44
 F www/sqlite.tcl 2f933ce18cffd34a0a020a82435ab937137970fd
-P 54d198189b58366e4e40139102bc6de94ac55e18
-R dcd329d5daa579a072c3c6f09022ae9f
+P db88a0c2d4b5c5cd05e0172f061fc33763fe3829
+R d187390322c22a87c588288b385bc0fd
 U drh
-Z 6732a1b7035c88b38d7888f45d2d7142
+Z 7fd829b482d9369ef2332e8e548395ac
index 586e4fee4e18766710d135a21afe3d0f72d987f9..80e1332bd3849392298a5f0423929c3a6b2caedc 100644 (file)
@@ -1 +1 @@
-db88a0c2d4b5c5cd05e0172f061fc33763fe3829
\ No newline at end of file
+a8fa6719d55b43f8d194aecfcae5af42d17742af
\ No newline at end of file
index d3690ac9ef88d7d4f5f59654d080fb12ead74687..8d04d9dc09b9646dc0bd425693f798055d58da75 100644 (file)
@@ -24,7 +24,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements.
 **
-** $Id: select.c,v 1.11 2000/06/06 17:27:05 drh Exp $
+** $Id: select.c,v 1.12 2000/06/06 18:00:16 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -336,15 +336,15 @@ int sqliteSelect(
   }
   if( pHaving ){
     if( pGroupBy==0 ){
-      sqliteSetString(&pParse->zErrMsg, "a GROUP BY clause is required to "
-         "use HAVING", 0);
+      sqliteSetString(&pParse->zErrMsg, "a GROUP BY clause is required "
+         "before HAVING", 0);
       pParse->nErr++;
       return 1;
     }
     if( sqliteExprResolveIds(pParse, pTabList, pHaving) ){
       return 1;
     }
-    if( sqliteExprCheck(pParse, pHaving, 0, 0) ){
+    if( sqliteExprCheck(pParse, pHaving, isAgg, 0) ){
       return 1;
     }
   }
diff --git a/test/select3.test b/test/select3.test
new file mode 100644 (file)
index 0000000..ceb9c64
--- /dev/null
@@ -0,0 +1,114 @@
+# Copyright (c) 1999, 2000 D. Richard Hipp
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA  02111-1307, USA.
+#
+# Author contact information:
+#   drh@hwaci.com
+#   http://www.hwaci.com/drh/
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing aggregate functions and the
+# GROUP BY and HAVING clauses of SELECT statements.
+#
+# $Id: select3.test,v 1.1 2000/06/06 18:00:16 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Build some test data
+#
+do_test select3-1.0 {
+  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 "$i\t$j"
+  }
+  close $fd
+  execsql {
+    CREATE TABLE t1(n int, log int);
+    COPY t1 FROM 'data1.txt'
+  }
+  file delete data1.txt
+  execsql {SELECT DISTINCT log FROM t1 ORDER BY log}
+} {0 1 2 3 4 5}
+
+# Basic aggregate functions.
+#
+do_test select3-1.1 {
+  execsql {SELECT count(*) FROM t1}
+} {31}
+do_test select3-1.2 {
+  execsql {
+    SELECT min(n),min(log),max(n),max(log),sum(n),sum(log),avg(n),avg(log)
+    FROM t1
+  }
+} {1 0 31 5 496 124 16 4}
+do_test select3-1.3 {
+  execsql {SELECT max(n)/avg(n), max(log)/avg(log) FROM t1}
+} {1.9375 1.25}
+
+# Try some basic GROUP BY clauses
+#
+do_test select3-2.1 {
+  execsql {SELECT log, count(*) FROM t1 GROUP BY log ORDER BY log}
+} {0 1 1 1 2 2 3 4 4 8 5 15}
+do_test select3-2.2 {
+  execsql {SELECT log, min(n) FROM t1 GROUP BY log ORDER BY log}
+} {0 1 1 2 2 3 3 5 4 9 5 17}
+do_test select3-2.3 {
+  execsql {SELECT log, avg(n) FROM t1 GROUP BY log ORDER BY log}
+} {0 1 1 2 2 3.5 3 6.5 4 12.5 5 24}
+do_test select3-2.3 {
+  execsql {SELECT log, avg(n)+1 FROM t1 GROUP BY log ORDER BY log}
+} {0 2 1 3 2 4.5 3 7.5 4 13.5 5 25}
+do_test select3-2.4 {
+  execsql {SELECT log, avg(n)-min(n) FROM t1 GROUP BY log ORDER BY log}
+} {0 0 1 0 2 0.5 3 1.5 4 3.5 5 7}
+do_test select3-2.5 {
+  execsql {SELECT log*2+1, avg(n)-min(n) FROM t1 GROUP BY log ORDER BY log}
+} {1 0 3 0 5 0.5 7 1.5 9 3.5 11 7}
+
+# Cannot have a HAVING without a GROUP BY
+#
+do_test select3-3.1 {
+  set v [catch {execsql {SELECT log, count(*) FROM t1 HAVING log>=4}} msg]
+  lappend v $msg
+} {1 {a GROUP BY clause is required before HAVING}}
+
+# Toss in some HAVING clauses
+#
+do_test select3-4.1 {
+  execsql {SELECT log, count(*) FROM t1 GROUP BY log HAVING log>=4 ORDER BY log}
+} {4 8 5 15}
+do_test select3-4.2 {
+  execsql {
+    SELECT log, count(*) FROM t1 
+    GROUP BY log 
+    HAVING count(*)>=4 
+    ORDER BY log
+  }
+} {3 4 4 8 5 15}
+do_test select3-4.3 {
+  execsql {
+    SELECT log, count(*) FROM t1 
+    GROUP BY log 
+    HAVING count(*)>=4 
+    ORDER BY max(n)
+  }
+} {3 4 4 8 5 15}
+
+finish_test