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 | # |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 16 | # $Id: aggerror.test,v 1.3 2006/05/03 23:34:06 drh Exp $ |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 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 | # |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 27 | do_test aggerror-1.1 { |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 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} |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 42 | do_test aggerror-1.2 { |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 43 | execsql { |
| 44 | INSERT INTO t1 VALUES(40); |
| 45 | SELECT x_count(*) FROM t1; |
| 46 | } |
| 47 | } {40} |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 48 | do_test aggerror-1.3 { |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 49 | catchsql { |
| 50 | SELECT x_count(a) FROM t1; |
| 51 | } |
| 52 | } {1 {value of 40 handed to x_count}} |
danielk1977 | a1686c9 | 2006-01-23 07:52:37 +0000 | [diff] [blame] | 53 | ifcapable utf16 { |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 54 | do_test aggerror-1.4 { |
danielk1977 | a1686c9 | 2006-01-23 07:52:37 +0000 | [diff] [blame] | 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 | } |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 63 | do_test aggerror-1.5 { |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 64 | execsql { |
| 65 | SELECT x_count(*) FROM t1 |
| 66 | } |
| 67 | } 40 |
drh | 605ad8f | 2006-05-03 23:34:05 +0000 | [diff] [blame] | 68 | do_test aggerror-1.6 { |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 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 |