1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
#pragma ident "%Z%%M% %I% %E% SMI"
# 2003 June 21
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc2.test,v 1.11 2003/12/17 23:57:36 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Test for ticket #360
#
do_test misc2-1.1 {
catchsql {
CREATE TABLE FOO(bar integer);
CREATE TRIGGER foo_insert BEFORE INSERT ON foo BEGIN
SELECT CASE WHEN (NOT new.bar BETWEEN 0 AND 20)
THEN raise(rollback, 'aiieee') END;
END;
INSERT INTO foo(bar) VALUES (1);
}
} {0 {}}
do_test misc2-1.2 {
catchsql {
INSERT INTO foo(bar) VALUES (111);
}
} {1 aiieee}
# Make sure ROWID works on a view and a subquery. Ticket #364
#
do_test misc2-2.1 {
execsql {
CREATE TABLE t1(a,b,c);
INSERT INTO t1 VALUES(1,2,3);
CREATE TABLE t2(a,b,c);
INSERT INTO t2 VALUES(7,8,9);
SELECT rowid, * FROM (SELECT * FROM t1, t2);
}
} {{} 1 2 3 7 8 9}
do_test misc2-2.2 {
execsql {
CREATE VIEW v1 AS SELECT * FROM t1, t2;
SELECT rowid, * FROM v1;
}
} {{} 1 2 3 7 8 9}
# Check name binding precedence. Ticket #387
#
do_test misc2-3.1 {
catchsql {
SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10
}
} {1 {ambiguous column name: a}}
# Make sure 32-bit integer overflow is handled properly in queries.
# ticket #408
#
do_test misc2-4.1 {
execsql {
INSERT INTO t1 VALUES(4000000000,'a','b');
SELECT a FROM t1 WHERE a>1;
}
} {4000000000}
do_test misc2-4.2 {
execsql {
INSERT INTO t1 VALUES(2147483648,'b2','c2');
INSERT INTO t1 VALUES(2147483647,'b3','c3');
SELECT a FROM t1 WHERE a>2147483647;
}
} {4000000000 2147483648}
do_test misc2-4.3 {
execsql {
SELECT a FROM t1 WHERE a<2147483648;
}
} {1 2147483647}
do_test misc2-4.4 {
execsql {
SELECT a FROM t1 WHERE a<=2147483648;
}
} {1 2147483648 2147483647}
do_test misc2-4.5 {
execsql {
SELECT a FROM t1 WHERE a<10000000000;
}
} {1 4000000000 2147483648 2147483647}
do_test misc2-4.6 {
execsql {
SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1;
}
} {1 2147483647 2147483648 4000000000}
# There were some issues with expanding a SrcList object using a call
# to sqliteSrcListAppend() if the SrcList had previously been duplicated
# using a call to sqliteSrcListDup(). Ticket #416. The following test
# makes sure the problem has been fixed.
#
do_test misc2-5.1 {
execsql {
CREATE TABLE x(a,b);
CREATE VIEW y AS
SELECT x1.b AS p, x2.b AS q FROM x AS x1, x AS x2 WHERE x1.a=x2.a;
CREATE VIEW z AS
SELECT y1.p, y2.p FROM y AS y1, y AS y2 WHERE y1.q=y2.q;
SELECT * from z;
}
} {}
# Make sure we can open a database with an empty filename. What this
# does is store the database in a temporary file that is deleted when
# the database is closed. Ticket #432.
#
do_test misc2-6.1 {
db close
sqlite db {}
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,2);
SELECT * FROM t1;
}
} {1 2}
# Make sure we get an error message (not a segfault) on an attempt to
# update a table from within the callback of a select on that same
# table.
#
do_test misc2-7.1 {
db close
file delete -force test.db
sqlite db test.db
execsql {
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
}
set rc [catch {
db eval {SELECT rowid FROM t1} {} {
db eval "DELETE FROM t1 WHERE rowid=$rowid"
}
} msg]
lappend rc $msg
} {1 {database table is locked}}
do_test misc2-7.2 {
set rc [catch {
db eval {SELECT rowid FROM t1} {} {
db eval "INSERT INTO t1 VALUES(3)"
}
} msg]
lappend rc $msg
} {1 {database table is locked}}
do_test misc2-7.3 {
db close
file delete -force test.db
sqlite db :memory:
execsql {
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
}
set rc [catch {
db eval {SELECT rowid FROM t1} {} {
db eval "DELETE FROM t1 WHERE rowid=$rowid"
}
} msg]
lappend rc $msg
} {1 {database table is locked}}
do_test misc2-7.4 {
set rc [catch {
db eval {SELECT rowid FROM t1} {} {
db eval "INSERT INTO t1 VALUES(3)"
}
} msg]
lappend rc $msg
} {1 {database table is locked}}
# Ticket #453. If the SQL ended with "-", the tokenizer was calling that
# an incomplete token, which caused problem. The solution was to just call
# it a minus sign.
#
do_test misc2-8.1 {
catchsql {-}
} {1 {near "-": syntax error}}
# Ticket #513. Make sure the VDBE stack does not grow on a 3-way join.
#
do_test misc2-9.1 {
execsql {
BEGIN;
CREATE TABLE counts(n INTEGER PRIMARY KEY);
INSERT INTO counts VALUES(0);
INSERT INTO counts VALUES(1);
INSERT INTO counts SELECT n+2 FROM counts;
INSERT INTO counts SELECT n+4 FROM counts;
INSERT INTO counts SELECT n+8 FROM counts;
COMMIT;
CREATE TEMP TABLE x AS
SELECT dim1.n, dim2.n, dim3.n
FROM counts AS dim1, counts AS dim2, counts AS dim3
WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10;
SELECT count(*) FROM x;
}
} {1000}
do_test misc2-9.2 {
execsql {
DROP TABLE x;
CREATE TEMP TABLE x AS
SELECT dim1.n, dim2.n, dim3.n
FROM counts AS dim1, counts AS dim2, counts AS dim3
WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6;
SELECT count(*) FROM x;
}
} {1000}
do_test misc2-9.3 {
execsql {
DROP TABLE x;
CREATE TEMP TABLE x AS
SELECT dim1.n, dim2.n, dim3.n, dim4.n
FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
SELECT count(*) FROM x;
}
} [expr 5*5*5*5]
finish_test
|