drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame^] | 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.1 2006/01/20 15:45:37 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 aggfunc-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 aggfunc-1.2 { |
| 43 | execsql { |
| 44 | INSERT INTO t1 VALUES(40); |
| 45 | SELECT x_count(*) FROM t1; |
| 46 | } |
| 47 | } {40} |
| 48 | do_test aggfunc-1.3 { |
| 49 | catchsql { |
| 50 | SELECT x_count(a) FROM t1; |
| 51 | } |
| 52 | } {1 {value of 40 handed to x_count}} |
| 53 | do_test aggfunc-1.4 { |
| 54 | execsql { |
| 55 | UPDATE t1 SET a=41 WHERE a=40 |
| 56 | } |
| 57 | catchsql { |
| 58 | SELECT x_count(a) FROM t1; |
| 59 | } |
| 60 | } {1 abc} |
| 61 | do_test aggfunc-1.5 { |
| 62 | execsql { |
| 63 | SELECT x_count(*) FROM t1 |
| 64 | } |
| 65 | } 40 |
| 66 | do_test aggfunc-1.6 { |
| 67 | execsql { |
| 68 | INSERT INTO t1 VALUES(40); |
| 69 | INSERT INTO t1 VALUES(42); |
| 70 | } |
| 71 | catchsql { |
| 72 | SELECT x_count(*) FROM t1; |
| 73 | } |
| 74 | } {1 {x_count totals to 42}} |
| 75 | |
| 76 | finish_test |