1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# 2007 Febuary 24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that table column values
# are pulled out of the database correctly.
#
# Long ago, the OP_Column opcode was sufficient to pull out the
# value of a table column. But then we added the ALTER TABLE ADD COLUMN
# feature. An added column might not actually exist in every row,
# and so the OP_Column opcode has to contain a default value. Later
# still we added a feature whereby a REAL value with no fractional
# part is stored in the database file as an integer to save space.
# After extracting the value, we have to call OP_RealAffinity to
# convert it back to a REAL.
#
# The sqlite3ExprCodeGetColumn() routine was added to take care of
# all of the complications above. The tests in this file attempt
# to verify that sqlite3ExprCodeGetColumn() is used instead of a
# raw OP_Column in all places where a table column is extracted from
# the database.
#
# $Id: tkt2251.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !altertable {
finish_test
return
}
# Create sample data. Verify that the default value and type of an added
# column is correct for aggregates.
do_test tkt2251-1.1 {
execsql {
CREATE TABLE t1(a INTEGER);
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 VALUES(9);
INSERT INTO t1 VALUES(9);
INSERT INTO t1 VALUES(9);
INSERT INTO t1 VALUES(3);
INSERT INTO t1 VALUES(2);
ALTER TABLE t1 ADD COLUMN b REAL DEFAULT 4.0;
SELECT avg(b), typeof(avg(b)) FROM t1;
}
} {4.0 real}
do_test tkt2251-1.2 {
execsql {
SELECT sum(b), typeof(sum(b)) FROM t1;
}
} {32.0 real}
do_test tkt2251-1.3 {
execsql {
SELECT a, sum(b), typeof(sum(b)) FROM t1 GROUP BY a ORDER BY a;
}
} {1 8.0 real 2 8.0 real 3 4.0 real 9 12.0 real}
# Make sure that the REAL value comes out when values are accessed
# by index.
#
do_test tkt2251-2.1 {
execsql {
SELECT b, typeof(b) FROM t1 WHERE a=3;
}
} {4.0 real}
do_test tkt2251-2.2 {
execsql {
CREATE INDEX t1i1 ON t1(a,b);
SELECT b, typeof(b) FROM t1 WHERE a=3;
}
} {4.0 real}
do_test tkt2251-2.3 {
execsql {
REINDEX;
SELECT b, typeof(b) FROM t1 WHERE a=3;
}
} {4.0 real}
# Make sure the correct REAL value is used when copying from one
# table to another.
#
do_test tkt2251-3.1 {
execsql {
CREATE TABLE t2(x,y);
INSERT INTO t2 SELECT * FROM t1;
SELECT y, typeof(y) FROM t2 WHERE x=3;
}
} {4.0 real}
do_test tkt2251-3.2 {
execsql {
CREATE TABLE t3 AS SELECT * FROM t1;
SELECT b, typeof(b) FROM t3 WHERE a=3;
}
} {4.0 real}
finish_test
|