sl@0: # 2007 Febuary 24 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests to verify that table column values sl@0: # are pulled out of the database correctly. sl@0: # sl@0: # Long ago, the OP_Column opcode was sufficient to pull out the sl@0: # value of a table column. But then we added the ALTER TABLE ADD COLUMN sl@0: # feature. An added column might not actually exist in every row, sl@0: # and so the OP_Column opcode has to contain a default value. Later sl@0: # still we added a feature whereby a REAL value with no fractional sl@0: # part is stored in the database file as an integer to save space. sl@0: # After extracting the value, we have to call OP_RealAffinity to sl@0: # convert it back to a REAL. sl@0: # sl@0: # The sqlite3ExprCodeGetColumn() routine was added to take care of sl@0: # all of the complications above. The tests in this file attempt sl@0: # to verify that sqlite3ExprCodeGetColumn() is used instead of a sl@0: # raw OP_Column in all places where a table column is extracted from sl@0: # the database. sl@0: # sl@0: # $Id: tkt2251.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !altertable { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Create sample data. Verify that the default value and type of an added sl@0: # column is correct for aggregates. sl@0: do_test tkt2251-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(a INTEGER); sl@0: INSERT INTO t1 VALUES(1); sl@0: INSERT INTO t1 VALUES(1); sl@0: INSERT INTO t1 VALUES(2); sl@0: INSERT INTO t1 VALUES(9); sl@0: INSERT INTO t1 VALUES(9); sl@0: INSERT INTO t1 VALUES(9); sl@0: INSERT INTO t1 VALUES(3); sl@0: INSERT INTO t1 VALUES(2); sl@0: ALTER TABLE t1 ADD COLUMN b REAL DEFAULT 4.0; sl@0: SELECT avg(b), typeof(avg(b)) FROM t1; sl@0: } sl@0: } {4.0 real} sl@0: do_test tkt2251-1.2 { sl@0: execsql { sl@0: SELECT sum(b), typeof(sum(b)) FROM t1; sl@0: } sl@0: } {32.0 real} sl@0: do_test tkt2251-1.3 { sl@0: execsql { sl@0: SELECT a, sum(b), typeof(sum(b)) FROM t1 GROUP BY a ORDER BY a; sl@0: } sl@0: } {1 8.0 real 2 8.0 real 3 4.0 real 9 12.0 real} sl@0: sl@0: # Make sure that the REAL value comes out when values are accessed sl@0: # by index. sl@0: # sl@0: do_test tkt2251-2.1 { sl@0: execsql { sl@0: SELECT b, typeof(b) FROM t1 WHERE a=3; sl@0: } sl@0: } {4.0 real} sl@0: do_test tkt2251-2.2 { sl@0: execsql { sl@0: CREATE INDEX t1i1 ON t1(a,b); sl@0: SELECT b, typeof(b) FROM t1 WHERE a=3; sl@0: } sl@0: } {4.0 real} sl@0: do_test tkt2251-2.3 { sl@0: execsql { sl@0: REINDEX; sl@0: SELECT b, typeof(b) FROM t1 WHERE a=3; sl@0: } sl@0: } {4.0 real} sl@0: sl@0: # Make sure the correct REAL value is used when copying from one sl@0: # table to another. sl@0: # sl@0: do_test tkt2251-3.1 { sl@0: execsql { sl@0: CREATE TABLE t2(x,y); sl@0: INSERT INTO t2 SELECT * FROM t1; sl@0: SELECT y, typeof(y) FROM t2 WHERE x=3; sl@0: } sl@0: } {4.0 real} sl@0: do_test tkt2251-3.2 { sl@0: execsql { sl@0: CREATE TABLE t3 AS SELECT * FROM t1; sl@0: SELECT b, typeof(b) FROM t3 WHERE a=3; sl@0: } sl@0: } {4.0 real} sl@0: sl@0: sl@0: finish_test