blob: 049370f9bfa35524b6a1975a9c1f3dec20fd0705 [file] [log] [blame]
drhb19a2bc2001-09-16 00:13:26 +00001# 2001 September 15
drh1d37e282000-05-30 03:12:21 +00002#
drhb19a2bc2001-09-16 00:13:26 +00003# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
drh1d37e282000-05-30 03:12:21 +00005#
drhb19a2bc2001-09-16 00:13:26 +00006# 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.
drh1d37e282000-05-30 03:12:21 +00009#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is testing the UPDATE statement.
13#
drh37ed48e2003-08-05 13:13:38 +000014# $Id: update.test,v 1.14 2003/08/05 13:13:39 drh Exp $
drh1d37e282000-05-30 03:12:21 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# Try to update an non-existent table
20#
21do_test update-1.1 {
22 set v [catch {execsql {UPDATE test1 SET f2=5 WHERE f1<1}} msg]
23 lappend v $msg
24} {1 {no such table: test1}}
25
26# Try to update a read-only table
27#
28do_test update-2.1 {
29 set v [catch \
30 {execsql {UPDATE sqlite_master SET name='xyz' WHERE name='123'}} msg]
31 lappend v $msg
32} {1 {table sqlite_master may not be modified}}
33
34# Create a table to work with
35#
36do_test update-3.1 {
37 execsql {CREATE TABLE test1(f1 int,f2 int)}
38 for {set i 1} {$i<=10} {incr i} {
39 set sql "INSERT INTO test1 VALUES($i,[expr {int(pow(2,$i))}])"
40 execsql $sql
41 }
42 execsql {SELECT * FROM test1 ORDER BY f1}
43} {1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024}
44
drh967e8b72000-06-21 13:59:10 +000045# Unknown column name in an expression
drh1d37e282000-05-30 03:12:21 +000046#
47do_test update-3.2 {
48 set v [catch {execsql {UPDATE test1 SET f1=f3*2 WHERE f2==32}} msg]
49 lappend v $msg
drh967e8b72000-06-21 13:59:10 +000050} {1 {no such column: f3}}
drh1d37e282000-05-30 03:12:21 +000051do_test update-3.3 {
52 set v [catch {execsql {UPDATE test1 SET f1=test2.f1*2 WHERE f2==32}} msg]
53 lappend v $msg
drh967e8b72000-06-21 13:59:10 +000054} {1 {no such column: test2.f1}}
drh1d37e282000-05-30 03:12:21 +000055do_test update-3.4 {
56 set v [catch {execsql {UPDATE test1 SET f3=f1*2 WHERE f2==32}} msg]
57 lappend v $msg
drh967e8b72000-06-21 13:59:10 +000058} {1 {no such column: f3}}
drh1d37e282000-05-30 03:12:21 +000059
60# Actually do some updates
61#
62do_test update-3.5 {
63 execsql {UPDATE test1 SET f2=f2*3}
drh1bee3d72001-10-15 00:44:35 +000064} {}
65do_test update-3.6 {
drh1d37e282000-05-30 03:12:21 +000066 execsql {SELECT * FROM test1 ORDER BY f1}
67} {1 6 2 12 3 24 4 48 5 96 6 192 7 384 8 768 9 1536 10 3072}
drh1bee3d72001-10-15 00:44:35 +000068do_test update-3.7 {
69 execsql {PRAGMA count_changes=on}
drh1d37e282000-05-30 03:12:21 +000070 execsql {UPDATE test1 SET f2=f2/3 WHERE f1<=5}
drh1bee3d72001-10-15 00:44:35 +000071} {5}
72do_test update-3.8 {
drh1d37e282000-05-30 03:12:21 +000073 execsql {SELECT * FROM test1 ORDER BY f1}
74} {1 2 2 4 3 8 4 16 5 32 6 192 7 384 8 768 9 1536 10 3072}
drh1bee3d72001-10-15 00:44:35 +000075do_test update-3.9 {
drh1d37e282000-05-30 03:12:21 +000076 execsql {UPDATE test1 SET f2=f2/3 WHERE f1>5}
drh1bee3d72001-10-15 00:44:35 +000077} {5}
78do_test update-3.10 {
drh1d37e282000-05-30 03:12:21 +000079 execsql {SELECT * FROM test1 ORDER BY f1}
80} {1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024}
81
82# Swap the values of f1 and f2 for all elements
83#
drh1bee3d72001-10-15 00:44:35 +000084do_test update-3.11 {
drh6206d502000-06-19 19:09:08 +000085 execsql {UPDATE test1 SET F2=f1, F1=f2}
drh1bee3d72001-10-15 00:44:35 +000086} {10}
87do_test update-3.12 {
drh6206d502000-06-19 19:09:08 +000088 execsql {SELECT * FROM test1 ORDER BY F1}
drh1d37e282000-05-30 03:12:21 +000089} {2 1 4 2 8 3 16 4 32 5 64 6 128 7 256 8 512 9 1024 10}
drh1bee3d72001-10-15 00:44:35 +000090do_test update-3.13 {
91 execsql {PRAGMA count_changes=off}
drh4f3c63e2001-02-19 18:24:21 +000092 execsql {UPDATE test1 SET F2=f1, F1=f2}
drh1bee3d72001-10-15 00:44:35 +000093} {}
94do_test update-3.14 {
drh4f3c63e2001-02-19 18:24:21 +000095 execsql {SELECT * FROM test1 ORDER BY F1}
96} {1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024}
97
98# Create duplicate entries and make sure updating still
99# works.
100#
101do_test update-4.0 {
102 execsql {
103 DELETE FROM test1 WHERE f1<=5;
104 INSERT INTO test1(f1,f2) VALUES(8,88);
105 INSERT INTO test1(f1,f2) VALUES(8,888);
106 INSERT INTO test1(f1,f2) VALUES(77,128);
107 INSERT INTO test1(f1,f2) VALUES(777,128);
108 }
109 execsql {SELECT * FROM test1 ORDER BY f1,f2}
110} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
111do_test update-4.1 {
112 execsql {UPDATE test1 SET f2=f2+1 WHERE f1==8}
113 execsql {SELECT * FROM test1 ORDER BY f1,f2}
114} {6 64 7 128 8 89 8 257 8 889 9 512 10 1024 77 128 777 128}
115do_test update-4.2 {
116 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2>800}
117 execsql {SELECT * FROM test1 ORDER BY f1,f2}
118} {6 64 7 128 8 89 8 257 8 888 9 512 10 1024 77 128 777 128}
119do_test update-4.3 {
120 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2<800}
121 execsql {SELECT * FROM test1 ORDER BY f1,f2}
122} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
123do_test update-4.4 {
124 execsql {UPDATE test1 SET f1=f1+1 WHERE f2==128}
125 execsql {SELECT * FROM test1 ORDER BY f1,f2}
126} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 778 128}
127do_test update-4.5 {
128 execsql {UPDATE test1 SET f1=f1-1 WHERE f1>100 and f2==128}
129 execsql {SELECT * FROM test1 ORDER BY f1,f2}
130} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 777 128}
131do_test update-4.6 {
drh1bee3d72001-10-15 00:44:35 +0000132 execsql {
133 PRAGMA count_changes=on;
134 UPDATE test1 SET f1=f1-1 WHERE f1<=100 and f2==128;
135 }
136} {2}
137do_test update-4.7 {
138 execsql {
139 PRAGMA count_changes=off;
140 SELECT * FROM test1 ORDER BY f1,f2
141 }
drh4f3c63e2001-02-19 18:24:21 +0000142} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
143
144# Repeat the previous sequence of tests with an index.
145#
146do_test update-5.0 {
147 execsql {CREATE INDEX idx1 ON test1(f1)}
148 execsql {SELECT * FROM test1 ORDER BY f1,f2}
149} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
150do_test update-5.1 {
151 execsql {UPDATE test1 SET f2=f2+1 WHERE f1==8}
152 execsql {SELECT * FROM test1 ORDER BY f1,f2}
153} {6 64 7 128 8 89 8 257 8 889 9 512 10 1024 77 128 777 128}
154do_test update-5.2 {
155 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2>800}
156 execsql {SELECT * FROM test1 ORDER BY f1,f2}
157} {6 64 7 128 8 89 8 257 8 888 9 512 10 1024 77 128 777 128}
158do_test update-5.3 {
159 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2<800}
160 execsql {SELECT * FROM test1 ORDER BY f1,f2}
161} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
162do_test update-5.4 {
163 execsql {UPDATE test1 SET f1=f1+1 WHERE f2==128}
164 execsql {SELECT * FROM test1 ORDER BY f1,f2}
165} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 778 128}
166do_test update-5.4.1 {
167 execsql {SELECT * FROM test1 WHERE f1==78 ORDER BY f1,f2}
168} {78 128}
169do_test update-5.4.2 {
170 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
171} {778 128}
172do_test update-5.4.3 {
173 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
174} {8 88 8 128 8 256 8 888}
175do_test update-5.5 {
176 execsql {UPDATE test1 SET f1=f1-1 WHERE f1>100 and f2==128}
drh1bee3d72001-10-15 00:44:35 +0000177} {}
178do_test update-5.5.1 {
drh4f3c63e2001-02-19 18:24:21 +0000179 execsql {SELECT * FROM test1 ORDER BY f1,f2}
180} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 777 128}
drh1bee3d72001-10-15 00:44:35 +0000181do_test update-5.5.2 {
drh4f3c63e2001-02-19 18:24:21 +0000182 execsql {SELECT * FROM test1 WHERE f1==78 ORDER BY f1,f2}
183} {78 128}
drh1bee3d72001-10-15 00:44:35 +0000184do_test update-5.5.3 {
drh4f3c63e2001-02-19 18:24:21 +0000185 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
186} {}
drh1bee3d72001-10-15 00:44:35 +0000187do_test update-5.5.4 {
drh4f3c63e2001-02-19 18:24:21 +0000188 execsql {SELECT * FROM test1 WHERE f1==777 ORDER BY f1,f2}
189} {777 128}
drh1bee3d72001-10-15 00:44:35 +0000190do_test update-5.5.5 {
drh4f3c63e2001-02-19 18:24:21 +0000191 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
192} {8 88 8 128 8 256 8 888}
193do_test update-5.6 {
drh1bee3d72001-10-15 00:44:35 +0000194 execsql {
195 PRAGMA count_changes=on;
196 UPDATE test1 SET f1=f1-1 WHERE f1<=100 and f2==128;
197 }
198} {2}
drh4f3c63e2001-02-19 18:24:21 +0000199do_test update-5.6.1 {
drh1bee3d72001-10-15 00:44:35 +0000200 execsql {
201 PRAGMA count_changes=off;
202 SELECT * FROM test1 ORDER BY f1,f2
203 }
204} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
205do_test update-5.6.2 {
drh4f3c63e2001-02-19 18:24:21 +0000206 execsql {SELECT * FROM test1 WHERE f1==77 ORDER BY f1,f2}
207} {77 128}
drh1bee3d72001-10-15 00:44:35 +0000208do_test update-5.6.3 {
drh4f3c63e2001-02-19 18:24:21 +0000209 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
210} {}
drh1bee3d72001-10-15 00:44:35 +0000211do_test update-5.6.4 {
drh4f3c63e2001-02-19 18:24:21 +0000212 execsql {SELECT * FROM test1 WHERE f1==777 ORDER BY f1,f2}
213} {777 128}
drh1bee3d72001-10-15 00:44:35 +0000214do_test update-5.6.5 {
drh4f3c63e2001-02-19 18:24:21 +0000215 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
216} {8 88 8 256 8 888}
217
218# Repeat the previous sequence of tests with a different index.
219#
drh4303fee2003-02-15 23:09:17 +0000220execsql {PRAGMA synchronous=FULL}
drh4f3c63e2001-02-19 18:24:21 +0000221do_test update-6.0 {
222 execsql {DROP INDEX idx1}
223 execsql {CREATE INDEX idx1 ON test1(f2)}
224 execsql {SELECT * FROM test1 ORDER BY f1,f2}
225} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
226do_test update-6.1 {
227 execsql {UPDATE test1 SET f2=f2+1 WHERE f1==8}
228 execsql {SELECT * FROM test1 ORDER BY f1,f2}
229} {6 64 7 128 8 89 8 257 8 889 9 512 10 1024 77 128 777 128}
230do_test update-6.1.1 {
231 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
232} {8 89 8 257 8 889}
233do_test update-6.1.2 {
234 execsql {SELECT * FROM test1 WHERE f2==89 ORDER BY f1,f2}
235} {8 89}
236do_test update-6.1.3 {
237 execsql {SELECT * FROM test1 WHERE f1==88 ORDER BY f1,f2}
238} {}
239do_test update-6.2 {
240 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2>800}
241 execsql {SELECT * FROM test1 ORDER BY f1,f2}
242} {6 64 7 128 8 89 8 257 8 888 9 512 10 1024 77 128 777 128}
243do_test update-6.3 {
244 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2<800}
245 execsql {SELECT * FROM test1 ORDER BY f1,f2}
246} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
247do_test update-6.3.1 {
248 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
249} {8 88 8 256 8 888}
250do_test update-6.3.2 {
251 execsql {SELECT * FROM test1 WHERE f2==89 ORDER BY f1,f2}
252} {}
253do_test update-6.3.3 {
254 execsql {SELECT * FROM test1 WHERE f2==88 ORDER BY f1,f2}
255} {8 88}
256do_test update-6.4 {
257 execsql {UPDATE test1 SET f1=f1+1 WHERE f2==128}
258 execsql {SELECT * FROM test1 ORDER BY f1,f2}
259} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 778 128}
260do_test update-6.4.1 {
261 execsql {SELECT * FROM test1 WHERE f1==78 ORDER BY f1,f2}
262} {78 128}
263do_test update-6.4.2 {
264 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
265} {778 128}
266do_test update-6.4.3 {
267 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
268} {8 88 8 128 8 256 8 888}
269do_test update-6.5 {
270 execsql {UPDATE test1 SET f1=f1-1 WHERE f1>100 and f2==128}
271 execsql {SELECT * FROM test1 ORDER BY f1,f2}
272} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 777 128}
273do_test update-6.5.1 {
274 execsql {SELECT * FROM test1 WHERE f1==78 ORDER BY f1,f2}
275} {78 128}
276do_test update-6.5.2 {
277 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
278} {}
279do_test update-6.5.3 {
280 execsql {SELECT * FROM test1 WHERE f1==777 ORDER BY f1,f2}
281} {777 128}
282do_test update-6.5.4 {
283 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
284} {8 88 8 128 8 256 8 888}
285do_test update-6.6 {
286 execsql {UPDATE test1 SET f1=f1-1 WHERE f1<=100 and f2==128}
287 execsql {SELECT * FROM test1 ORDER BY f1,f2}
288} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
289do_test update-6.6.1 {
290 execsql {SELECT * FROM test1 WHERE f1==77 ORDER BY f1,f2}
291} {77 128}
292do_test update-6.6.2 {
293 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
294} {}
295do_test update-6.6.3 {
296 execsql {SELECT * FROM test1 WHERE f1==777 ORDER BY f1,f2}
297} {777 128}
298do_test update-6.6.4 {
299 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
300} {8 88 8 256 8 888}
301
302# Repeat the previous sequence of tests with multiple
303# indices
304#
305do_test update-7.0 {
306 execsql {CREATE INDEX idx2 ON test1(f2)}
307 execsql {CREATE INDEX idx3 ON test1(f1,f2)}
308 execsql {SELECT * FROM test1 ORDER BY f1,f2}
309} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
310do_test update-7.1 {
311 execsql {UPDATE test1 SET f2=f2+1 WHERE f1==8}
312 execsql {SELECT * FROM test1 ORDER BY f1,f2}
313} {6 64 7 128 8 89 8 257 8 889 9 512 10 1024 77 128 777 128}
314do_test update-7.1.1 {
315 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
316} {8 89 8 257 8 889}
317do_test update-7.1.2 {
318 execsql {SELECT * FROM test1 WHERE f2==89 ORDER BY f1,f2}
319} {8 89}
320do_test update-7.1.3 {
321 execsql {SELECT * FROM test1 WHERE f1==88 ORDER BY f1,f2}
322} {}
323do_test update-7.2 {
324 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2>800}
325 execsql {SELECT * FROM test1 ORDER BY f1,f2}
326} {6 64 7 128 8 89 8 257 8 888 9 512 10 1024 77 128 777 128}
327do_test update-7.3 {
drh04096482001-11-09 22:41:44 +0000328 # explain {UPDATE test1 SET f2=f2-1 WHERE f1==8 and F2<300}
drh4f3c63e2001-02-19 18:24:21 +0000329 execsql {UPDATE test1 SET f2=f2-1 WHERE f1==8 and f2<800}
330 execsql {SELECT * FROM test1 ORDER BY f1,f2}
331} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
332do_test update-7.3.1 {
333 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
334} {8 88 8 256 8 888}
335do_test update-7.3.2 {
336 execsql {SELECT * FROM test1 WHERE f2==89 ORDER BY f1,f2}
337} {}
338do_test update-7.3.3 {
339 execsql {SELECT * FROM test1 WHERE f2==88 ORDER BY f1,f2}
340} {8 88}
341do_test update-7.4 {
342 execsql {UPDATE test1 SET f1=f1+1 WHERE f2==128}
343 execsql {SELECT * FROM test1 ORDER BY f1,f2}
344} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 778 128}
345do_test update-7.4.1 {
346 execsql {SELECT * FROM test1 WHERE f1==78 ORDER BY f1,f2}
347} {78 128}
348do_test update-7.4.2 {
349 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
350} {778 128}
351do_test update-7.4.3 {
352 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
353} {8 88 8 128 8 256 8 888}
354do_test update-7.5 {
355 execsql {UPDATE test1 SET f1=f1-1 WHERE f1>100 and f2==128}
356 execsql {SELECT * FROM test1 ORDER BY f1,f2}
357} {6 64 8 88 8 128 8 256 8 888 9 512 10 1024 78 128 777 128}
358do_test update-7.5.1 {
359 execsql {SELECT * FROM test1 WHERE f1==78 ORDER BY f1,f2}
360} {78 128}
361do_test update-7.5.2 {
362 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
363} {}
364do_test update-7.5.3 {
365 execsql {SELECT * FROM test1 WHERE f1==777 ORDER BY f1,f2}
366} {777 128}
367do_test update-7.5.4 {
368 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
369} {8 88 8 128 8 256 8 888}
370do_test update-7.6 {
371 execsql {UPDATE test1 SET f1=f1-1 WHERE f1<=100 and f2==128}
372 execsql {SELECT * FROM test1 ORDER BY f1,f2}
373} {6 64 7 128 8 88 8 256 8 888 9 512 10 1024 77 128 777 128}
374do_test update-7.6.1 {
375 execsql {SELECT * FROM test1 WHERE f1==77 ORDER BY f1,f2}
376} {77 128}
377do_test update-7.6.2 {
378 execsql {SELECT * FROM test1 WHERE f1==778 ORDER BY f1,f2}
379} {}
380do_test update-7.6.3 {
381 execsql {SELECT * FROM test1 WHERE f1==777 ORDER BY f1,f2}
382} {777 128}
383do_test update-7.6.4 {
384 execsql {SELECT * FROM test1 WHERE f1==8 ORDER BY f1,f2}
385} {8 88 8 256 8 888}
drh1d37e282000-05-30 03:12:21 +0000386
drhc837e702000-06-08 16:26:24 +0000387# Error messages
388#
drh4f3c63e2001-02-19 18:24:21 +0000389do_test update-9.1 {
drhc837e702000-06-08 16:26:24 +0000390 set v [catch {execsql {
391 UPDATE test1 SET x=11 WHERE f1=1025
392 }} msg]
393 lappend v $msg
drh967e8b72000-06-21 13:59:10 +0000394} {1 {no such column: x}}
drh4f3c63e2001-02-19 18:24:21 +0000395do_test update-9.2 {
drhc837e702000-06-08 16:26:24 +0000396 set v [catch {execsql {
397 UPDATE test1 SET f1=x(11) WHERE f1=1025
398 }} msg]
399 lappend v $msg
400} {1 {no such function: x}}
drh4f3c63e2001-02-19 18:24:21 +0000401do_test update-9.3 {
drhc837e702000-06-08 16:26:24 +0000402 set v [catch {execsql {
403 UPDATE test1 SET f1=11 WHERE x=1025
404 }} msg]
405 lappend v $msg
drh967e8b72000-06-21 13:59:10 +0000406} {1 {no such column: x}}
drh4f3c63e2001-02-19 18:24:21 +0000407do_test update-9.4 {
drhc837e702000-06-08 16:26:24 +0000408 set v [catch {execsql {
409 UPDATE test1 SET f1=11 WHERE x(f1)=1025
410 }} msg]
411 lappend v $msg
412} {1 {no such function: x}}
drh1d37e282000-05-30 03:12:21 +0000413
drh79b0c952002-05-21 12:56:43 +0000414# Try doing updates on a unique column where the value does not
415# really change.
416#
417do_test update-10.1 {
418 execsql {
419 DROP TABLE test1;
420 CREATE TABLE t1(
421 a integer primary key,
422 b UNIQUE,
423 c, d,
424 e, f,
425 UNIQUE(c,d)
426 );
427 INSERT INTO t1 VALUES(1,2,3,4,5,6);
428 INSERT INTO t1 VALUES(2,3,4,4,6,7);
429 SELECT * FROM t1
430 }
431} {1 2 3 4 5 6 2 3 4 4 6 7}
432do_test update-10.2 {
433 catchsql {
434 UPDATE t1 SET a=1, e=9 WHERE f=6;
435 SELECT * FROM t1;
436 }
437} {0 {1 2 3 4 9 6 2 3 4 4 6 7}}
438do_test update-10.3 {
439 catchsql {
440 UPDATE t1 SET a=1, e=10 WHERE f=7;
441 SELECT * FROM t1;
442 }
drh483750b2003-01-29 18:46:51 +0000443} {1 {PRIMARY KEY must be unique}}
drh79b0c952002-05-21 12:56:43 +0000444do_test update-10.4 {
445 catchsql {
446 SELECT * FROM t1;
447 }
448} {0 {1 2 3 4 9 6 2 3 4 4 6 7}}
449do_test update-10.5 {
450 catchsql {
451 UPDATE t1 SET b=2, e=11 WHERE f=6;
452 SELECT * FROM t1;
453 }
454} {0 {1 2 3 4 11 6 2 3 4 4 6 7}}
455do_test update-10.6 {
456 catchsql {
457 UPDATE t1 SET b=2, e=12 WHERE f=7;
458 SELECT * FROM t1;
459 }
drh37ed48e2003-08-05 13:13:38 +0000460} {1 {column b is not unique}}
drh79b0c952002-05-21 12:56:43 +0000461do_test update-10.7 {
462 catchsql {
463 SELECT * FROM t1;
464 }
465} {0 {1 2 3 4 11 6 2 3 4 4 6 7}}
466do_test update-10.8 {
467 catchsql {
468 UPDATE t1 SET c=3, d=4, e=13 WHERE f=6;
469 SELECT * FROM t1;
470 }
471} {0 {1 2 3 4 13 6 2 3 4 4 6 7}}
472do_test update-10.9 {
473 catchsql {
474 UPDATE t1 SET c=3, d=4, e=14 WHERE f=7;
475 SELECT * FROM t1;
476 }
drh37ed48e2003-08-05 13:13:38 +0000477} {1 {columns c, d are not unique}}
drh79b0c952002-05-21 12:56:43 +0000478do_test update-10.10 {
479 catchsql {
480 SELECT * FROM t1;
481 }
482} {0 {1 2 3 4 13 6 2 3 4 4 6 7}}
drh1d37e282000-05-30 03:12:21 +0000483
drh53e3fc72002-07-16 17:22:50 +0000484# Make sure we can handle a subquery in the where clause.
485#
486do_test update-11.1 {
487 execsql {
488 UPDATE t1 SET e=e+1 WHERE b IN (SELECT b FROM t1);
489 SELECT b,e FROM t1;
490 }
491} {2 14 3 7}
492do_test update-11.2 {
493 execsql {
494 UPDATE t1 SET e=e+1 WHERE a IN (SELECT a FROM t1);
495 SELECT a,e FROM t1;
496 }
497} {1 15 2 8}
498
drhed717fe2003-06-15 23:42:24 +0000499integrity_check update-12.1
500
drh1d37e282000-05-30 03:12:21 +0000501finish_test