Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/sqlite/test/vacuum.test

Issue 3108030: Move bundled copy of sqlite one level deeper to better separate it... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/test/utf16align.test ('k') | third_party/sqlite/test/vacuum2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # 2001 September 15
2 #
3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
5 #
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.
9 #
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the VACUUM statement.
13 #
14 # $Id: vacuum.test,v 1.43 2009/01/31 14:54:07 danielk1977 Exp $
15
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18
19 # If the VACUUM statement is disabled in the current build, skip all
20 # the tests in this file.
21 #
22 ifcapable {!vacuum} {
23 omit_test vacuum.test {Compiled with SQLITE_OMIT_VACUUM}
24 finish_test
25 return
26 }
27 if $AUTOVACUUM {
28 omit_test vacuum.test {Auto-vacuum is enabled}
29 finish_test
30 return
31 }
32
33 set fcnt 1
34 do_test vacuum-1.1 {
35 execsql {
36 BEGIN;
37 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
38 INSERT INTO t1 VALUES(NULL,randstr(10,100),randstr(5,50));
39 INSERT INTO t1 VALUES(123456,randstr(10,100),randstr(5,50));
40 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
41 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
42 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
43 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
44 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
45 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
46 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
47 CREATE INDEX i1 ON t1(b,c);
48 CREATE UNIQUE INDEX i2 ON t1(c,a);
49 CREATE TABLE t2 AS SELECT * FROM t1;
50 COMMIT;
51 DROP TABLE t2;
52 }
53 set ::size1 [file size test.db]
54 set ::cksum [cksum]
55 expr {$::cksum!=""}
56 } {1}
57 do_test vacuum-1.2 {
58 execsql {
59 VACUUM;
60 }
61 cksum
62 } $cksum
63 ifcapable vacuum {
64 do_test vacuum-1.3 {
65 expr {[file size test.db]<$::size1}
66 } {1}
67 }
68 do_test vacuum-1.4 {
69 set sql_script {
70 BEGIN;
71 CREATE TABLE t2 AS SELECT * FROM t1;
72 CREATE TABLE t3 AS SELECT * FROM t1;
73 CREATE VIEW v1 AS SELECT b, c FROM t3;
74 CREATE TRIGGER r1 AFTER DELETE ON t2 BEGIN SELECT 1; END;
75 COMMIT;
76 DROP TABLE t2;
77 }
78 # If the library was compiled to omit view support, comment out the
79 # create view in the script $sql_script before executing it. Similarly,
80 # if triggers are not supported, comment out the trigger definition.
81 ifcapable !view {
82 regsub {CREATE VIEW} $sql_script {-- CREATE VIEW} sql_script
83 }
84 ifcapable !trigger {
85 regsub {CREATE TRIGGER} $sql_script {-- CREATE TRIGGER} sql_script
86 }
87 execsql $sql_script
88 set ::size1 [file size test.db]
89 set ::cksum [cksum]
90 expr {$::cksum!=""}
91 } {1}
92 do_test vacuum-1.5 {
93 execsql {
94 VACUUM;
95 }
96 cksum
97 } $cksum
98
99 ifcapable vacuum {
100 do_test vacuum-1.6 {
101 expr {[file size test.db]<$::size1}
102 } {1}
103 }
104 ifcapable vacuum {
105 do_test vacuum-2.1.1 {
106 catchsql {
107 BEGIN;
108 VACUUM;
109 }
110 } {1 {cannot VACUUM from within a transaction}}
111 do_test vacuum-2.1.2 {
112 sqlite3_get_autocommit db
113 } {0}
114 do_test vacuum-2.1.3 {
115 db eval {COMMIT}
116 } {}
117 }
118 do_test vacuum-2.2 {
119 sqlite3 db2 test.db
120 execsql {
121 BEGIN;
122 CREATE TABLE t4 AS SELECT * FROM t1;
123 CREATE TABLE t5 AS SELECT * FROM t1;
124 COMMIT;
125 DROP TABLE t4;
126 DROP TABLE t5;
127 } db2
128 set ::cksum [cksum db2]
129 catchsql {
130 VACUUM
131 }
132 } {0 {}}
133 do_test vacuum-2.3 {
134 cksum
135 } $cksum
136 do_test vacuum-2.4 {
137 catch {db2 eval {SELECT count(*) FROM sqlite_master}}
138 cksum db2
139 } $cksum
140
141 # Make sure the schema cookie is incremented by vacuum.
142 #
143 do_test vacuum-2.5 {
144 execsql {
145 BEGIN;
146 CREATE TABLE t6 AS SELECT * FROM t1;
147 CREATE TABLE t7 AS SELECT * FROM t1;
148 COMMIT;
149 }
150 sqlite3 db3 test.db
151 execsql {
152 -- The "SELECT * FROM sqlite_master" statement ensures that this test
153 -- works when shared-cache is enabled. If shared-cache is enabled, then
154 -- db3 shares a cache with db2 (but not db - it was opened as
155 -- "./test.db").
156 SELECT * FROM sqlite_master;
157 SELECT * FROM t7 LIMIT 1
158 } db3
159 execsql {
160 VACUUM;
161 }
162 execsql {
163 INSERT INTO t7 VALUES(1234567890,'hello','world');
164 } db3
165 execsql {
166 SELECT * FROM t7 WHERE a=1234567890
167 }
168 } {1234567890 hello world}
169 integrity_check vacuum-2.6
170 do_test vacuum-2.7 {
171 execsql {
172 SELECT * FROM t7 WHERE a=1234567890
173 } db3
174 } {1234567890 hello world}
175 do_test vacuum-2.8 {
176 execsql {
177 INSERT INTO t7 SELECT * FROM t6;
178 SELECT count(*) FROM t7;
179 }
180 } 513
181 integrity_check vacuum-2.9
182 do_test vacuum-2.10 {
183 execsql {
184 DELETE FROM t7;
185 SELECT count(*) FROM t7;
186 } db3
187 } 0
188 integrity_check vacuum-2.11
189 db3 close
190
191
192 # Ticket #427. Make sure VACUUM works when the EMPTY_RESULT_CALLBACKS
193 # pragma is turned on.
194 #
195 do_test vacuum-3.1 {
196 db close
197 db2 close
198 file delete test.db
199 sqlite3 db test.db
200 execsql {
201 PRAGMA empty_result_callbacks=on;
202 VACUUM;
203 }
204 } {}
205
206 # Ticket #464. Make sure VACUUM works with the sqlite3_prepare() API.
207 #
208 do_test vacuum-4.1 {
209 db close
210 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
211 set VM [sqlite3_prepare $DB {VACUUM} -1 TAIL]
212 sqlite3_step $VM
213 } {SQLITE_DONE}
214 do_test vacuum-4.2 {
215 sqlite3_finalize $VM
216 } SQLITE_OK
217
218 # Ticket #515. VACUUM after deleting and recreating the table that
219 # a view refers to. Omit this test if the library is not view-enabled.
220 #
221 ifcapable view {
222 do_test vacuum-5.1 {
223 db close
224 file delete -force test.db
225 sqlite3 db test.db
226 catchsql {
227 CREATE TABLE Test (TestID int primary key);
228 INSERT INTO Test VALUES (NULL);
229 CREATE VIEW viewTest AS SELECT * FROM Test;
230
231 BEGIN;
232 CREATE TABLE tempTest (TestID int primary key, Test2 int NULL);
233 INSERT INTO tempTest SELECT TestID, 1 FROM Test;
234 DROP TABLE Test;
235 CREATE TABLE Test(TestID int primary key, Test2 int NULL);
236 INSERT INTO Test SELECT * FROM tempTest;
237 DROP TABLE tempTest;
238 COMMIT;
239 VACUUM;
240 }
241 } {0 {}}
242 do_test vacuum-5.2 {
243 catchsql {
244 VACUUM;
245 }
246 } {0 {}}
247 } ;# ifcapable view
248
249 # Ensure vacuum works with complicated tables names.
250 do_test vacuum-6.1 {
251 execsql {
252 CREATE TABLE "abc abc"(a, b, c);
253 INSERT INTO "abc abc" VALUES(1, 2, 3);
254 VACUUM;
255 }
256 } {}
257 do_test vacuum-6.2 {
258 execsql {
259 select * from "abc abc";
260 }
261 } {1 2 3}
262
263 # Also ensure that blobs survive a vacuum.
264 ifcapable {bloblit} {
265 do_test vacuum-6.3 {
266 execsql {
267 DELETE FROM "abc abc";
268 INSERT INTO "abc abc" VALUES(X'00112233', NULL, NULL);
269 VACUUM;
270 }
271 } {}
272 do_test vacuum-6.4 {
273 execsql {
274 select count(*) from "abc abc" WHERE a = X'00112233';
275 }
276 } {1}
277 }
278
279 # Check what happens when an in-memory database is vacuumed. The
280 # [file delete] command covers us in case the library was compiled
281 # without in-memory database support.
282 #
283 file delete -force :memory:
284 do_test vacuum-7.0 {
285 sqlite3 db2 :memory:
286 execsql {
287 CREATE TABLE t1(t);
288 VACUUM;
289 } db2
290 execsql {
291 CREATE TABLE t2(t);
292 CREATE TABLE t3(t);
293 DROP TABLE t2;
294 VACUUM;
295 pragma integrity_check;
296 } db2
297 } {ok}
298 db2 close
299
300 # Ticket #873. VACUUM a database that has ' in its name.
301 #
302 do_test vacuum-8.1 {
303 file delete -force a'z.db
304 file delete -force a'z.db-journal
305 sqlite3 db2 a'z.db
306 execsql {
307 CREATE TABLE t1(t);
308 VACUUM;
309 } db2
310 } {}
311 db2 close
312
313 # Ticket #1095: Vacuum a table that uses AUTOINCREMENT
314 #
315 ifcapable {autoinc} {
316 do_test vacuum-9.1 {
317 execsql {
318 DROP TABLE 'abc abc';
319 CREATE TABLE autoinc(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
320 INSERT INTO autoinc(b) VALUES('hi');
321 INSERT INTO autoinc(b) VALUES('there');
322 DELETE FROM autoinc;
323 }
324 set ::cksum [cksum]
325 expr {$::cksum!=""}
326 } {1}
327 do_test vacuum-9.2 {
328 execsql {
329 VACUUM;
330 }
331 cksum
332 } $::cksum
333 do_test vacuum-9.3 {
334 execsql {
335 INSERT INTO autoinc(b) VALUES('one');
336 INSERT INTO autoinc(b) VALUES('two');
337 }
338 set ::cksum [cksum]
339 expr {$::cksum!=""}
340 } {1}
341 do_test vacuum-9.4 {
342 execsql {
343 VACUUM;
344 }
345 cksum
346 } $::cksum
347 }
348
349 file delete -force {a'z.db}
350
351 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/test/utf16align.test ('k') | third_party/sqlite/test/vacuum2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698