sl@0
|
1 |
# 2006 January 20
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file implements tests for calling sqlite3_result_error()
|
sl@0
|
14 |
# from within an aggregate function implementation.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: aggerror.test,v 1.3 2006/05/03 23:34:06 drh Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
set testdir [file dirname $argv0]
|
sl@0
|
19 |
source $testdir/tester.tcl
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
# Add the x_count aggregate function to the database handle.
|
sl@0
|
23 |
# x_count will error out if its input is 40 or 41 or if its
|
sl@0
|
24 |
# final results is 42. Make sure that such errors are handled
|
sl@0
|
25 |
# appropriately.
|
sl@0
|
26 |
#
|
sl@0
|
27 |
do_test aggerror-1.1 {
|
sl@0
|
28 |
set DB [sqlite3_connection_pointer db]
|
sl@0
|
29 |
sqlite3_create_aggregate $DB
|
sl@0
|
30 |
execsql {
|
sl@0
|
31 |
CREATE TABLE t1(a);
|
sl@0
|
32 |
INSERT INTO t1 VALUES(1);
|
sl@0
|
33 |
INSERT INTO t1 VALUES(2);
|
sl@0
|
34 |
INSERT INTO t1 SELECT a+2 FROM t1;
|
sl@0
|
35 |
INSERT INTO t1 SELECT a+4 FROM t1;
|
sl@0
|
36 |
INSERT INTO t1 SELECT a+8 FROM t1;
|
sl@0
|
37 |
INSERT INTO t1 SELECT a+16 FROM t1;
|
sl@0
|
38 |
INSERT INTO t1 SELECT a+32 FROM t1 ORDER BY a LIMIT 7;
|
sl@0
|
39 |
SELECT x_count(*) FROM t1;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
} {39}
|
sl@0
|
42 |
do_test aggerror-1.2 {
|
sl@0
|
43 |
execsql {
|
sl@0
|
44 |
INSERT INTO t1 VALUES(40);
|
sl@0
|
45 |
SELECT x_count(*) FROM t1;
|
sl@0
|
46 |
}
|
sl@0
|
47 |
} {40}
|
sl@0
|
48 |
do_test aggerror-1.3 {
|
sl@0
|
49 |
catchsql {
|
sl@0
|
50 |
SELECT x_count(a) FROM t1;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
} {1 {value of 40 handed to x_count}}
|
sl@0
|
53 |
ifcapable utf16 {
|
sl@0
|
54 |
do_test aggerror-1.4 {
|
sl@0
|
55 |
execsql {
|
sl@0
|
56 |
UPDATE t1 SET a=41 WHERE a=40
|
sl@0
|
57 |
}
|
sl@0
|
58 |
catchsql {
|
sl@0
|
59 |
SELECT x_count(a) FROM t1;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
} {1 abc}
|
sl@0
|
62 |
}
|
sl@0
|
63 |
do_test aggerror-1.5 {
|
sl@0
|
64 |
execsql {
|
sl@0
|
65 |
SELECT x_count(*) FROM t1
|
sl@0
|
66 |
}
|
sl@0
|
67 |
} 40
|
sl@0
|
68 |
do_test aggerror-1.6 {
|
sl@0
|
69 |
execsql {
|
sl@0
|
70 |
INSERT INTO t1 VALUES(40);
|
sl@0
|
71 |
INSERT INTO t1 VALUES(42);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
catchsql {
|
sl@0
|
74 |
SELECT x_count(*) FROM t1;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
} {1 {x_count totals to 42}}
|
sl@0
|
77 |
|
sl@0
|
78 |
finish_test
|