blob: f95d8b220a8d663d2028444abe04094858d28288 [file] [log] [blame]
drh90669c12006-01-20 15:45:36 +00001# 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#
drh605ad8f2006-05-03 23:34:05 +000016# $Id: aggerror.test,v 1.3 2006/05/03 23:34:06 drh Exp $
drh90669c12006-01-20 15:45:36 +000017
18set testdir [file dirname $argv0]
19source $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#
drh605ad8f2006-05-03 23:34:05 +000027do_test aggerror-1.1 {
drh90669c12006-01-20 15:45:36 +000028 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}
drh605ad8f2006-05-03 23:34:05 +000042do_test aggerror-1.2 {
drh90669c12006-01-20 15:45:36 +000043 execsql {
44 INSERT INTO t1 VALUES(40);
45 SELECT x_count(*) FROM t1;
46 }
47} {40}
drh605ad8f2006-05-03 23:34:05 +000048do_test aggerror-1.3 {
drh90669c12006-01-20 15:45:36 +000049 catchsql {
50 SELECT x_count(a) FROM t1;
51 }
52} {1 {value of 40 handed to x_count}}
danielk1977a1686c92006-01-23 07:52:37 +000053ifcapable utf16 {
drh605ad8f2006-05-03 23:34:05 +000054 do_test aggerror-1.4 {
danielk1977a1686c92006-01-23 07:52:37 +000055 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}
drh605ad8f2006-05-03 23:34:05 +000063do_test aggerror-1.5 {
drh90669c12006-01-20 15:45:36 +000064 execsql {
65 SELECT x_count(*) FROM t1
66 }
67} 40
drh605ad8f2006-05-03 23:34:05 +000068do_test aggerror-1.6 {
drh90669c12006-01-20 15:45:36 +000069 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
78finish_test