/ Check-in [0a26b915]
Login

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

Overview
Comment:Apply (1679) to version 3. Ticket #777. (CVS 1680)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0a26b9158095f0995fce2f0ccdfb383ab26c76a5
User & Date: danielk1977 2004-06-24 00:20:05
Context
2004-06-24
01:30
Minor fix for 'make doc'. (CVS 1681) check-in: 31fe5cbd user: danielk1977 tags: trunk
00:20
Apply (1679) to version 3. Ticket #777. (CVS 1680) check-in: 0a26b915 user: danielk1977 tags: trunk
2004-06-23
13:46
Improve test coverage of utf.c. (CVS 1678) check-in: 53c553c7 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

    12     12   ** This file contains the C functions that implement various SQL
    13     13   ** functions of SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: func.c,v 1.75 2004/06/21 06:50:28 danielk1977 Exp $
           19  +** $Id: func.c,v 1.76 2004/06/24 00:20:05 danielk1977 Exp $
    20     20   */
    21     21   #include <ctype.h>
    22     22   #include <math.h>
    23     23   #include <stdlib.h>
    24     24   #include <assert.h>
    25     25   #include "sqliteInt.h"
    26     26   #include "vdbeInt.h"
................................................................................
   967    967   ** Routines to implement min() and max() aggregate functions.
   968    968   */
   969    969   static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){
   970    970     int max = 0;
   971    971     int cmp = 0;
   972    972     Mem *pArg  = (Mem *)argv[0];
   973    973     Mem *pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
          974  +  if( !pBest ) return;
   974    975   
   975         -  if( !pBest || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
   976    976     if( pBest->flags ){
   977    977       CollSeq *pColl = sqlite3GetFuncCollSeq(context);
   978    978       /* This step function is used for both the min() and max() aggregates,
   979    979       ** the only difference between the two being that the sense of the
   980    980       ** comparison is inverted. For the max() aggregate, the
   981    981       ** sqlite3_user_data() function returns (void *)-1. For min() it
   982    982       ** returns (void *)db, where db is the sqlite3* database pointer.

Changes to test/func.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing built-in functions.
    13     13   #
    14         -# $Id: func.test,v 1.25 2004/06/23 01:05:27 danielk1977 Exp $
           14  +# $Id: func.test,v 1.26 2004/06/24 00:20:05 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Create a table to work with.
    20     20   #
    21     21   do_test func-0.0 {
................................................................................
   247    247   
   248    248   # Tests for aggregate functions and how they handle NULLs.
   249    249   #
   250    250   do_test func-8.1 {
   251    251     execsql {
   252    252       SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2;
   253    253     }
   254         -} {68236 3 22745.33 1 67890 5}
          254  +} {68236 3 22745.33 {} 67890 5}
   255    255   do_test func-8.2 {
   256    256     execsql {
   257    257       SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2;
   258    258     }
   259    259   } {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
   260    260   do_test func-8.3 {
   261    261     execsql {
   262    262       CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
   263    263       SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
   264    264     }
   265         -} {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
          265  +} {{}}
          266  +do_test func-8.4 {
          267  +  execsql {
          268  +    SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
          269  +  }
          270  +} {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
   266    271   
   267    272   # How do you test the random() function in a meaningful, deterministic way?
   268    273   #
   269    274   do_test func-9.1 {
   270    275     execsql {
   271    276       SELECT random() is not null;
   272    277     }

Changes to test/minmax.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing SELECT statements that contain
    13     13   # aggregate min() and max() functions and which are handled as
    14     14   # as a special case.
    15     15   #
    16         -# $Id: minmax.test,v 1.9 2004/03/13 14:00:37 drh Exp $
           16  +# $Id: minmax.test,v 1.10 2004/06/24 00:20:05 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   do_test minmax-1.0 {
    22     22     execsql {
    23     23       BEGIN;
................................................................................
   123    123   } {0}
   124    124   
   125    125   do_test minmax-4.1 {
   126    126     execsql {
   127    127       SELECT coalesce(min(x+0),-1), coalesce(max(x+0),-1) FROM
   128    128         (SELECT * FROM t1 UNION SELECT NULL as 'x', NULL as 'y')
   129    129     }
   130         -} {1 20}
          130  +} {-1 20}
   131    131   do_test minmax-4.2 {
   132    132     execsql {
   133    133       SELECT y, sum(x) FROM
   134    134         (SELECT null, y+1 FROM t1 UNION SELECT * FROM t1)
   135    135       GROUP BY y ORDER BY y;
   136    136     }
   137    137   } {1 1 2 5 3 22 4 92 5 90 6 0}
................................................................................
   271    271   do_test minmax-9.2 {
   272    272     execsql {
   273    273       SELECT max(rowid) FROM (
   274    274         SELECT max(rowid) FROM t4 EXCEPT SELECT max(rowid) FROM t5
   275    275       )
   276    276     }
   277    277   } {{}}
          278  +
          279  +# If there is a NULL in an aggregate max(), ignore it.  If a NULL
          280  +# occurs in an aggregate min(), then the result will be NULL because
          281  +# NULL compares less than all other values.
          282  +#
          283  +do_test minmax-10.1 {
          284  +  execsql {
          285  +    CREATE TABLE t6(x);
          286  +    INSERT INTO t6 VALUES(1);
          287  +    INSERT INTO t6 VALUES(2);
          288  +    INSERT INTO t6 VALUES(NULL);
          289  +    SELECT coalesce(min(x),-1) FROM t6;
          290  +  }
          291  +} {-1}
          292  +do_test minmax-10.2 {
          293  +  execsql {
          294  +    SELECT max(x) FROM t6;
          295  +  }
          296  +} {2}
          297  +do_test minmax-10.3 {
          298  +  execsql {
          299  +    CREATE INDEX i6 ON t6(x);
          300  +    SELECT coalesce(min(x),-1) FROM t6;
          301  +  }
          302  +} {-1}
          303  +do_test minmax-10.4 {
          304  +  execsql {
          305  +    SELECT max(x) FROM t6;
          306  +  }
          307  +} {2}
   278    308   
   279    309   finish_test

Changes to test/null.test.

    96     96   # Check to see that NULL values are ignored in aggregate functions.
    97     97   #
    98     98   do_test null-3.1 {
    99     99     execsql {
   100    100       select count(*), count(b), count(c), sum(b), sum(c), 
   101    101              avg(b), avg(c), min(b), max(b) from t1;
   102    102     }
   103         -} {7 4 6 2 3 0.5 0.5 0 1}
          103  +} {7 4 6 2 3 0.5 0.5 {} 1}
   104    104   
   105    105   # Check to see how WHERE clauses handle NULL values.  A NULL value
   106    106   # is the same as UNKNOWN.  The WHERE clause should only select those
   107    107   # rows that are TRUE.  FALSE and UNKNOWN rows are rejected.
   108    108   #
   109    109   do_test null-4.1 {
   110    110     execsql {

Changes to test/select1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the SELECT statement.
    13     13   #
    14         -# $Id: select1.test,v 1.32 2004/05/28 11:37:29 danielk1977 Exp $
           14  +# $Id: select1.test,v 1.33 2004/06/24 00:20:05 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Try to select on a non-existant table.
    20     20   #
    21     21   do_test select1-1.1 {
................................................................................
   155    155   } {0 11}
   156    156   do_test select1-2.8 {
   157    157     set v [catch {execsql {SELECT MIN(f1,f2) FROM test1}} msg]
   158    158     lappend v [lsort $msg]
   159    159   } {0 {11 33}}
   160    160   do_test select1-2.8.1 {
   161    161     execsql {SELECT coalesce(min(a),'xyzzy') FROM t3}
   162         -} {11}
          162  +} {xyzzy}
   163    163   do_test select1-2.8.2 {
   164    164     execsql {SELECT min(coalesce(a,'xyzzy')) FROM t3}
   165    165   } {11}
   166    166   do_test select1-2.8.3 {
   167    167     execsql {SELECT min(b), min(b) FROM t4}
   168    168   } [list $long $long]
   169    169   do_test select1-2.9 {