xref: /onnv-gate/usr/src/lib/libsqlite/test/misc1.test (revision 4520:7dbeadedd7fe)
1*4520Snw141292
2*4520Snw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*4520Snw141292
4*4520Snw141292# 2001 September 15
5*4520Snw141292#
6*4520Snw141292# The author disclaims copyright to this source code.  In place of
7*4520Snw141292# a legal notice, here is a blessing:
8*4520Snw141292#
9*4520Snw141292#    May you do good and not evil.
10*4520Snw141292#    May you find forgiveness for yourself and forgive others.
11*4520Snw141292#    May you share freely, never taking more than you give.
12*4520Snw141292#
13*4520Snw141292#***********************************************************************
14*4520Snw141292# This file implements regression tests for SQLite library.
15*4520Snw141292#
16*4520Snw141292# This file implements tests for miscellanous features that were
17*4520Snw141292# left out of other test files.
18*4520Snw141292#
19*4520Snw141292# $Id: misc1.test,v 1.23 2003/08/05 13:13:39 drh Exp $
20*4520Snw141292
21*4520Snw141292set testdir [file dirname $argv0]
22*4520Snw141292source $testdir/tester.tcl
23*4520Snw141292
24*4520Snw141292# Test the creation and use of tables that have a large number
25*4520Snw141292# of columns.
26*4520Snw141292#
27*4520Snw141292do_test misc1-1.1 {
28*4520Snw141292  set cmd "CREATE TABLE manycol(x0 text"
29*4520Snw141292  for {set i 1} {$i<=99} {incr i} {
30*4520Snw141292    append cmd ",x$i text"
31*4520Snw141292  }
32*4520Snw141292  append cmd ")";
33*4520Snw141292  execsql $cmd
34*4520Snw141292  set cmd "INSERT INTO manycol VALUES(0"
35*4520Snw141292  for {set i 1} {$i<=99} {incr i} {
36*4520Snw141292    append cmd ",$i"
37*4520Snw141292  }
38*4520Snw141292  append cmd ")";
39*4520Snw141292  execsql $cmd
40*4520Snw141292  execsql "SELECT x99 FROM manycol"
41*4520Snw141292} 99
42*4520Snw141292do_test misc1-1.2 {
43*4520Snw141292  execsql {SELECT x0, x10, x25, x50, x75 FROM manycol}
44*4520Snw141292} {0 10 25 50 75}
45*4520Snw141292do_test misc1-1.3.1 {
46*4520Snw141292  for {set j 100} {$j<=1000} {incr j 100} {
47*4520Snw141292    set cmd "INSERT INTO manycol VALUES($j"
48*4520Snw141292    for {set i 1} {$i<=99} {incr i} {
49*4520Snw141292      append cmd ",[expr {$i+$j}]"
50*4520Snw141292    }
51*4520Snw141292    append cmd ")"
52*4520Snw141292    execsql $cmd
53*4520Snw141292  }
54*4520Snw141292  execsql {SELECT x50 FROM manycol ORDER BY x80+0}
55*4520Snw141292} {50 150 250 350 450 550 650 750 850 950 1050}
56*4520Snw141292do_test misc1-1.3.2 {
57*4520Snw141292  execsql {SELECT x50 FROM manycol ORDER BY x80}
58*4520Snw141292} {1050 150 250 350 450 550 650 750 50 850 950}
59*4520Snw141292do_test misc1-1.4 {
60*4520Snw141292  execsql {SELECT x75 FROM manycol WHERE x50=350}
61*4520Snw141292} 375
62*4520Snw141292do_test misc1-1.5 {
63*4520Snw141292  execsql {SELECT x50 FROM manycol WHERE x99=599}
64*4520Snw141292} 550
65*4520Snw141292do_test misc1-1.6 {
66*4520Snw141292  execsql {CREATE INDEX manycol_idx1 ON manycol(x99)}
67*4520Snw141292  execsql {SELECT x50 FROM manycol WHERE x99=899}
68*4520Snw141292} 850
69*4520Snw141292do_test misc1-1.7 {
70*4520Snw141292  execsql {SELECT count(*) FROM manycol}
71*4520Snw141292} 11
72*4520Snw141292do_test misc1-1.8 {
73*4520Snw141292  execsql {DELETE FROM manycol WHERE x98=1234}
74*4520Snw141292  execsql {SELECT count(*) FROM manycol}
75*4520Snw141292} 11
76*4520Snw141292do_test misc1-1.9 {
77*4520Snw141292  execsql {DELETE FROM manycol WHERE x98=998}
78*4520Snw141292  execsql {SELECT count(*) FROM manycol}
79*4520Snw141292} 10
80*4520Snw141292do_test misc1-1.10 {
81*4520Snw141292  execsql {DELETE FROM manycol WHERE x99=500}
82*4520Snw141292  execsql {SELECT count(*) FROM manycol}
83*4520Snw141292} 10
84*4520Snw141292do_test misc1-1.11 {
85*4520Snw141292  execsql {DELETE FROM manycol WHERE x99=599}
86*4520Snw141292  execsql {SELECT count(*) FROM manycol}
87*4520Snw141292} 9
88*4520Snw141292
89*4520Snw141292# Check GROUP BY expressions that name two or more columns.
90*4520Snw141292#
91*4520Snw141292do_test misc1-2.1 {
92*4520Snw141292  execsql {
93*4520Snw141292    BEGIN TRANSACTION;
94*4520Snw141292    CREATE TABLE agger(one text, two text, three text, four text);
95*4520Snw141292    INSERT INTO agger VALUES(1, 'one', 'hello', 'yes');
96*4520Snw141292    INSERT INTO agger VALUES(2, 'two', 'howdy', 'no');
97*4520Snw141292    INSERT INTO agger VALUES(3, 'thr', 'howareya', 'yes');
98*4520Snw141292    INSERT INTO agger VALUES(4, 'two', 'lothere', 'yes');
99*4520Snw141292    INSERT INTO agger VALUES(5, 'one', 'atcha', 'yes');
100*4520Snw141292    INSERT INTO agger VALUES(6, 'two', 'hello', 'no');
101*4520Snw141292    COMMIT
102*4520Snw141292  }
103*4520Snw141292  execsql {SELECT count(*) FROM agger}
104*4520Snw141292} 6
105*4520Snw141292do_test misc1-2.2 {
106*4520Snw141292  execsql {SELECT sum(one), two, four FROM agger
107*4520Snw141292           GROUP BY two, four ORDER BY sum(one) desc}
108*4520Snw141292} {8 two no 6 one yes 4 two yes 3 thr yes}
109*4520Snw141292do_test misc1-2.3 {
110*4520Snw141292  execsql {SELECT sum((one)), (two), (four) FROM agger
111*4520Snw141292           GROUP BY (two), (four) ORDER BY sum(one) desc}
112*4520Snw141292} {8 two no 6 one yes 4 two yes 3 thr yes}
113*4520Snw141292
114*4520Snw141292# Here's a test for a bug found by Joel Lucsy.  The code below
115*4520Snw141292# was causing an assertion failure.
116*4520Snw141292#
117*4520Snw141292do_test misc1-3.1 {
118*4520Snw141292  set r [execsql {
119*4520Snw141292    CREATE TABLE t1(a);
120*4520Snw141292    INSERT INTO t1 VALUES('hi');
121*4520Snw141292    PRAGMA full_column_names=on;
122*4520Snw141292    SELECT rowid, * FROM t1;
123*4520Snw141292  }]
124*4520Snw141292  lindex $r 1
125*4520Snw141292} {hi}
126*4520Snw141292
127*4520Snw141292# Here's a test for yet another bug found by Joel Lucsy.  The code
128*4520Snw141292# below was causing an assertion failure.
129*4520Snw141292#
130*4520Snw141292do_test misc1-4.1 {
131*4520Snw141292  execsql {
132*4520Snw141292    BEGIN;
133*4520Snw141292    CREATE TABLE t2(a);
134*4520Snw141292    INSERT INTO t2 VALUES('This is a long string to use up a lot of disk -');
135*4520Snw141292    UPDATE t2 SET a=a||a||a||a;
136*4520Snw141292    INSERT INTO t2 SELECT '1 - ' || a FROM t2;
137*4520Snw141292    INSERT INTO t2 SELECT '2 - ' || a FROM t2;
138*4520Snw141292    INSERT INTO t2 SELECT '3 - ' || a FROM t2;
139*4520Snw141292    INSERT INTO t2 SELECT '4 - ' || a FROM t2;
140*4520Snw141292    INSERT INTO t2 SELECT '5 - ' || a FROM t2;
141*4520Snw141292    INSERT INTO t2 SELECT '6 - ' || a FROM t2;
142*4520Snw141292    COMMIT;
143*4520Snw141292    SELECT count(*) FROM t2;
144*4520Snw141292  }
145*4520Snw141292} {64}
146*4520Snw141292
147*4520Snw141292# Make sure we actually see a semicolon or end-of-file in the SQL input
148*4520Snw141292# before executing a command.  Thus if "WHERE" is misspelled on an UPDATE,
149*4520Snw141292# the user won't accidently update every record.
150*4520Snw141292#
151*4520Snw141292do_test misc1-5.1 {
152*4520Snw141292  catchsql {
153*4520Snw141292    CREATE TABLE t3(a,b);
154*4520Snw141292    INSERT INTO t3 VALUES(1,2);
155*4520Snw141292    INSERT INTO t3 VALUES(3,4);
156*4520Snw141292    UPDATE t3 SET a=0 WHEREwww b=2;
157*4520Snw141292  }
158*4520Snw141292} {1 {near "WHEREwww": syntax error}}
159*4520Snw141292do_test misc1-5.2 {
160*4520Snw141292  execsql {
161*4520Snw141292    SELECT * FROM t3 ORDER BY a;
162*4520Snw141292  }
163*4520Snw141292} {1 2 3 4}
164*4520Snw141292
165*4520Snw141292# Certain keywords (especially non-standard keywords like "REPLACE") can
166*4520Snw141292# also be used as identifiers.  The way this works in the parser is that
167*4520Snw141292# the parser first detects a syntax error, the error handling routine
168*4520Snw141292# sees that the special keyword caused the error, then replaces the keyword
169*4520Snw141292# with "ID" and tries again.
170*4520Snw141292#
171*4520Snw141292# Check the operation of this logic.
172*4520Snw141292#
173*4520Snw141292do_test misc1-6.1 {
174*4520Snw141292  catchsql {
175*4520Snw141292    CREATE TABLE t4(
176*4520Snw141292      abort, asc, begin, cluster, conflict, copy, delimiters, desc, end,
177*4520Snw141292      explain, fail, ignore, key, offset, pragma, replace, temp,
178*4520Snw141292      vacuum, view
179*4520Snw141292    );
180*4520Snw141292  }
181*4520Snw141292} {0 {}}
182*4520Snw141292do_test misc1-6.2 {
183*4520Snw141292  catchsql {
184*4520Snw141292    INSERT INTO t4
185*4520Snw141292       VALUES(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
186*4520Snw141292  }
187*4520Snw141292} {0 {}}
188*4520Snw141292do_test misc1-6.3 {
189*4520Snw141292  execsql {
190*4520Snw141292    SELECT * FROM t4
191*4520Snw141292  }
192*4520Snw141292} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19}
193*4520Snw141292do_test misc1-6.4 {
194*4520Snw141292  execsql {
195*4520Snw141292    SELECT abort+asc,max(key,pragma,temp) FROM t4
196*4520Snw141292  }
197*4520Snw141292} {3 17}
198*4520Snw141292
199*4520Snw141292# Test for multi-column primary keys, and for multiple primary keys.
200*4520Snw141292#
201*4520Snw141292do_test misc1-7.1 {
202*4520Snw141292  catchsql {
203*4520Snw141292    CREATE TABLE error1(
204*4520Snw141292      a TYPE PRIMARY KEY,
205*4520Snw141292      b TYPE PRIMARY KEY
206*4520Snw141292    );
207*4520Snw141292  }
208*4520Snw141292} {1 {table "error1" has more than one primary key}}
209*4520Snw141292do_test misc1-7.2 {
210*4520Snw141292  catchsql {
211*4520Snw141292    CREATE TABLE error1(
212*4520Snw141292      a INTEGER PRIMARY KEY,
213*4520Snw141292      b TYPE PRIMARY KEY
214*4520Snw141292    );
215*4520Snw141292  }
216*4520Snw141292} {1 {table "error1" has more than one primary key}}
217*4520Snw141292do_test misc1-7.3 {
218*4520Snw141292  execsql {
219*4520Snw141292    CREATE TABLE t5(a,b,c,PRIMARY KEY(a,b));
220*4520Snw141292    INSERT INTO t5 VALUES(1,2,3);
221*4520Snw141292    SELECT * FROM t5 ORDER BY a;
222*4520Snw141292  }
223*4520Snw141292} {1 2 3}
224*4520Snw141292do_test misc1-7.4 {
225*4520Snw141292  catchsql {
226*4520Snw141292    INSERT INTO t5 VALUES(1,2,4);
227*4520Snw141292  }
228*4520Snw141292} {1 {columns a, b are not unique}}
229*4520Snw141292do_test misc1-7.5 {
230*4520Snw141292  catchsql {
231*4520Snw141292    INSERT INTO t5 VALUES(0,2,4);
232*4520Snw141292  }
233*4520Snw141292} {0 {}}
234*4520Snw141292do_test misc1-7.6 {
235*4520Snw141292  execsql {
236*4520Snw141292    SELECT * FROM t5 ORDER BY a;
237*4520Snw141292  }
238*4520Snw141292} {0 2 4 1 2 3}
239*4520Snw141292
240*4520Snw141292do_test misc1-8.1 {
241*4520Snw141292  catchsql {
242*4520Snw141292    SELECT *;
243*4520Snw141292  }
244*4520Snw141292} {1 {no tables specified}}
245*4520Snw141292do_test misc1-8.2 {
246*4520Snw141292  catchsql {
247*4520Snw141292    SELECT t1.*;
248*4520Snw141292  }
249*4520Snw141292} {1 {no such table: t1}}
250*4520Snw141292
251*4520Snw141292execsql {
252*4520Snw141292  DROP TABLE t1;
253*4520Snw141292  DROP TABLE t2;
254*4520Snw141292  DROP TABLE t3;
255*4520Snw141292  DROP TABLE t4;
256*4520Snw141292}
257*4520Snw141292
258*4520Snw141292# If an integer is too big to be represented as a 32-bit machine integer,
259*4520Snw141292# then treat it as a string.
260*4520Snw141292#
261*4520Snw141292do_test misc1-9.1 {
262*4520Snw141292  catchsql {
263*4520Snw141292    CREATE TABLE t1(a unique not null, b unique not null);
264*4520Snw141292    INSERT INTO t1 VALUES('a',12345678901234567890);
265*4520Snw141292    INSERT INTO t1 VALUES('b',12345678911234567890);
266*4520Snw141292    INSERT INTO t1 VALUES('c',12345678921234567890);
267*4520Snw141292    SELECT * FROM t1;
268*4520Snw141292  }
269*4520Snw141292} {0 {a 12345678901234567890 b 12345678911234567890 c 12345678921234567890}}
270*4520Snw141292
271*4520Snw141292# A WHERE clause is not allowed to contain more than 99 terms.  Check to
272*4520Snw141292# make sure this limit is enforced.
273*4520Snw141292#
274*4520Snw141292do_test misc1-10.0 {
275*4520Snw141292  execsql {SELECT count(*) FROM manycol}
276*4520Snw141292} {9}
277*4520Snw141292do_test misc1-10.1 {
278*4520Snw141292  set ::where {WHERE x0>=0}
279*4520Snw141292  for {set i 1} {$i<=99} {incr i} {
280*4520Snw141292    append ::where " AND x$i<>0"
281*4520Snw141292  }
282*4520Snw141292  catchsql "SELECT count(*) FROM manycol $::where"
283*4520Snw141292} {0 9}
284*4520Snw141292do_test misc1-10.2 {
285*4520Snw141292  catchsql "SELECT count(*) FROM manycol $::where AND rowid>0"
286*4520Snw141292} {1 {WHERE clause too complex - no more than 100 terms allowed}}
287*4520Snw141292do_test misc1-10.3 {
288*4520Snw141292  regsub "x0>=0" $::where "x0=0" ::where
289*4520Snw141292  catchsql "DELETE FROM manycol $::where"
290*4520Snw141292} {0 {}}
291*4520Snw141292do_test misc1-10.4 {
292*4520Snw141292  execsql {SELECT count(*) FROM manycol}
293*4520Snw141292} {8}
294*4520Snw141292do_test misc1-10.5 {
295*4520Snw141292  catchsql "DELETE FROM manycol $::where AND rowid>0"
296*4520Snw141292} {1 {WHERE clause too complex - no more than 100 terms allowed}}
297*4520Snw141292do_test misc1-10.6 {
298*4520Snw141292  execsql {SELECT x1 FROM manycol WHERE x0=100}
299*4520Snw141292} {101}
300*4520Snw141292do_test misc1-10.7 {
301*4520Snw141292  regsub "x0=0" $::where "x0=100" ::where
302*4520Snw141292  catchsql "UPDATE manycol SET x1=x1+1 $::where"
303*4520Snw141292} {0 {}}
304*4520Snw141292do_test misc1-10.8 {
305*4520Snw141292  execsql {SELECT x1 FROM manycol WHERE x0=100}
306*4520Snw141292} {102}
307*4520Snw141292do_test misc1-10.9 {
308*4520Snw141292  catchsql "UPDATE manycol SET x1=x1+1 $::where AND rowid>0"
309*4520Snw141292} {1 {WHERE clause too complex - no more than 100 terms allowed}}
310*4520Snw141292do_test misc1-10.10 {
311*4520Snw141292  execsql {SELECT x1 FROM manycol WHERE x0=100}
312*4520Snw141292} {102}
313*4520Snw141292
314*4520Snw141292# Make sure the initialization works even if a database is opened while
315*4520Snw141292# another process has the database locked.
316*4520Snw141292#
317*4520Snw141292do_test misc1-11.1 {
318*4520Snw141292  execsql {BEGIN}
319*4520Snw141292  sqlite db2 test.db
320*4520Snw141292  set rc [catch {db2 eval {SELECT count(*) FROM t1}} msg]
321*4520Snw141292  lappend rc $msg
322*4520Snw141292} {1 {database is locked}}
323*4520Snw141292do_test misc1-11.2 {
324*4520Snw141292  execsql {COMMIT}
325*4520Snw141292  set rc [catch {db2 eval {SELECT count(*) FROM t1}} msg]
326*4520Snw141292  db2 close
327*4520Snw141292  lappend rc $msg
328*4520Snw141292} {0 3}
329*4520Snw141292
330*4520Snw141292# Make sure string comparisons really do compare strings in format4+.
331*4520Snw141292# Similar tests in the format3.test file show that for format3 and earlier
332*4520Snw141292# all comparisions where numeric if either operand looked like a number.
333*4520Snw141292#
334*4520Snw141292do_test misc1-12.1 {
335*4520Snw141292  execsql {SELECT '0'=='0.0'}
336*4520Snw141292} {0}
337*4520Snw141292do_test misc1-12.2 {
338*4520Snw141292  execsql {SELECT '0'==0.0}
339*4520Snw141292} {1}
340*4520Snw141292do_test misc1-12.3 {
341*4520Snw141292  execsql {SELECT '12345678901234567890'=='12345678901234567891'}
342*4520Snw141292} {0}
343*4520Snw141292do_test misc1-12.4 {
344*4520Snw141292  execsql {
345*4520Snw141292    CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
346*4520Snw141292    INSERT INTO t6 VALUES('0','0.0');
347*4520Snw141292    SELECT * FROM t6;
348*4520Snw141292  }
349*4520Snw141292} {0 0.0}
350*4520Snw141292do_test misc1-12.5 {
351*4520Snw141292  execsql {
352*4520Snw141292    INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
353*4520Snw141292    SELECT * FROM t6;
354*4520Snw141292  }
355*4520Snw141292} {0 0.0}
356*4520Snw141292do_test misc1-12.6 {
357*4520Snw141292  execsql {
358*4520Snw141292    INSERT OR IGNORE INTO t6 VALUES('y',0);
359*4520Snw141292    SELECT * FROM t6;
360*4520Snw141292  }
361*4520Snw141292} {0 0.0 y 0}
362*4520Snw141292do_test misc1-12.7 {
363*4520Snw141292  execsql {
364*4520Snw141292    CREATE TABLE t7(x INTEGER, y TEXT, z);
365*4520Snw141292    INSERT INTO t7 VALUES(0,0,1);
366*4520Snw141292    INSERT INTO t7 VALUES(0.0,0,2);
367*4520Snw141292    INSERT INTO t7 VALUES(0,0.0,3);
368*4520Snw141292    INSERT INTO t7 VALUES(0.0,0.0,4);
369*4520Snw141292    SELECT DISTINCT x, y FROM t7 ORDER BY z;
370*4520Snw141292  }
371*4520Snw141292} {0 0 0 0.0}
372*4520Snw141292do_test misc1-12.8 {
373*4520Snw141292  execsql {
374*4520Snw141292    SELECT min(z), max(z), count(z) FROM t7 GROUP BY x ORDER BY 1;
375*4520Snw141292  }
376*4520Snw141292} {1 4 4}
377*4520Snw141292do_test misc1-12.9 {
378*4520Snw141292  execsql {
379*4520Snw141292    SELECT min(z), max(z), count(z) FROM t7 GROUP BY y ORDER BY 1;
380*4520Snw141292  }
381*4520Snw141292} {1 2 2 3 4 2}
382*4520Snw141292
383*4520Snw141292# This used to be an error.  But we changed the code so that arbitrary
384*4520Snw141292# identifiers can be used as a collating sequence.  Collation is by text
385*4520Snw141292# if the identifier contains "text", "blob", or "clob" and is numeric
386*4520Snw141292# otherwise.
387*4520Snw141292do_test misc1-12.10 {
388*4520Snw141292  catchsql {
389*4520Snw141292    SELECT * FROM t6 ORDER BY a COLLATE unknown;
390*4520Snw141292  }
391*4520Snw141292} {0 {0 0.0 y 0}}
392*4520Snw141292do_test misc1-12.11 {
393*4520Snw141292  execsql {
394*4520Snw141292    CREATE TABLE t8(x TEXT COLLATE numeric, y INTEGER COLLATE text, z);
395*4520Snw141292    INSERT INTO t8 VALUES(0,0,1);
396*4520Snw141292    INSERT INTO t8 VALUES(0.0,0,2);
397*4520Snw141292    INSERT INTO t8 VALUES(0,0.0,3);
398*4520Snw141292    INSERT INTO t8 VALUES(0.0,0.0,4);
399*4520Snw141292    SELECT DISTINCT x, y FROM t8 ORDER BY z;
400*4520Snw141292  }
401*4520Snw141292} {0 0 0 0.0}
402*4520Snw141292do_test misc1-12.12 {
403*4520Snw141292  execsql {
404*4520Snw141292    SELECT min(z), max(z), count(z) FROM t8 GROUP BY x ORDER BY 1;
405*4520Snw141292  }
406*4520Snw141292} {1 4 4}
407*4520Snw141292do_test misc1-12.13 {
408*4520Snw141292  execsql {
409*4520Snw141292    SELECT min(z), max(z), count(z) FROM t8 GROUP BY y ORDER BY 1;
410*4520Snw141292  }
411*4520Snw141292} {1 2 2 3 4 2}
412*4520Snw141292
413*4520Snw141292# There was a problem with realloc() in the OP_MemStore operation of
414*4520Snw141292# the VDBE.  A buffer was being reallocated but some pointers into
415*4520Snw141292# the old copy of the buffer were not being moved over to the new copy.
416*4520Snw141292# The following code tests for the problem.
417*4520Snw141292#
418*4520Snw141292do_test misc1-13.1 {
419*4520Snw141292   execsql {
420*4520Snw141292     CREATE TABLE t9(x,y);
421*4520Snw141292     INSERT INTO t9 VALUES('one',1);
422*4520Snw141292     INSERT INTO t9 VALUES('two',2);
423*4520Snw141292     INSERT INTO t9 VALUES('three',3);
424*4520Snw141292     INSERT INTO t9 VALUES('four',4);
425*4520Snw141292     INSERT INTO t9 VALUES('five',5);
426*4520Snw141292     INSERT INTO t9 VALUES('six',6);
427*4520Snw141292     INSERT INTO t9 VALUES('seven',7);
428*4520Snw141292     INSERT INTO t9 VALUES('eight',8);
429*4520Snw141292     INSERT INTO t9 VALUES('nine',9);
430*4520Snw141292     INSERT INTO t9 VALUES('ten',10);
431*4520Snw141292     INSERT INTO t9 VALUES('eleven',11);
432*4520Snw141292     SELECT y FROM t9
433*4520Snw141292     WHERE x=(SELECT x FROM t9 WHERE y=1)
434*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=2)
435*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=3)
436*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=4)
437*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=5)
438*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=6)
439*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=7)
440*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=8)
441*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=9)
442*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=10)
443*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=11)
444*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=12)
445*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=13)
446*4520Snw141292        OR x=(SELECT x FROM t9 WHERE y=14)
447*4520Snw141292     ;
448*4520Snw141292   }
449*4520Snw141292} {1 2 3 4 5 6 7 8 9 10 11}
450*4520Snw141292
451*4520Snw141292# Make sure a database connection still works after changing the
452*4520Snw141292# working directory.
453*4520Snw141292#
454*4520Snw141292do_test misc1-14.1 {
455*4520Snw141292  file mkdir tempdir
456*4520Snw141292  cd tempdir
457*4520Snw141292  execsql {BEGIN}
458*4520Snw141292  file exists ./test.db-journal
459*4520Snw141292} {0}
460*4520Snw141292do_test misc1-14.2 {
461*4520Snw141292  file exists ../test.db-journal
462*4520Snw141292} {1}
463*4520Snw141292do_test misc1-14.3 {
464*4520Snw141292  cd ..
465*4520Snw141292  file delete tempdir
466*4520Snw141292  execsql {COMMIT}
467*4520Snw141292  file exists ./test.db-journal
468*4520Snw141292} {0}
469*4520Snw141292
470*4520Snw141292# A failed create table should not leave the table in the internal
471*4520Snw141292# data structures.  Ticket #238.
472*4520Snw141292#
473*4520Snw141292do_test misc1-15.1 {
474*4520Snw141292  catchsql {
475*4520Snw141292    CREATE TABLE t10 AS SELECT c1;
476*4520Snw141292  }
477*4520Snw141292} {1 {no such column: c1}}
478*4520Snw141292do_test misc1-15.2 {
479*4520Snw141292  catchsql {
480*4520Snw141292    CREATE TABLE t10 AS SELECT 1;
481*4520Snw141292  }
482*4520Snw141292  # The bug in ticket #238 causes the statement above to fail with
483*4520Snw141292  # the error "table t10 alread exists"
484*4520Snw141292} {0 {}}
485*4520Snw141292
486*4520Snw141292# Test for memory leaks when a CREATE TABLE containing a primary key
487*4520Snw141292# fails.  Ticket #249.
488*4520Snw141292#
489*4520Snw141292do_test misc1-16.1 {
490*4520Snw141292  catchsql {SELECT name FROM sqlite_master LIMIT 1}
491*4520Snw141292  catchsql {
492*4520Snw141292    CREATE TABLE test(a integer, primary key(a));
493*4520Snw141292  }
494*4520Snw141292} {0 {}}
495*4520Snw141292do_test misc1-16.2 {
496*4520Snw141292  catchsql {
497*4520Snw141292    CREATE TABLE test(a integer, primary key(a));
498*4520Snw141292  }
499*4520Snw141292} {1 {table test already exists}}
500*4520Snw141292do_test misc1-16.3 {
501*4520Snw141292  catchsql {
502*4520Snw141292    CREATE TABLE test2(a text primary key, b text, primary key(a,b));
503*4520Snw141292  }
504*4520Snw141292} {1 {table "test2" has more than one primary key}}
505*4520Snw141292do_test misc1-16.4 {
506*4520Snw141292  execsql {
507*4520Snw141292    INSERT INTO test VALUES(1);
508*4520Snw141292    SELECT rowid, a FROM test;
509*4520Snw141292  }
510*4520Snw141292} {1 1}
511*4520Snw141292do_test misc1-16.5 {
512*4520Snw141292  execsql {
513*4520Snw141292    INSERT INTO test VALUES(5);
514*4520Snw141292    SELECT rowid, a FROM test;
515*4520Snw141292  }
516*4520Snw141292} {1 1 5 5}
517*4520Snw141292do_test misc1-16.6 {
518*4520Snw141292  execsql {
519*4520Snw141292    INSERT INTO test VALUES(NULL);
520*4520Snw141292    SELECT rowid, a FROM test;
521*4520Snw141292  }
522*4520Snw141292} {1 1 5 5 6 6}
523*4520Snw141292
524*4520Snw141292# Ticket #333: Temp triggers that modify persistent tables.
525*4520Snw141292#
526*4520Snw141292do_test misc1-17.1 {
527*4520Snw141292  execsql {
528*4520Snw141292    BEGIN;
529*4520Snw141292    CREATE TABLE RealTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
530*4520Snw141292    CREATE TEMP TABLE TempTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
531*4520Snw141292    CREATE TEMP TRIGGER trigTest_1 AFTER UPDATE ON TempTable BEGIN
532*4520Snw141292      INSERT INTO RealTable(TestString)
533*4520Snw141292         SELECT new.TestString FROM TempTable LIMIT 1;
534*4520Snw141292    END;
535*4520Snw141292    INSERT INTO TempTable(TestString) VALUES ('1');
536*4520Snw141292    INSERT INTO TempTable(TestString) VALUES ('2');
537*4520Snw141292    UPDATE TempTable SET TestString = TestString + 1 WHERE TestID IN (1, 2);
538*4520Snw141292    COMMIT;
539*4520Snw141292    SELECT TestString FROM RealTable ORDER BY 1;
540*4520Snw141292  }
541*4520Snw141292} {2 3}
542*4520Snw141292
543*4520Snw141292finish_test
544