Home | History | Annotate | Download | only in test
      1 # 2006 January 20
      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 # This file implements tests for calling sqlite3_result_error()
     14 # from within an aggregate function implementation.
     15 #
     16 # $Id: aggerror.test,v 1.3 2006/05/03 23:34:06 drh Exp $
     17 
     18 set testdir [file dirname $argv0]
     19 source $testdir/tester.tcl
     20 
     21 
     22 # Add the x_count aggregate function to the database handle.
     23 # x_count will error out if its input is 40 or 41 or if its
     24 # final results is 42.  Make sure that such errors are handled
     25 # appropriately.
     26 #
     27 do_test aggerror-1.1 {
     28   set DB [sqlite3_connection_pointer db]
     29   sqlite3_create_aggregate $DB
     30   execsql {
     31     CREATE TABLE t1(a);
     32     INSERT INTO t1 VALUES(1);
     33     INSERT INTO t1 VALUES(2);
     34     INSERT INTO t1 SELECT a+2 FROM t1;
     35     INSERT INTO t1 SELECT a+4 FROM t1;
     36     INSERT INTO t1 SELECT a+8 FROM t1;
     37     INSERT INTO t1 SELECT a+16 FROM t1;
     38     INSERT INTO t1 SELECT a+32 FROM t1 ORDER BY a LIMIT 7;
     39     SELECT x_count(*) FROM t1;
     40   }
     41 } {39}
     42 do_test aggerror-1.2 {
     43   execsql {
     44     INSERT INTO t1 VALUES(40);
     45     SELECT x_count(*) FROM t1;
     46   }
     47 } {40}
     48 do_test aggerror-1.3 {
     49   catchsql {
     50     SELECT x_count(a) FROM t1;
     51   }
     52 } {1 {value of 40 handed to x_count}}
     53 ifcapable utf16 {
     54   do_test aggerror-1.4 {
     55     execsql {
     56       UPDATE t1 SET a=41 WHERE a=40
     57     }
     58     catchsql {
     59       SELECT x_count(a) FROM t1;
     60     }
     61   } {1 abc}
     62 }
     63 do_test aggerror-1.5 {
     64   execsql {
     65     SELECT x_count(*) FROM t1
     66   }
     67 } 40
     68 do_test aggerror-1.6 {
     69   execsql {
     70     INSERT INTO t1 VALUES(40);
     71     INSERT INTO t1 VALUES(42);
     72   }
     73   catchsql {
     74     SELECT x_count(*) FROM t1;
     75   }
     76 } {1 {x_count totals to 42}}
     77 
     78 finish_test
     79