/ Check-in [305b043f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment::-) (CVS 79)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 305b043f4f71278d6d2c32e6e457f63efefae20d
User & Date: drh 2000-06-08 11:25:01
Context
2000-06-08
13:36
remove all memory leaks (CVS 80) check-in: bf98cf82 user: drh tags: trunk
11:25
:-) (CVS 79) check-in: 305b043f user: drh tags: trunk
11:13
:-) (CVS 78) check-in: 923c14fe user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846

847
848
849
850
851
852
853
** Author contact information:
**   drh@hwaci.com
**   http://www.hwaci.com/drh/
**
*************************************************************************
** This file contains C code routines used for processing expressions
**
** $Id: expr.c,v 1.11 2000/06/07 23:51:50 drh Exp $
*/
#include "sqliteInt.h"

/*
** Walk an expression tree.  Return 1 if the expression is constant
** and 0 if it involves variables.
*/
................................................................................
  switch( pExpr->op ){
    case TK_FIELD: {
      aAgg = pParse->aAgg;
      for(i=0; i<pParse->nAgg; i++){
        if( aAgg[i].isAgg ) continue;
        if( aAgg[i].pExpr->iTable==pExpr->iTable
         && aAgg[i].pExpr->iField==pExpr->iField ){
          pExpr->iAgg = i;
          break;
        }
      }
      if( i>=pParse->nAgg ){
        i = appendAggInfo(pParse);
        if( i<0 ) return 1;
        pParse->aAgg[i].isAgg = 0;
        pParse->aAgg[i].pExpr = pExpr;
      }

      break;
    }
    case TK_AGG_FUNCTION: {
      if( pExpr->iField==FN_Count || pExpr->iField==FN_Avg ){
        if( pParse->iAggCount>=0 ){
          i = pParse->iAggCount;
        }else{







|







 







<









>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
830
831
832
833
834
835
836

837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
** Author contact information:
**   drh@hwaci.com
**   http://www.hwaci.com/drh/
**
*************************************************************************
** This file contains C code routines used for processing expressions
**
** $Id: expr.c,v 1.12 2000/06/08 11:25:01 drh Exp $
*/
#include "sqliteInt.h"

/*
** Walk an expression tree.  Return 1 if the expression is constant
** and 0 if it involves variables.
*/
................................................................................
  switch( pExpr->op ){
    case TK_FIELD: {
      aAgg = pParse->aAgg;
      for(i=0; i<pParse->nAgg; i++){
        if( aAgg[i].isAgg ) continue;
        if( aAgg[i].pExpr->iTable==pExpr->iTable
         && aAgg[i].pExpr->iField==pExpr->iField ){

          break;
        }
      }
      if( i>=pParse->nAgg ){
        i = appendAggInfo(pParse);
        if( i<0 ) return 1;
        pParse->aAgg[i].isAgg = 0;
        pParse->aAgg[i].pExpr = pExpr;
      }
      pExpr->iAgg = i;
      break;
    }
    case TK_AGG_FUNCTION: {
      if( pExpr->iField==FN_Count || pExpr->iField==FN_Avg ){
        if( pParse->iAggCount>=0 ){
          i = pParse->iAggCount;
        }else{

Changes to src/select.c.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
777
778
779
780
781
782
783

784
785
786
787
788
789
790
**   drh@hwaci.com
**   http://www.hwaci.com/drh/
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements.
**
** $Id: select.c,v 1.20 2000/06/08 11:13:02 drh Exp $
*/
#include "sqliteInt.h"

/*
** Allocate a new Select structure and return a pointer to that
** structure.
*/
................................................................................
      return 1;
    }
  }

  /* Do an analysis of aggregate expressions.
  */
  if( isAgg ){

    for(i=0; i<pEList->nExpr; i++){
      if( sqliteExprAnalyzeAggregates(pParse, pEList->a[i].pExpr) ){
        return 1;
      }
    }
    if( pGroupBy ){
      for(i=0; i<pGroupBy->nExpr; i++){







|







 







>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
**   drh@hwaci.com
**   http://www.hwaci.com/drh/
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements.
**
** $Id: select.c,v 1.21 2000/06/08 11:25:01 drh Exp $
*/
#include "sqliteInt.h"

/*
** Allocate a new Select structure and return a pointer to that
** structure.
*/
................................................................................
      return 1;
    }
  }

  /* Do an analysis of aggregate expressions.
  */
  if( isAgg ){
    assert( pParse->nAgg==0 && pParse->iAggCount<0 );
    for(i=0; i<pEList->nExpr; i++){
      if( sqliteExprAnalyzeAggregates(pParse, pEList->a[i].pExpr) ){
        return 1;
      }
    }
    if( pGroupBy ){
      for(i=0; i<pGroupBy->nExpr; i++){

Changes to test/select5.test.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
51
52
53
54
55
56
57



58
59
#   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: select5.test,v 1.1 2000/06/08 11:13:02 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
set fd [open data1.txt w]
................................................................................
#
do_test select5-1.1 {
  execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY y}
} {5 15 6 8 7 4 8 2 9 1 10 1}
do_test select5-1.2 {
  execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY count(*), y}
} {9 1 10 1 8 2 7 4 6 8 5 15}




finish_test







|







 







>
>
>


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
51
52
53
54
55
56
57
58
59
60
61
62
#   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: select5.test,v 1.2 2000/06/08 11:25:01 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
set fd [open data1.txt w]
................................................................................
#
do_test select5-1.1 {
  execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY y}
} {5 15 6 8 7 4 8 2 9 1 10 1}
do_test select5-1.2 {
  execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY count(*), y}
} {9 1 10 1 8 2 7 4 6 8 5 15}
do_test select5-1.3 {
  execsql {SELECT count(*), y FROM t1 GROUP BY y ORDER BY count(*), y}
} {1 9 1 10 2 8 4 7 8 6 15 5}

finish_test