3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # 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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to verify that table column values
14 # are pulled out of the database correctly.
16 # Long ago, the OP_Column opcode was sufficient to pull out the
17 # value of a table column. But then we added the ALTER TABLE ADD COLUMN
18 # feature. An added column might not actually exist in every row,
19 # and so the OP_Column opcode has to contain a default value. Later
20 # still we added a feature whereby a REAL value with no fractional
21 # part is stored in the database file as an integer to save space.
22 # After extracting the value, we have to call OP_RealAffinity to
23 # convert it back to a REAL.
25 # The sqlite3ExprCodeGetColumn() routine was added to take care of
26 # all of the complications above. The tests in this file attempt
27 # to verify that sqlite3ExprCodeGetColumn() is used instead of a
28 # raw OP_Column in all places where a table column is extracted from
31 # $Id: tkt2251.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $
33 set testdir [file dirname $argv0]
34 source $testdir/tester.tcl
36 ifcapable !altertable {
41 # Create sample data. Verify that the default value and type of an added
42 # column is correct for aggregates.
45 CREATE TABLE t1(a INTEGER);
46 INSERT INTO t1 VALUES(1);
47 INSERT INTO t1 VALUES(1);
48 INSERT INTO t1 VALUES(2);
49 INSERT INTO t1 VALUES(9);
50 INSERT INTO t1 VALUES(9);
51 INSERT INTO t1 VALUES(9);
52 INSERT INTO t1 VALUES(3);
53 INSERT INTO t1 VALUES(2);
54 ALTER TABLE t1 ADD COLUMN b REAL DEFAULT 4.0;
55 SELECT avg(b), typeof(avg(b)) FROM t1;
60 SELECT sum(b), typeof(sum(b)) FROM t1;
65 SELECT a, sum(b), typeof(sum(b)) FROM t1 GROUP BY a ORDER BY a;
67 } {1 8.0 real 2 8.0 real 3 4.0 real 9 12.0 real}
69 # Make sure that the REAL value comes out when values are accessed
74 SELECT b, typeof(b) FROM t1 WHERE a=3;
79 CREATE INDEX t1i1 ON t1(a,b);
80 SELECT b, typeof(b) FROM t1 WHERE a=3;
86 SELECT b, typeof(b) FROM t1 WHERE a=3;
90 # Make sure the correct REAL value is used when copying from one
96 INSERT INTO t2 SELECT * FROM t1;
97 SELECT y, typeof(y) FROM t2 WHERE x=3;
100 do_test tkt2251-3.2 {
102 CREATE TABLE t3 AS SELECT * FROM t1;
103 SELECT b, typeof(b) FROM t3 WHERE a=3;