xref: /titanic_50/usr/src/lib/libsqlite/test/memdb.test (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
1*c5c4113dSnw141292
2*c5c4113dSnw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*c5c4113dSnw141292
4*c5c4113dSnw141292# 2001 September 15
5*c5c4113dSnw141292#
6*c5c4113dSnw141292# The author disclaims copyright to this source code.  In place of
7*c5c4113dSnw141292# a legal notice, here is a blessing:
8*c5c4113dSnw141292#
9*c5c4113dSnw141292#    May you do good and not evil.
10*c5c4113dSnw141292#    May you find forgiveness for yourself and forgive others.
11*c5c4113dSnw141292#    May you share freely, never taking more than you give.
12*c5c4113dSnw141292#
13*c5c4113dSnw141292#***********************************************************************
14*c5c4113dSnw141292# This file implements regression tests for SQLite library.  The
15*c5c4113dSnw141292# focus of this script is in-memory database backend.
16*c5c4113dSnw141292#
17*c5c4113dSnw141292# $Id: memdb.test,v 1.6 2003/08/05 13:13:39 drh Exp $
18*c5c4113dSnw141292
19*c5c4113dSnw141292
20*c5c4113dSnw141292set testdir [file dirname $argv0]
21*c5c4113dSnw141292source $testdir/tester.tcl
22*c5c4113dSnw141292
23*c5c4113dSnw141292# In the following sequence of tests, compute the MD5 sum of the content
24*c5c4113dSnw141292# of a table, make lots of modifications to that table, then do a rollback.
25*c5c4113dSnw141292# Verify that after the rollback, the MD5 checksum is unchanged.
26*c5c4113dSnw141292#
27*c5c4113dSnw141292# These tests were browed from trans.tcl.
28*c5c4113dSnw141292#
29*c5c4113dSnw141292do_test memdb-1.1 {
30*c5c4113dSnw141292  db close
31*c5c4113dSnw141292  sqlite db :memory:
32*c5c4113dSnw141292  # sqlite db test.db
33*c5c4113dSnw141292  execsql {
34*c5c4113dSnw141292    BEGIN;
35*c5c4113dSnw141292    CREATE TABLE t3(x TEXT);
36*c5c4113dSnw141292    INSERT INTO t3 VALUES(randstr(10,400));
37*c5c4113dSnw141292    INSERT INTO t3 VALUES(randstr(10,400));
38*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
39*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
40*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
41*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
42*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
43*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
44*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
45*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
46*c5c4113dSnw141292    INSERT INTO t3 SELECT randstr(10,400) FROM t3;
47*c5c4113dSnw141292    COMMIT;
48*c5c4113dSnw141292    SELECT count(*) FROM t3;
49*c5c4113dSnw141292  }
50*c5c4113dSnw141292} {1024}
51*c5c4113dSnw141292
52*c5c4113dSnw141292# The following procedure computes a "signature" for table "t3".  If
53*c5c4113dSnw141292# T3 changes in any way, the signature should change.
54*c5c4113dSnw141292#
55*c5c4113dSnw141292# This is used to test ROLLBACK.  We gather a signature for t3, then
56*c5c4113dSnw141292# make lots of changes to t3, then rollback and take another signature.
57*c5c4113dSnw141292# The two signatures should be the same.
58*c5c4113dSnw141292#
59*c5c4113dSnw141292proc signature {{fn {}}} {
60*c5c4113dSnw141292  set rx [db eval {SELECT x FROM t3}]
61*c5c4113dSnw141292  # set r1 [md5 $rx\n]
62*c5c4113dSnw141292  if {$fn!=""} {
63*c5c4113dSnw141292    # set fd [open $fn w]
64*c5c4113dSnw141292    # puts $fd $rx
65*c5c4113dSnw141292    # close $fd
66*c5c4113dSnw141292  }
67*c5c4113dSnw141292  # set r [db eval {SELECT count(*), md5sum(x) FROM t3}]
68*c5c4113dSnw141292  # puts "SIG($fn)=$r1"
69*c5c4113dSnw141292  return [list [string length $rx] $rx]
70*c5c4113dSnw141292}
71*c5c4113dSnw141292
72*c5c4113dSnw141292# Do rollbacks.  Make sure the signature does not change.
73*c5c4113dSnw141292#
74*c5c4113dSnw141292set limit 10
75*c5c4113dSnw141292for {set i 2} {$i<=$limit} {incr i} {
76*c5c4113dSnw141292  set ::sig [signature one]
77*c5c4113dSnw141292  # puts "sig=$sig"
78*c5c4113dSnw141292  set cnt [lindex $::sig 0]
79*c5c4113dSnw141292  set ::journal_format [expr {($i%3)+1}]
80*c5c4113dSnw141292  if {$i%2==0} {
81*c5c4113dSnw141292    execsql {PRAGMA synchronous=FULL}
82*c5c4113dSnw141292  } else {
83*c5c4113dSnw141292    execsql {PRAGMA synchronous=NORMAL}
84*c5c4113dSnw141292  }
85*c5c4113dSnw141292  do_test memdb-1.$i.1-$cnt {
86*c5c4113dSnw141292     execsql {
87*c5c4113dSnw141292       BEGIN;
88*c5c4113dSnw141292       DELETE FROM t3 WHERE random()%10!=0;
89*c5c4113dSnw141292       INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
90*c5c4113dSnw141292       INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
91*c5c4113dSnw141292       ROLLBACK;
92*c5c4113dSnw141292     }
93*c5c4113dSnw141292     set sig2 [signature two]
94*c5c4113dSnw141292  } $sig
95*c5c4113dSnw141292  # puts "sig2=$sig2"
96*c5c4113dSnw141292  # if {$sig2!=$sig} exit
97*c5c4113dSnw141292  do_test memdb-1.$i.2-$cnt {
98*c5c4113dSnw141292     execsql {
99*c5c4113dSnw141292       BEGIN;
100*c5c4113dSnw141292       DELETE FROM t3 WHERE random()%10!=0;
101*c5c4113dSnw141292       INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
102*c5c4113dSnw141292       DELETE FROM t3 WHERE random()%10!=0;
103*c5c4113dSnw141292       INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
104*c5c4113dSnw141292       ROLLBACK;
105*c5c4113dSnw141292     }
106*c5c4113dSnw141292     signature
107*c5c4113dSnw141292  } $sig
108*c5c4113dSnw141292  if {$i<$limit} {
109*c5c4113dSnw141292    do_test memdb-1.$i.9-$cnt {
110*c5c4113dSnw141292       execsql {
111*c5c4113dSnw141292         INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
112*c5c4113dSnw141292       }
113*c5c4113dSnw141292    } {}
114*c5c4113dSnw141292  }
115*c5c4113dSnw141292  set ::pager_old_format 0
116*c5c4113dSnw141292}
117*c5c4113dSnw141292
118*c5c4113dSnw141292do_test memdb-2.1 {
119*c5c4113dSnw141292  execsql {
120*c5c4113dSnw141292    PRAGMA integrity_check
121*c5c4113dSnw141292  }
122*c5c4113dSnw141292} {ok}
123*c5c4113dSnw141292
124*c5c4113dSnw141292do_test memdb-3.1 {
125*c5c4113dSnw141292  execsql {
126*c5c4113dSnw141292    CREATE TABLE t4(a,b,c,d);
127*c5c4113dSnw141292    BEGIN;
128*c5c4113dSnw141292    INSERT INTO t4 VALUES(1,2,3,4);
129*c5c4113dSnw141292    SELECT * FROM t4;
130*c5c4113dSnw141292  }
131*c5c4113dSnw141292} {1 2 3 4}
132*c5c4113dSnw141292do_test memdb-3.2 {
133*c5c4113dSnw141292  execsql {
134*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table';
135*c5c4113dSnw141292  }
136*c5c4113dSnw141292} {t3 t4}
137*c5c4113dSnw141292do_test memdb-3.3 {
138*c5c4113dSnw141292  execsql {
139*c5c4113dSnw141292    DROP TABLE t4;
140*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table';
141*c5c4113dSnw141292  }
142*c5c4113dSnw141292} {t3}
143*c5c4113dSnw141292do_test memdb-3.4 {
144*c5c4113dSnw141292  execsql {
145*c5c4113dSnw141292    ROLLBACK;
146*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table';
147*c5c4113dSnw141292  }
148*c5c4113dSnw141292} {t3 t4}
149*c5c4113dSnw141292
150*c5c4113dSnw141292# Create tables for the first group of tests.
151*c5c4113dSnw141292#
152*c5c4113dSnw141292do_test memdb-4.0 {
153*c5c4113dSnw141292  execsql {
154*c5c4113dSnw141292    CREATE TABLE t1(a, b, c, UNIQUE(a,b));
155*c5c4113dSnw141292    CREATE TABLE t2(x);
156*c5c4113dSnw141292    SELECT c FROM t1 ORDER BY c;
157*c5c4113dSnw141292  }
158*c5c4113dSnw141292} {}
159*c5c4113dSnw141292
160*c5c4113dSnw141292# Six columns of configuration data as follows:
161*c5c4113dSnw141292#
162*c5c4113dSnw141292#   i      The reference number of the test
163*c5c4113dSnw141292#   conf   The conflict resolution algorithm on the BEGIN statement
164*c5c4113dSnw141292#   cmd    An INSERT or REPLACE command to execute against table t1
165*c5c4113dSnw141292#   t0     True if there is an error from $cmd
166*c5c4113dSnw141292#   t1     Content of "c" column of t1 assuming no error in $cmd
167*c5c4113dSnw141292#   t2     Content of "x" column of t2
168*c5c4113dSnw141292#
169*c5c4113dSnw141292foreach {i conf cmd t0 t1 t2} {
170*c5c4113dSnw141292  1 {}       INSERT                  1 {}  1
171*c5c4113dSnw141292  2 {}       {INSERT OR IGNORE}      0 3   1
172*c5c4113dSnw141292  3 {}       {INSERT OR REPLACE}     0 4   1
173*c5c4113dSnw141292  4 {}       REPLACE                 0 4   1
174*c5c4113dSnw141292  5 {}       {INSERT OR FAIL}        1 {}  1
175*c5c4113dSnw141292  6 {}       {INSERT OR ABORT}       1 {}  1
176*c5c4113dSnw141292  7 {}       {INSERT OR ROLLBACK}    1 {}  {}
177*c5c4113dSnw141292  8 IGNORE   INSERT                  0 3   1
178*c5c4113dSnw141292  9 IGNORE   {INSERT OR IGNORE}      0 3   1
179*c5c4113dSnw141292 10 IGNORE   {INSERT OR REPLACE}     0 4   1
180*c5c4113dSnw141292 11 IGNORE   REPLACE                 0 4   1
181*c5c4113dSnw141292 12 IGNORE   {INSERT OR FAIL}        1 {}  1
182*c5c4113dSnw141292 13 IGNORE   {INSERT OR ABORT}       1 {}  1
183*c5c4113dSnw141292 14 IGNORE   {INSERT OR ROLLBACK}    1 {}  {}
184*c5c4113dSnw141292 15 REPLACE  INSERT                  0 4   1
185*c5c4113dSnw141292 16 FAIL     INSERT                  1 {}  1
186*c5c4113dSnw141292 17 ABORT    INSERT                  1 {}  1
187*c5c4113dSnw141292 18 ROLLBACK INSERT                  1 {}  {}
188*c5c4113dSnw141292} {
189*c5c4113dSnw141292  do_test memdb-4.$i {
190*c5c4113dSnw141292    if {$conf!=""} {set conf "ON CONFLICT $conf"}
191*c5c4113dSnw141292    set r0 [catch {execsql [subst {
192*c5c4113dSnw141292      DELETE FROM t1;
193*c5c4113dSnw141292      DELETE FROM t2;
194*c5c4113dSnw141292      INSERT INTO t1 VALUES(1,2,3);
195*c5c4113dSnw141292      BEGIN $conf;
196*c5c4113dSnw141292      INSERT INTO t2 VALUES(1);
197*c5c4113dSnw141292      $cmd INTO t1 VALUES(1,2,4);
198*c5c4113dSnw141292    }]} r1]
199*c5c4113dSnw141292    catch {execsql {COMMIT}}
200*c5c4113dSnw141292    if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
201*c5c4113dSnw141292    set r2 [execsql {SELECT x FROM t2}]
202*c5c4113dSnw141292    list $r0 $r1 $r2
203*c5c4113dSnw141292  } [list $t0 $t1 $t2]
204*c5c4113dSnw141292}
205*c5c4113dSnw141292
206*c5c4113dSnw141292do_test memdb-5.0 {
207*c5c4113dSnw141292  execsql {
208*c5c4113dSnw141292    DROP TABLE t2;
209*c5c4113dSnw141292    DROP TABLE t3;
210*c5c4113dSnw141292    CREATE TABLE t2(a,b,c);
211*c5c4113dSnw141292    INSERT INTO t2 VALUES(1,2,1);
212*c5c4113dSnw141292    INSERT INTO t2 VALUES(2,3,2);
213*c5c4113dSnw141292    INSERT INTO t2 VALUES(3,4,1);
214*c5c4113dSnw141292    INSERT INTO t2 VALUES(4,5,4);
215*c5c4113dSnw141292    SELECT c FROM t2 ORDER BY b;
216*c5c4113dSnw141292    CREATE TABLE t3(x);
217*c5c4113dSnw141292    INSERT INTO t3 VALUES(1);
218*c5c4113dSnw141292  }
219*c5c4113dSnw141292} {1 2 1 4}
220*c5c4113dSnw141292
221*c5c4113dSnw141292# Six columns of configuration data as follows:
222*c5c4113dSnw141292#
223*c5c4113dSnw141292#   i      The reference number of the test
224*c5c4113dSnw141292#   conf1  The conflict resolution algorithm on the UNIQUE constraint
225*c5c4113dSnw141292#   conf2  The conflict resolution algorithm on the BEGIN statement
226*c5c4113dSnw141292#   cmd    An UPDATE command to execute against table t1
227*c5c4113dSnw141292#   t0     True if there is an error from $cmd
228*c5c4113dSnw141292#   t1     Content of "b" column of t1 assuming no error in $cmd
229*c5c4113dSnw141292#   t2     Content of "x" column of t3
230*c5c4113dSnw141292#
231*c5c4113dSnw141292foreach {i conf1 conf2 cmd t0 t1 t2} {
232*c5c4113dSnw141292  1 {}       {}       UPDATE                  1 {6 7 8 9}  1
233*c5c4113dSnw141292  2 REPLACE  {}       UPDATE                  0 {7 6 9}    1
234*c5c4113dSnw141292  3 IGNORE   {}       UPDATE                  0 {6 7 3 9}  1
235*c5c4113dSnw141292  4 FAIL     {}       UPDATE                  1 {6 7 3 4}  1
236*c5c4113dSnw141292  5 ABORT    {}       UPDATE                  1 {1 2 3 4}  1
237*c5c4113dSnw141292  6 ROLLBACK {}       UPDATE                  1 {1 2 3 4}  0
238*c5c4113dSnw141292  7 REPLACE  {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
239*c5c4113dSnw141292  8 IGNORE   {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
240*c5c4113dSnw141292  9 FAIL     {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
241*c5c4113dSnw141292 10 ABORT    {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
242*c5c4113dSnw141292 11 ROLLBACK {}       {UPDATE OR IGNORE}      0 {6 7 3 9}   1
243*c5c4113dSnw141292 12 {}       {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
244*c5c4113dSnw141292 13 {}       {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
245*c5c4113dSnw141292 14 {}       {}       {UPDATE OR FAIL}        1 {6 7 3 4}  1
246*c5c4113dSnw141292 15 {}       {}       {UPDATE OR ABORT}       1 {1 2 3 4}  1
247*c5c4113dSnw141292 16 {}       {}       {UPDATE OR ROLLBACK}    1 {1 2 3 4}  0
248*c5c4113dSnw141292 17 {}       IGNORE   UPDATE                  0 {6 7 3 9}  1
249*c5c4113dSnw141292 18 {}       REPLACE  UPDATE                  0 {7 6 9}    1
250*c5c4113dSnw141292 19 {}       FAIL     UPDATE                  1 {6 7 3 4}  1
251*c5c4113dSnw141292 20 {}       ABORT    UPDATE                  1 {1 2 3 4}  1
252*c5c4113dSnw141292 21 {}       ROLLBACK UPDATE                  1 {1 2 3 4}  0
253*c5c4113dSnw141292 22 REPLACE  IGNORE   UPDATE                  0 {6 7 3 9}  1
254*c5c4113dSnw141292 23 IGNORE   REPLACE  UPDATE                  0 {7 6 9}    1
255*c5c4113dSnw141292 24 REPLACE  FAIL     UPDATE                  1 {6 7 3 4}  1
256*c5c4113dSnw141292 25 IGNORE   ABORT    UPDATE                  1 {1 2 3 4}  1
257*c5c4113dSnw141292 26 REPLACE  ROLLBACK UPDATE                  1 {1 2 3 4}  0
258*c5c4113dSnw141292} {
259*c5c4113dSnw141292  if {$t0} {set t1 {column a is not unique}}
260*c5c4113dSnw141292  do_test memdb-5.$i {
261*c5c4113dSnw141292    if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
262*c5c4113dSnw141292    if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
263*c5c4113dSnw141292    set r0 [catch {execsql [subst {
264*c5c4113dSnw141292      DROP TABLE t1;
265*c5c4113dSnw141292      CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
266*c5c4113dSnw141292      INSERT INTO t1 SELECT * FROM t2;
267*c5c4113dSnw141292      UPDATE t3 SET x=0;
268*c5c4113dSnw141292      BEGIN $conf2;
269*c5c4113dSnw141292      $cmd t3 SET x=1;
270*c5c4113dSnw141292      $cmd t1 SET b=b*2;
271*c5c4113dSnw141292      $cmd t1 SET a=c+5;
272*c5c4113dSnw141292    }]} r1]
273*c5c4113dSnw141292    catch {execsql {COMMIT}}
274*c5c4113dSnw141292    if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
275*c5c4113dSnw141292    set r2 [execsql {SELECT x FROM t3}]
276*c5c4113dSnw141292    list $r0 $r1 $r2
277*c5c4113dSnw141292  } [list $t0 $t1 $t2]
278*c5c4113dSnw141292}
279*c5c4113dSnw141292
280*c5c4113dSnw141292do_test memdb-6.1 {
281*c5c4113dSnw141292  execsql {
282*c5c4113dSnw141292    SELECT * FROM t2;
283*c5c4113dSnw141292  }
284*c5c4113dSnw141292} {1 2 1 2 3 2 3 4 1 4 5 4}
285*c5c4113dSnw141292do_test memdb-6.2 {
286*c5c4113dSnw141292  execsql {
287*c5c4113dSnw141292    BEGIN;
288*c5c4113dSnw141292    DROP TABLE t2;
289*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
290*c5c4113dSnw141292  }
291*c5c4113dSnw141292} {t1 t3 t4}
292*c5c4113dSnw141292do_test memdb-6.3 {
293*c5c4113dSnw141292  execsql {
294*c5c4113dSnw141292    ROLLBACK;
295*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
296*c5c4113dSnw141292  }
297*c5c4113dSnw141292} {t1 t2 t3 t4}
298*c5c4113dSnw141292do_test memdb-6.4 {
299*c5c4113dSnw141292  execsql {
300*c5c4113dSnw141292    SELECT * FROM t2;
301*c5c4113dSnw141292  }
302*c5c4113dSnw141292} {1 2 1 2 3 2 3 4 1 4 5 4}
303*c5c4113dSnw141292do_test memdb-6.5 {
304*c5c4113dSnw141292  execsql {
305*c5c4113dSnw141292    SELECT a FROM t2 UNION SELECT b FROM t2 ORDER BY 1;
306*c5c4113dSnw141292  }
307*c5c4113dSnw141292} {1 2 3 4 5}
308*c5c4113dSnw141292do_test memdb-6.6 {
309*c5c4113dSnw141292  execsql {
310*c5c4113dSnw141292    CREATE INDEX i2 ON t2(c);
311*c5c4113dSnw141292    SELECT a FROM t2 ORDER BY c;
312*c5c4113dSnw141292  }
313*c5c4113dSnw141292} {1 3 2 4}
314*c5c4113dSnw141292do_test memdb-6.6 {
315*c5c4113dSnw141292  execsql {
316*c5c4113dSnw141292    SELECT a FROM t2 ORDER BY c DESC;
317*c5c4113dSnw141292  }
318*c5c4113dSnw141292} {4 2 3 1}
319*c5c4113dSnw141292do_test memdb-6.7 {
320*c5c4113dSnw141292  execsql {
321*c5c4113dSnw141292    BEGIN;
322*c5c4113dSnw141292    CREATE TABLE t5(x,y);
323*c5c4113dSnw141292    INSERT INTO t5 VALUES(1,2);
324*c5c4113dSnw141292    SELECT * FROM t5;
325*c5c4113dSnw141292  }
326*c5c4113dSnw141292} {1 2}
327*c5c4113dSnw141292do_test memdb-6.8 {
328*c5c4113dSnw141292  execsql {
329*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
330*c5c4113dSnw141292  }
331*c5c4113dSnw141292} {t1 t2 t3 t4 t5}
332*c5c4113dSnw141292do_test memdb-6.9 {
333*c5c4113dSnw141292  execsql {
334*c5c4113dSnw141292    ROLLBACK;
335*c5c4113dSnw141292    SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
336*c5c4113dSnw141292  }
337*c5c4113dSnw141292} {t1 t2 t3 t4}
338*c5c4113dSnw141292do_test memdb-6.10 {
339*c5c4113dSnw141292  execsql {
340*c5c4113dSnw141292    CREATE TABLE t5(x PRIMARY KEY, y UNIQUE);
341*c5c4113dSnw141292    SELECT * FROM t5;
342*c5c4113dSnw141292  }
343*c5c4113dSnw141292} {}
344*c5c4113dSnw141292do_test memdb-6.11 {
345*c5c4113dSnw141292  execsql {
346*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY y DESC;
347*c5c4113dSnw141292  }
348*c5c4113dSnw141292} {}
349*c5c4113dSnw141292do_test memdb-6.12 {
350*c5c4113dSnw141292  execsql {
351*c5c4113dSnw141292    INSERT INTO t5 VALUES(1,2);
352*c5c4113dSnw141292    INSERT INTO t5 VALUES(3,4);
353*c5c4113dSnw141292    REPLACE INTO t5 VALUES(1,4);
354*c5c4113dSnw141292    SELECT rowid,* FROM t5;
355*c5c4113dSnw141292  }
356*c5c4113dSnw141292} {3 1 4}
357*c5c4113dSnw141292do_test memdb-6.13 {
358*c5c4113dSnw141292  execsql {
359*c5c4113dSnw141292    DELETE FROM t5 WHERE x>5;
360*c5c4113dSnw141292    SELECT * FROM t5;
361*c5c4113dSnw141292  }
362*c5c4113dSnw141292} {1 4}
363*c5c4113dSnw141292do_test memdb-6.14 {
364*c5c4113dSnw141292  execsql {
365*c5c4113dSnw141292    DELETE FROM t5 WHERE y<3;
366*c5c4113dSnw141292    SELECT * FROM t5;
367*c5c4113dSnw141292  }
368*c5c4113dSnw141292} {1 4}
369*c5c4113dSnw141292do_test memdb-6.15 {
370*c5c4113dSnw141292  execsql {
371*c5c4113dSnw141292    DELETE FROM t5 WHERE x>0;
372*c5c4113dSnw141292    SELECT * FROM t5;
373*c5c4113dSnw141292  }
374*c5c4113dSnw141292} {}
375*c5c4113dSnw141292
376*c5c4113dSnw141292do_test memdb-7.1 {
377*c5c4113dSnw141292  execsql {
378*c5c4113dSnw141292    CREATE TABLE t6(x);
379*c5c4113dSnw141292    INSERT INTO t6 VALUES(1);
380*c5c4113dSnw141292    INSERT INTO t6 SELECT x+1 FROM t6;
381*c5c4113dSnw141292    INSERT INTO t6 SELECT x+2 FROM t6;
382*c5c4113dSnw141292    INSERT INTO t6 SELECT x+4 FROM t6;
383*c5c4113dSnw141292    INSERT INTO t6 SELECT x+8 FROM t6;
384*c5c4113dSnw141292    INSERT INTO t6 SELECT x+16 FROM t6;
385*c5c4113dSnw141292    INSERT INTO t6 SELECT x+32 FROM t6;
386*c5c4113dSnw141292    INSERT INTO t6 SELECT x+64 FROM t6;
387*c5c4113dSnw141292    INSERT INTO t6 SELECT x+128 FROM t6;
388*c5c4113dSnw141292    SELECT count(*) FROM (SELECT DISTINCT x FROM t6);
389*c5c4113dSnw141292  }
390*c5c4113dSnw141292} {256}
391*c5c4113dSnw141292for {set i 1} {$i<=256} {incr i} {
392*c5c4113dSnw141292  do_test memdb-7.2.$i {
393*c5c4113dSnw141292     execsql "DELETE FROM t6 WHERE x=\
394*c5c4113dSnw141292              (SELECT x FROM t6 ORDER BY random() LIMIT 1)"
395*c5c4113dSnw141292     execsql {SELECT count(*) FROM t6}
396*c5c4113dSnw141292  } [expr {256-$i}]
397*c5c4113dSnw141292}
398*c5c4113dSnw141292
399*c5c4113dSnw141292finish_test
400