sl@0
|
1 |
# 2006 June 10
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# $Id: vtab5.test,v 1.8 2008/07/12 14:52:21 drh Exp $
|
sl@0
|
14 |
|
sl@0
|
15 |
set testdir [file dirname $argv0]
|
sl@0
|
16 |
source $testdir/tester.tcl
|
sl@0
|
17 |
|
sl@0
|
18 |
ifcapable !vtab {
|
sl@0
|
19 |
finish_test
|
sl@0
|
20 |
return
|
sl@0
|
21 |
}
|
sl@0
|
22 |
|
sl@0
|
23 |
# The following tests - vtab5-1.* - ensure that an INSERT, DELETE or UPDATE
|
sl@0
|
24 |
# statement can be executed immediately after a CREATE or schema reload. The
|
sl@0
|
25 |
# point here is testing that the parser always calls xConnect() before the
|
sl@0
|
26 |
# schema of a virtual table is used.
|
sl@0
|
27 |
#
|
sl@0
|
28 |
register_echo_module [sqlite3_connection_pointer db]
|
sl@0
|
29 |
do_test vtab5-1.1 {
|
sl@0
|
30 |
execsql {
|
sl@0
|
31 |
CREATE TABLE treal(a VARCHAR(16), b INTEGER, c FLOAT);
|
sl@0
|
32 |
INSERT INTO treal VALUES('a', 'b', 'c');
|
sl@0
|
33 |
CREATE VIRTUAL TABLE techo USING echo(treal);
|
sl@0
|
34 |
}
|
sl@0
|
35 |
} {}
|
sl@0
|
36 |
do_test vtab5.1.2 {
|
sl@0
|
37 |
execsql {
|
sl@0
|
38 |
SELECT * FROM techo;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
} {a b c}
|
sl@0
|
41 |
do_test vtab5.1.3 {
|
sl@0
|
42 |
db close
|
sl@0
|
43 |
sqlite3 db test.db
|
sl@0
|
44 |
register_echo_module [sqlite3_connection_pointer db]
|
sl@0
|
45 |
execsql {
|
sl@0
|
46 |
INSERT INTO techo VALUES('c', 'd', 'e');
|
sl@0
|
47 |
SELECT * FROM techo;
|
sl@0
|
48 |
}
|
sl@0
|
49 |
} {a b c c d e}
|
sl@0
|
50 |
do_test vtab5.1.4 {
|
sl@0
|
51 |
db close
|
sl@0
|
52 |
sqlite3 db test.db
|
sl@0
|
53 |
register_echo_module [sqlite3_connection_pointer db]
|
sl@0
|
54 |
execsql {
|
sl@0
|
55 |
UPDATE techo SET a = 10;
|
sl@0
|
56 |
SELECT * FROM techo;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
} {10 b c 10 d e}
|
sl@0
|
59 |
do_test vtab5.1.5 {
|
sl@0
|
60 |
db close
|
sl@0
|
61 |
sqlite3 db test.db
|
sl@0
|
62 |
register_echo_module [sqlite3_connection_pointer db]
|
sl@0
|
63 |
execsql {
|
sl@0
|
64 |
DELETE FROM techo WHERE b > 'c';
|
sl@0
|
65 |
SELECT * FROM techo;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
} {10 b c}
|
sl@0
|
68 |
do_test vtab5.1.X {
|
sl@0
|
69 |
execsql {
|
sl@0
|
70 |
DROP TABLE techo;
|
sl@0
|
71 |
DROP TABLE treal;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
} {}
|
sl@0
|
74 |
|
sl@0
|
75 |
# The following tests - vtab5-2.* - ensure that collation sequences
|
sl@0
|
76 |
# assigned to virtual table columns via the "CREATE TABLE" statement
|
sl@0
|
77 |
# passed to sqlite3_declare_vtab() are used correctly.
|
sl@0
|
78 |
#
|
sl@0
|
79 |
do_test vtab5.2.1 {
|
sl@0
|
80 |
execsql {
|
sl@0
|
81 |
CREATE TABLE strings(str COLLATE NOCASE);
|
sl@0
|
82 |
INSERT INTO strings VALUES('abc1');
|
sl@0
|
83 |
INSERT INTO strings VALUES('Abc3');
|
sl@0
|
84 |
INSERT INTO strings VALUES('ABc2');
|
sl@0
|
85 |
INSERT INTO strings VALUES('aBc4');
|
sl@0
|
86 |
SELECT str FROM strings ORDER BY 1;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
} {abc1 ABc2 Abc3 aBc4}
|
sl@0
|
89 |
do_test vtab5.2.2 {
|
sl@0
|
90 |
execsql {
|
sl@0
|
91 |
CREATE VIRTUAL TABLE echo_strings USING echo(strings);
|
sl@0
|
92 |
SELECT str FROM echo_strings ORDER BY 1;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
} {abc1 ABc2 Abc3 aBc4}
|
sl@0
|
95 |
do_test vtab5.2.3 {
|
sl@0
|
96 |
execsql {
|
sl@0
|
97 |
SELECT str||'' FROM echo_strings ORDER BY 1;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
} {ABc2 Abc3 aBc4 abc1}
|
sl@0
|
100 |
|
sl@0
|
101 |
# Test that it is impossible to create a triggger on a virtual table.
|
sl@0
|
102 |
#
|
sl@0
|
103 |
ifcapable trigger {
|
sl@0
|
104 |
do_test vtab5.3.1 {
|
sl@0
|
105 |
catchsql {
|
sl@0
|
106 |
CREATE TRIGGER trig INSTEAD OF INSERT ON echo_strings BEGIN
|
sl@0
|
107 |
SELECT 1, 2, 3;
|
sl@0
|
108 |
END;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
} {1 {cannot create triggers on virtual tables}}
|
sl@0
|
111 |
do_test vtab5.3.2 {
|
sl@0
|
112 |
catchsql {
|
sl@0
|
113 |
CREATE TRIGGER trig AFTER INSERT ON echo_strings BEGIN
|
sl@0
|
114 |
SELECT 1, 2, 3;
|
sl@0
|
115 |
END;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
} {1 {cannot create triggers on virtual tables}}
|
sl@0
|
118 |
do_test vtab5.3.2 {
|
sl@0
|
119 |
catchsql {
|
sl@0
|
120 |
CREATE TRIGGER trig BEFORE INSERT ON echo_strings BEGIN
|
sl@0
|
121 |
SELECT 1, 2, 3;
|
sl@0
|
122 |
END;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
} {1 {cannot create triggers on virtual tables}}
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
# Test that it is impossible to create an index on a virtual table.
|
sl@0
|
128 |
#
|
sl@0
|
129 |
do_test vtab5.4.1 {
|
sl@0
|
130 |
catchsql {
|
sl@0
|
131 |
CREATE INDEX echo_strings_i ON echo_strings(str);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
} {1 {virtual tables may not be indexed}}
|
sl@0
|
134 |
|
sl@0
|
135 |
# Test that it is impossible to add a column to a virtual table.
|
sl@0
|
136 |
#
|
sl@0
|
137 |
do_test vtab5.4.2 {
|
sl@0
|
138 |
catchsql {
|
sl@0
|
139 |
ALTER TABLE echo_strings ADD COLUMN col2;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
} {1 {virtual tables may not be altered}}
|
sl@0
|
142 |
|
sl@0
|
143 |
# Test that it is impossible to rename a virtual table.
|
sl@0
|
144 |
# UPDATE: It is now possible.
|
sl@0
|
145 |
#
|
sl@0
|
146 |
# do_test vtab5.4.3 {
|
sl@0
|
147 |
# catchsql {
|
sl@0
|
148 |
# ALTER TABLE echo_strings RENAME TO echo_strings2;
|
sl@0
|
149 |
# }
|
sl@0
|
150 |
# } {1 {virtual tables may not be altered}}
|
sl@0
|
151 |
|
sl@0
|
152 |
finish_test
|