xref: /titanic_44/usr/src/lib/libsqlite/test/intpkey.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.
15*c5c4113dSnw141292#
16*c5c4113dSnw141292# This file implements tests for the special processing associated
17*c5c4113dSnw141292# with INTEGER PRIMARY KEY columns.
18*c5c4113dSnw141292#
19*c5c4113dSnw141292# $Id: intpkey.test,v 1.14 2003/06/15 23:42:25 drh Exp $
20*c5c4113dSnw141292
21*c5c4113dSnw141292set testdir [file dirname $argv0]
22*c5c4113dSnw141292source $testdir/tester.tcl
23*c5c4113dSnw141292
24*c5c4113dSnw141292# Create a table with a primary key and a datatype other than
25*c5c4113dSnw141292# integer
26*c5c4113dSnw141292#
27*c5c4113dSnw141292do_test intpkey-1.0 {
28*c5c4113dSnw141292  execsql {
29*c5c4113dSnw141292    CREATE TABLE t1(a TEXT PRIMARY KEY, b, c);
30*c5c4113dSnw141292  }
31*c5c4113dSnw141292} {}
32*c5c4113dSnw141292
33*c5c4113dSnw141292# There should be an index associated with the primary key
34*c5c4113dSnw141292#
35*c5c4113dSnw141292do_test intpkey-1.1 {
36*c5c4113dSnw141292  execsql {
37*c5c4113dSnw141292    SELECT name FROM sqlite_master
38*c5c4113dSnw141292    WHERE type='index' AND tbl_name='t1';
39*c5c4113dSnw141292  }
40*c5c4113dSnw141292} {{(t1 autoindex 1)}}
41*c5c4113dSnw141292
42*c5c4113dSnw141292# Now create a table with an integer primary key and verify that
43*c5c4113dSnw141292# there is no associated index.
44*c5c4113dSnw141292#
45*c5c4113dSnw141292do_test intpkey-1.2 {
46*c5c4113dSnw141292  execsql {
47*c5c4113dSnw141292    DROP TABLE t1;
48*c5c4113dSnw141292    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
49*c5c4113dSnw141292    SELECT name FROM sqlite_master
50*c5c4113dSnw141292      WHERE type='index' AND tbl_name='t1';
51*c5c4113dSnw141292  }
52*c5c4113dSnw141292} {}
53*c5c4113dSnw141292
54*c5c4113dSnw141292# Insert some records into the new table.  Specify the primary key
55*c5c4113dSnw141292# and verify that the key is used as the record number.
56*c5c4113dSnw141292#
57*c5c4113dSnw141292do_test intpkey-1.3 {
58*c5c4113dSnw141292  execsql {
59*c5c4113dSnw141292    INSERT INTO t1 VALUES(5,'hello','world');
60*c5c4113dSnw141292  }
61*c5c4113dSnw141292  db last_insert_rowid
62*c5c4113dSnw141292} {5}
63*c5c4113dSnw141292do_test intpkey-1.4 {
64*c5c4113dSnw141292  execsql {
65*c5c4113dSnw141292    SELECT * FROM t1;
66*c5c4113dSnw141292  }
67*c5c4113dSnw141292} {5 hello world}
68*c5c4113dSnw141292do_test intpkey-1.5 {
69*c5c4113dSnw141292  execsql {
70*c5c4113dSnw141292    SELECT rowid, * FROM t1;
71*c5c4113dSnw141292  }
72*c5c4113dSnw141292} {5 5 hello world}
73*c5c4113dSnw141292
74*c5c4113dSnw141292# Attempting to insert a duplicate primary key should give a constraint
75*c5c4113dSnw141292# failure.
76*c5c4113dSnw141292#
77*c5c4113dSnw141292do_test intpkey-1.6 {
78*c5c4113dSnw141292  set r [catch {execsql {
79*c5c4113dSnw141292     INSERT INTO t1 VALUES(5,'second','entry');
80*c5c4113dSnw141292  }} msg]
81*c5c4113dSnw141292  lappend r $msg
82*c5c4113dSnw141292} {1 {PRIMARY KEY must be unique}}
83*c5c4113dSnw141292do_test intpkey-1.7 {
84*c5c4113dSnw141292  execsql {
85*c5c4113dSnw141292    SELECT rowid, * FROM t1;
86*c5c4113dSnw141292  }
87*c5c4113dSnw141292} {5 5 hello world}
88*c5c4113dSnw141292do_test intpkey-1.8 {
89*c5c4113dSnw141292  set r [catch {execsql {
90*c5c4113dSnw141292     INSERT INTO t1 VALUES(6,'second','entry');
91*c5c4113dSnw141292  }} msg]
92*c5c4113dSnw141292  lappend r $msg
93*c5c4113dSnw141292} {0 {}}
94*c5c4113dSnw141292do_test intpkey-1.8.1 {
95*c5c4113dSnw141292  db last_insert_rowid
96*c5c4113dSnw141292} {6}
97*c5c4113dSnw141292do_test intpkey-1.9 {
98*c5c4113dSnw141292  execsql {
99*c5c4113dSnw141292    SELECT rowid, * FROM t1;
100*c5c4113dSnw141292  }
101*c5c4113dSnw141292} {5 5 hello world 6 6 second entry}
102*c5c4113dSnw141292
103*c5c4113dSnw141292# A ROWID is automatically generated for new records that do not specify
104*c5c4113dSnw141292# the integer primary key.
105*c5c4113dSnw141292#
106*c5c4113dSnw141292do_test intpkey-1.10 {
107*c5c4113dSnw141292  execsql {
108*c5c4113dSnw141292    INSERT INTO t1(b,c) VALUES('one','two');
109*c5c4113dSnw141292    SELECT b FROM t1 ORDER BY b;
110*c5c4113dSnw141292  }
111*c5c4113dSnw141292} {hello one second}
112*c5c4113dSnw141292
113*c5c4113dSnw141292# Try to change the ROWID for the new entry.
114*c5c4113dSnw141292#
115*c5c4113dSnw141292do_test intpkey-1.11 {
116*c5c4113dSnw141292  execsql {
117*c5c4113dSnw141292    UPDATE t1 SET a=4 WHERE b='one';
118*c5c4113dSnw141292    SELECT * FROM t1;
119*c5c4113dSnw141292  }
120*c5c4113dSnw141292} {4 one two 5 hello world 6 second entry}
121*c5c4113dSnw141292
122*c5c4113dSnw141292# Make sure SELECT statements are able to use the primary key column
123*c5c4113dSnw141292# as an index.
124*c5c4113dSnw141292#
125*c5c4113dSnw141292do_test intpkey-1.12 {
126*c5c4113dSnw141292  execsql {
127*c5c4113dSnw141292    SELECT * FROM t1 WHERE a==4;
128*c5c4113dSnw141292  }
129*c5c4113dSnw141292} {4 one two}
130*c5c4113dSnw141292
131*c5c4113dSnw141292# Try to insert a non-integer value into the primary key field.  This
132*c5c4113dSnw141292# should result in a data type mismatch.
133*c5c4113dSnw141292#
134*c5c4113dSnw141292do_test intpkey-1.13.1 {
135*c5c4113dSnw141292  set r [catch {execsql {
136*c5c4113dSnw141292    INSERT INTO t1 VALUES('x','y','z');
137*c5c4113dSnw141292  }} msg]
138*c5c4113dSnw141292  lappend r $msg
139*c5c4113dSnw141292} {1 {datatype mismatch}}
140*c5c4113dSnw141292do_test intpkey-1.13.2 {
141*c5c4113dSnw141292  set r [catch {execsql {
142*c5c4113dSnw141292    INSERT INTO t1 VALUES('','y','z');
143*c5c4113dSnw141292  }} msg]
144*c5c4113dSnw141292  lappend r $msg
145*c5c4113dSnw141292} {1 {datatype mismatch}}
146*c5c4113dSnw141292do_test intpkey-1.14 {
147*c5c4113dSnw141292  set r [catch {execsql {
148*c5c4113dSnw141292    INSERT INTO t1 VALUES(3.4,'y','z');
149*c5c4113dSnw141292  }} msg]
150*c5c4113dSnw141292  lappend r $msg
151*c5c4113dSnw141292} {1 {datatype mismatch}}
152*c5c4113dSnw141292do_test intpkey-1.15 {
153*c5c4113dSnw141292  set r [catch {execsql {
154*c5c4113dSnw141292    INSERT INTO t1 VALUES(-3,'y','z');
155*c5c4113dSnw141292  }} msg]
156*c5c4113dSnw141292  lappend r $msg
157*c5c4113dSnw141292} {0 {}}
158*c5c4113dSnw141292do_test intpkey-1.16 {
159*c5c4113dSnw141292  execsql {SELECT * FROM t1}
160*c5c4113dSnw141292} {-3 y z 4 one two 5 hello world 6 second entry}
161*c5c4113dSnw141292
162*c5c4113dSnw141292#### INDICES
163*c5c4113dSnw141292# Check to make sure indices work correctly with integer primary keys
164*c5c4113dSnw141292#
165*c5c4113dSnw141292do_test intpkey-2.1 {
166*c5c4113dSnw141292  execsql {
167*c5c4113dSnw141292    CREATE INDEX i1 ON t1(b);
168*c5c4113dSnw141292    SELECT * FROM t1 WHERE b=='y'
169*c5c4113dSnw141292  }
170*c5c4113dSnw141292} {-3 y z}
171*c5c4113dSnw141292do_test intpkey-2.1.1 {
172*c5c4113dSnw141292  execsql {
173*c5c4113dSnw141292    SELECT * FROM t1 WHERE b=='y' AND rowid<0
174*c5c4113dSnw141292  }
175*c5c4113dSnw141292} {-3 y z}
176*c5c4113dSnw141292do_test intpkey-2.1.2 {
177*c5c4113dSnw141292  execsql {
178*c5c4113dSnw141292    SELECT * FROM t1 WHERE b=='y' AND rowid<0 AND rowid>=-20
179*c5c4113dSnw141292  }
180*c5c4113dSnw141292} {-3 y z}
181*c5c4113dSnw141292do_test intpkey-2.1.3 {
182*c5c4113dSnw141292  execsql {
183*c5c4113dSnw141292    SELECT * FROM t1 WHERE b>='y'
184*c5c4113dSnw141292  }
185*c5c4113dSnw141292} {-3 y z}
186*c5c4113dSnw141292do_test intpkey-2.1.4 {
187*c5c4113dSnw141292  execsql {
188*c5c4113dSnw141292    SELECT * FROM t1 WHERE b>='y' AND rowid<10
189*c5c4113dSnw141292  }
190*c5c4113dSnw141292} {-3 y z}
191*c5c4113dSnw141292
192*c5c4113dSnw141292do_test intpkey-2.2 {
193*c5c4113dSnw141292  execsql {
194*c5c4113dSnw141292    UPDATE t1 SET a=8 WHERE b=='y';
195*c5c4113dSnw141292    SELECT * FROM t1 WHERE b=='y';
196*c5c4113dSnw141292  }
197*c5c4113dSnw141292} {8 y z}
198*c5c4113dSnw141292do_test intpkey-2.3 {
199*c5c4113dSnw141292  execsql {
200*c5c4113dSnw141292    SELECT rowid, * FROM t1;
201*c5c4113dSnw141292  }
202*c5c4113dSnw141292} {4 4 one two 5 5 hello world 6 6 second entry 8 8 y z}
203*c5c4113dSnw141292do_test intpkey-2.4 {
204*c5c4113dSnw141292  execsql {
205*c5c4113dSnw141292    SELECT rowid, * FROM t1 WHERE b<'second'
206*c5c4113dSnw141292  }
207*c5c4113dSnw141292} {5 5 hello world 4 4 one two}
208*c5c4113dSnw141292do_test intpkey-2.4.1 {
209*c5c4113dSnw141292  execsql {
210*c5c4113dSnw141292    SELECT rowid, * FROM t1 WHERE 'second'>b
211*c5c4113dSnw141292  }
212*c5c4113dSnw141292} {5 5 hello world 4 4 one two}
213*c5c4113dSnw141292do_test intpkey-2.4.2 {
214*c5c4113dSnw141292  execsql {
215*c5c4113dSnw141292    SELECT rowid, * FROM t1 WHERE 8>rowid AND 'second'>b
216*c5c4113dSnw141292  }
217*c5c4113dSnw141292} {4 4 one two 5 5 hello world}
218*c5c4113dSnw141292do_test intpkey-2.4.3 {
219*c5c4113dSnw141292  execsql {
220*c5c4113dSnw141292    SELECT rowid, * FROM t1 WHERE 8>rowid AND 'second'>b AND 0<rowid
221*c5c4113dSnw141292  }
222*c5c4113dSnw141292} {4 4 one two 5 5 hello world}
223*c5c4113dSnw141292do_test intpkey-2.5 {
224*c5c4113dSnw141292  execsql {
225*c5c4113dSnw141292    SELECT rowid, * FROM t1 WHERE b>'a'
226*c5c4113dSnw141292  }
227*c5c4113dSnw141292} {5 5 hello world 4 4 one two 6 6 second entry 8 8 y z}
228*c5c4113dSnw141292do_test intpkey-2.6 {
229*c5c4113dSnw141292  execsql {
230*c5c4113dSnw141292    DELETE FROM t1 WHERE rowid=4;
231*c5c4113dSnw141292    SELECT * FROM t1 WHERE b>'a';
232*c5c4113dSnw141292  }
233*c5c4113dSnw141292} {5 hello world 6 second entry 8 y z}
234*c5c4113dSnw141292do_test intpkey-2.7 {
235*c5c4113dSnw141292  execsql {
236*c5c4113dSnw141292    UPDATE t1 SET a=-4 WHERE rowid=8;
237*c5c4113dSnw141292    SELECT * FROM t1 WHERE b>'a';
238*c5c4113dSnw141292  }
239*c5c4113dSnw141292} {5 hello world 6 second entry -4 y z}
240*c5c4113dSnw141292do_test intpkey-2.7 {
241*c5c4113dSnw141292  execsql {
242*c5c4113dSnw141292    SELECT * FROM t1
243*c5c4113dSnw141292  }
244*c5c4113dSnw141292} {-4 y z 5 hello world 6 second entry}
245*c5c4113dSnw141292
246*c5c4113dSnw141292# Do an SQL statement.  Append the search count to the end of the result.
247*c5c4113dSnw141292#
248*c5c4113dSnw141292proc count sql {
249*c5c4113dSnw141292  set ::sqlite_search_count 0
250*c5c4113dSnw141292  return [concat [execsql $sql] $::sqlite_search_count]
251*c5c4113dSnw141292}
252*c5c4113dSnw141292
253*c5c4113dSnw141292# Create indices that include the integer primary key as one of their
254*c5c4113dSnw141292# columns.
255*c5c4113dSnw141292#
256*c5c4113dSnw141292do_test intpkey-3.1 {
257*c5c4113dSnw141292  execsql {
258*c5c4113dSnw141292    CREATE INDEX i2 ON t1(a);
259*c5c4113dSnw141292  }
260*c5c4113dSnw141292} {}
261*c5c4113dSnw141292do_test intpkey-3.2 {
262*c5c4113dSnw141292  count {
263*c5c4113dSnw141292    SELECT * FROM t1 WHERE a=5;
264*c5c4113dSnw141292  }
265*c5c4113dSnw141292} {5 hello world 0}
266*c5c4113dSnw141292do_test intpkey-3.3 {
267*c5c4113dSnw141292  count {
268*c5c4113dSnw141292    SELECT * FROM t1 WHERE a>4 AND a<6;
269*c5c4113dSnw141292  }
270*c5c4113dSnw141292} {5 hello world 2}
271*c5c4113dSnw141292do_test intpkey-3.4 {
272*c5c4113dSnw141292  count {
273*c5c4113dSnw141292    SELECT * FROM t1 WHERE b>='hello' AND b<'hello2';
274*c5c4113dSnw141292  }
275*c5c4113dSnw141292} {5 hello world 3}
276*c5c4113dSnw141292do_test intpkey-3.5 {
277*c5c4113dSnw141292  execsql {
278*c5c4113dSnw141292    CREATE INDEX i3 ON t1(c,a);
279*c5c4113dSnw141292  }
280*c5c4113dSnw141292} {}
281*c5c4113dSnw141292do_test intpkey-3.6 {
282*c5c4113dSnw141292  count {
283*c5c4113dSnw141292    SELECT * FROM t1 WHERE c=='world';
284*c5c4113dSnw141292  }
285*c5c4113dSnw141292} {5 hello world 3}
286*c5c4113dSnw141292do_test intpkey-3.7 {
287*c5c4113dSnw141292  execsql {INSERT INTO t1 VALUES(11,'hello','world')}
288*c5c4113dSnw141292  count {
289*c5c4113dSnw141292    SELECT * FROM t1 WHERE c=='world';
290*c5c4113dSnw141292  }
291*c5c4113dSnw141292} {5 hello world 11 hello world 5}
292*c5c4113dSnw141292do_test intpkey-3.8 {
293*c5c4113dSnw141292  count {
294*c5c4113dSnw141292    SELECT * FROM t1 WHERE c=='world' AND a>7;
295*c5c4113dSnw141292  }
296*c5c4113dSnw141292} {11 hello world 5}
297*c5c4113dSnw141292do_test intpkey-3.9 {
298*c5c4113dSnw141292  count {
299*c5c4113dSnw141292    SELECT * FROM t1 WHERE 7<a;
300*c5c4113dSnw141292  }
301*c5c4113dSnw141292} {11 hello world 1}
302*c5c4113dSnw141292
303*c5c4113dSnw141292# Test inequality constraints on integer primary keys and rowids
304*c5c4113dSnw141292#
305*c5c4113dSnw141292do_test intpkey-4.1 {
306*c5c4113dSnw141292  count {
307*c5c4113dSnw141292    SELECT * FROM t1 WHERE 11=rowid
308*c5c4113dSnw141292  }
309*c5c4113dSnw141292} {11 hello world 0}
310*c5c4113dSnw141292do_test intpkey-4.2 {
311*c5c4113dSnw141292  count {
312*c5c4113dSnw141292    SELECT * FROM t1 WHERE 11=rowid AND b=='hello'
313*c5c4113dSnw141292  }
314*c5c4113dSnw141292} {11 hello world 0}
315*c5c4113dSnw141292do_test intpkey-4.3 {
316*c5c4113dSnw141292  count {
317*c5c4113dSnw141292    SELECT * FROM t1 WHERE 11=rowid AND b=='hello' AND c IS NOT NULL;
318*c5c4113dSnw141292  }
319*c5c4113dSnw141292} {11 hello world 0}
320*c5c4113dSnw141292do_test intpkey-4.4 {
321*c5c4113dSnw141292  count {
322*c5c4113dSnw141292    SELECT * FROM t1 WHERE rowid==11
323*c5c4113dSnw141292  }
324*c5c4113dSnw141292} {11 hello world 0}
325*c5c4113dSnw141292do_test intpkey-4.5 {
326*c5c4113dSnw141292  count {
327*c5c4113dSnw141292    SELECT * FROM t1 WHERE oid==11 AND b=='hello'
328*c5c4113dSnw141292  }
329*c5c4113dSnw141292} {11 hello world 0}
330*c5c4113dSnw141292do_test intpkey-4.6 {
331*c5c4113dSnw141292  count {
332*c5c4113dSnw141292    SELECT * FROM t1 WHERE a==11 AND b=='hello' AND c IS NOT NULL;
333*c5c4113dSnw141292  }
334*c5c4113dSnw141292} {11 hello world 0}
335*c5c4113dSnw141292
336*c5c4113dSnw141292do_test intpkey-4.7 {
337*c5c4113dSnw141292  count {
338*c5c4113dSnw141292    SELECT * FROM t1 WHERE 8<rowid;
339*c5c4113dSnw141292  }
340*c5c4113dSnw141292} {11 hello world 1}
341*c5c4113dSnw141292do_test intpkey-4.8 {
342*c5c4113dSnw141292  count {
343*c5c4113dSnw141292    SELECT * FROM t1 WHERE 8<rowid AND 11>=oid;
344*c5c4113dSnw141292  }
345*c5c4113dSnw141292} {11 hello world 1}
346*c5c4113dSnw141292do_test intpkey-4.9 {
347*c5c4113dSnw141292  count {
348*c5c4113dSnw141292    SELECT * FROM t1 WHERE 11<=_rowid_ AND 12>=a;
349*c5c4113dSnw141292  }
350*c5c4113dSnw141292} {11 hello world 1}
351*c5c4113dSnw141292do_test intpkey-4.10 {
352*c5c4113dSnw141292  count {
353*c5c4113dSnw141292    SELECT * FROM t1 WHERE 0>=_rowid_;
354*c5c4113dSnw141292  }
355*c5c4113dSnw141292} {-4 y z 1}
356*c5c4113dSnw141292do_test intpkey-4.11 {
357*c5c4113dSnw141292  count {
358*c5c4113dSnw141292    SELECT * FROM t1 WHERE a<0;
359*c5c4113dSnw141292  }
360*c5c4113dSnw141292} {-4 y z 1}
361*c5c4113dSnw141292do_test intpkey-4.12 {
362*c5c4113dSnw141292  count {
363*c5c4113dSnw141292    SELECT * FROM t1 WHERE a<0 AND a>10;
364*c5c4113dSnw141292  }
365*c5c4113dSnw141292} {1}
366*c5c4113dSnw141292
367*c5c4113dSnw141292# Make sure it is OK to insert a rowid of 0
368*c5c4113dSnw141292#
369*c5c4113dSnw141292do_test intpkey-5.1 {
370*c5c4113dSnw141292  execsql {
371*c5c4113dSnw141292    INSERT INTO t1 VALUES(0,'zero','entry');
372*c5c4113dSnw141292  }
373*c5c4113dSnw141292  count {
374*c5c4113dSnw141292    SELECT * FROM t1 WHERE a=0;
375*c5c4113dSnw141292  }
376*c5c4113dSnw141292} {0 zero entry 0}
377*c5c4113dSnw141292do_test intpkey=5.2 {
378*c5c4113dSnw141292  execsql {
379*c5c4113dSnw141292    SELECT rowid, a FROM t1
380*c5c4113dSnw141292  }
381*c5c4113dSnw141292} {-4 -4 0 0 5 5 6 6 11 11}
382*c5c4113dSnw141292
383*c5c4113dSnw141292# Test the ability of the COPY command to put data into a
384*c5c4113dSnw141292# table that contains an integer primary key.
385*c5c4113dSnw141292#
386*c5c4113dSnw141292do_test intpkey-6.1 {
387*c5c4113dSnw141292  set f [open ./data1.txt w]
388*c5c4113dSnw141292  puts $f "20\tb-20\tc-20"
389*c5c4113dSnw141292  puts $f "21\tb-21\tc-21"
390*c5c4113dSnw141292  puts $f "22\tb-22\tc-22"
391*c5c4113dSnw141292  close $f
392*c5c4113dSnw141292  execsql {
393*c5c4113dSnw141292    COPY t1 FROM 'data1.txt';
394*c5c4113dSnw141292    SELECT * FROM t1 WHERE a>=20;
395*c5c4113dSnw141292  }
396*c5c4113dSnw141292} {20 b-20 c-20 21 b-21 c-21 22 b-22 c-22}
397*c5c4113dSnw141292do_test intpkey-6.2 {
398*c5c4113dSnw141292  execsql {
399*c5c4113dSnw141292    SELECT * FROM t1 WHERE b=='hello'
400*c5c4113dSnw141292  }
401*c5c4113dSnw141292} {5 hello world 11 hello world}
402*c5c4113dSnw141292do_test intpkey-6.3 {
403*c5c4113dSnw141292  execsql {
404*c5c4113dSnw141292    DELETE FROM t1 WHERE b='b-21';
405*c5c4113dSnw141292    SELECT * FROM t1 WHERE b=='b-21';
406*c5c4113dSnw141292  }
407*c5c4113dSnw141292} {}
408*c5c4113dSnw141292do_test intpkey-6.4 {
409*c5c4113dSnw141292  execsql {
410*c5c4113dSnw141292    SELECT * FROM t1 WHERE a>=20
411*c5c4113dSnw141292  }
412*c5c4113dSnw141292} {20 b-20 c-20 22 b-22 c-22}
413*c5c4113dSnw141292
414*c5c4113dSnw141292# Do an insert of values with the columns specified out of order.
415*c5c4113dSnw141292#
416*c5c4113dSnw141292do_test intpkey-7.1 {
417*c5c4113dSnw141292  execsql {
418*c5c4113dSnw141292    INSERT INTO t1(c,b,a) VALUES('row','new',30);
419*c5c4113dSnw141292    SELECT * FROM t1 WHERE rowid>=30;
420*c5c4113dSnw141292  }
421*c5c4113dSnw141292} {30 new row}
422*c5c4113dSnw141292do_test intpkey-7.2 {
423*c5c4113dSnw141292  execsql {
424*c5c4113dSnw141292    SELECT * FROM t1 WHERE rowid>20;
425*c5c4113dSnw141292  }
426*c5c4113dSnw141292} {22 b-22 c-22 30 new row}
427*c5c4113dSnw141292
428*c5c4113dSnw141292# Do an insert from a select statement.
429*c5c4113dSnw141292#
430*c5c4113dSnw141292do_test intpkey-8.1 {
431*c5c4113dSnw141292  execsql {
432*c5c4113dSnw141292    CREATE TABLE t2(x INTEGER PRIMARY KEY, y, z);
433*c5c4113dSnw141292    INSERT INTO t2 SELECT * FROM t1;
434*c5c4113dSnw141292    SELECT rowid FROM t2;
435*c5c4113dSnw141292  }
436*c5c4113dSnw141292} {-4 0 5 6 11 20 22 30}
437*c5c4113dSnw141292do_test intpkey-8.2 {
438*c5c4113dSnw141292  execsql {
439*c5c4113dSnw141292    SELECT x FROM t2;
440*c5c4113dSnw141292  }
441*c5c4113dSnw141292} {-4 0 5 6 11 20 22 30}
442*c5c4113dSnw141292
443*c5c4113dSnw141292do_test intpkey-9.1 {
444*c5c4113dSnw141292  execsql {
445*c5c4113dSnw141292    UPDATE t1 SET c='www' WHERE c='world';
446*c5c4113dSnw141292    SELECT rowid, a, c FROM t1 WHERE c=='www';
447*c5c4113dSnw141292  }
448*c5c4113dSnw141292} {5 5 www 11 11 www}
449*c5c4113dSnw141292
450*c5c4113dSnw141292
451*c5c4113dSnw141292# Check insert of NULL for primary key
452*c5c4113dSnw141292#
453*c5c4113dSnw141292do_test intpkey-10.1 {
454*c5c4113dSnw141292  execsql {
455*c5c4113dSnw141292    DROP TABLE t2;
456*c5c4113dSnw141292    CREATE TABLE t2(x INTEGER PRIMARY KEY, y, z);
457*c5c4113dSnw141292    INSERT INTO t2 VALUES(NULL, 1, 2);
458*c5c4113dSnw141292    SELECT * from t2;
459*c5c4113dSnw141292  }
460*c5c4113dSnw141292} {1 1 2}
461*c5c4113dSnw141292do_test intpkey-10.2 {
462*c5c4113dSnw141292  execsql {
463*c5c4113dSnw141292    INSERT INTO t2 VALUES(NULL, 2, 3);
464*c5c4113dSnw141292    SELECT * from t2 WHERE x=2;
465*c5c4113dSnw141292  }
466*c5c4113dSnw141292} {2 2 3}
467*c5c4113dSnw141292do_test intpkey-10.3 {
468*c5c4113dSnw141292  execsql {
469*c5c4113dSnw141292    INSERT INTO t2 SELECT NULL, z, y FROM t2;
470*c5c4113dSnw141292    SELECT * FROM t2;
471*c5c4113dSnw141292  }
472*c5c4113dSnw141292} {1 1 2 2 2 3 3 2 1 4 3 2}
473*c5c4113dSnw141292
474*c5c4113dSnw141292# This tests checks to see if a floating point number can be used
475*c5c4113dSnw141292# to reference an integer primary key.
476*c5c4113dSnw141292#
477*c5c4113dSnw141292do_test intpkey-11.1 {
478*c5c4113dSnw141292  execsql {
479*c5c4113dSnw141292    SELECT b FROM t1 WHERE a=2.0+3.0;
480*c5c4113dSnw141292  }
481*c5c4113dSnw141292} {hello}
482*c5c4113dSnw141292do_test intpkey-11.1 {
483*c5c4113dSnw141292  execsql {
484*c5c4113dSnw141292    SELECT b FROM t1 WHERE a=2.0+3.5;
485*c5c4113dSnw141292  }
486*c5c4113dSnw141292} {}
487*c5c4113dSnw141292
488*c5c4113dSnw141292integrity_check intpkey-12.1
489*c5c4113dSnw141292
490*c5c4113dSnw141292finish_test
491