diff options
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/misc7.test')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/test/misc7.test | 439 |
1 files changed, 439 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/misc7.test b/libraries/sqlite/unix/sqlite-3.5.1/test/misc7.test new file mode 100644 index 0000000..ea856f2 --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/misc7.test | |||
@@ -0,0 +1,439 @@ | |||
1 | # 2006 September 4 | ||
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. | ||
12 | # | ||
13 | # $Id: misc7.test,v 1.15 2007/08/22 20:18:22 drh Exp $ | ||
14 | |||
15 | set testdir [file dirname $argv0] | ||
16 | source $testdir/tester.tcl | ||
17 | |||
18 | #do_test misc7-1 { | ||
19 | # c_misuse_test | ||
20 | #} {} | ||
21 | |||
22 | do_test misc7-2 { | ||
23 | c_realloc_test | ||
24 | } {} | ||
25 | |||
26 | do_test misc7-3 { | ||
27 | c_collation_test | ||
28 | } {} | ||
29 | |||
30 | # Try to open a directory: | ||
31 | # | ||
32 | do_test misc7-4 { | ||
33 | file delete mydir | ||
34 | file mkdir mydir | ||
35 | set rc [catch { | ||
36 | sqlite3 db2 ./mydir | ||
37 | } msg] | ||
38 | list $rc $msg | ||
39 | } {1 {unable to open database file}} | ||
40 | |||
41 | # Try to open a file with a directory where it's journal file should be. | ||
42 | # | ||
43 | do_test misc7-5 { | ||
44 | file delete mydir | ||
45 | file mkdir mydir-journal | ||
46 | sqlite3 db2 ./mydir | ||
47 | catchsql { | ||
48 | CREATE TABLE abc(a, b, c); | ||
49 | } db2 | ||
50 | } {1 {unable to open database file}} | ||
51 | db2 close | ||
52 | |||
53 | #-------------------------------------------------------------------- | ||
54 | # The following tests, misc7-6.* test the libraries behaviour when | ||
55 | # it cannot open a file. To force this condition, we use up all the | ||
56 | # file-descriptors before running sqlite. This probably only works | ||
57 | # on unix. | ||
58 | # | ||
59 | |||
60 | proc use_up_files {} { | ||
61 | set ret [list] | ||
62 | catch { | ||
63 | while 1 { lappend ret [open test.db] } | ||
64 | } | ||
65 | return $ret | ||
66 | } | ||
67 | |||
68 | proc do_fileopen_test {prefix sql} { | ||
69 | set fd_list [use_up_files] | ||
70 | set ::go 1 | ||
71 | set ::n 1 | ||
72 | set ::sql $sql | ||
73 | while {$::go} { | ||
74 | catch {db close} | ||
75 | do_test ${prefix}.${::n} { | ||
76 | set rc [catch { | ||
77 | sqlite db test.db | ||
78 | db eval $::sql | ||
79 | } msg] | ||
80 | if {$rc == 0} {set ::go 0} | ||
81 | |||
82 | expr {$rc == 0 || ($rc == 1 && [string first unable $msg]==0)} | ||
83 | } 1 | ||
84 | |||
85 | close [lindex $fd_list 0] | ||
86 | set fd_list [lrange $fd_list 1 end] | ||
87 | incr ::n | ||
88 | } | ||
89 | foreach fd $fd_list { | ||
90 | close $fd | ||
91 | } | ||
92 | db close | ||
93 | } | ||
94 | |||
95 | execsql { CREATE TABLE abc(a PRIMARY KEY, b, c); } | ||
96 | db close | ||
97 | |||
98 | if {$tcl_platform(platform)!="windows"} { | ||
99 | do_fileopen_test misc7-6.1 { | ||
100 | BEGIN; | ||
101 | INSERT INTO abc VALUES(1, 2, 3); | ||
102 | INSERT INTO abc VALUES(2, 3, 4); | ||
103 | INSERT INTO abc SELECT a+2, b, c FROM abc; | ||
104 | COMMIT; | ||
105 | } | ||
106 | |||
107 | do_fileopen_test misc7-6.2 { | ||
108 | PRAGMA temp.cache_size = 1000; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | # | ||
113 | # End of tests for out-of-file-descriptors condition. | ||
114 | #-------------------------------------------------------------------- | ||
115 | |||
116 | sqlite3 db test.db | ||
117 | execsql { | ||
118 | DELETE FROM abc; | ||
119 | INSERT INTO abc VALUES(1, 2, 3); | ||
120 | INSERT INTO abc VALUES(2, 3, 4); | ||
121 | INSERT INTO abc SELECT a+2, b, c FROM abc; | ||
122 | } | ||
123 | |||
124 | |||
125 | #-------------------------------------------------------------------- | ||
126 | # Test that the sqlite3_busy_timeout call seems to delay approximately | ||
127 | # the right amount of time. | ||
128 | # | ||
129 | do_test misc7-7.0 { | ||
130 | sqlite3 db2 test.db | ||
131 | sqlite3_busy_timeout [sqlite3_connection_pointer db] 2000 | ||
132 | execsql { | ||
133 | BEGIN EXCLUSIVE; | ||
134 | } db2 | ||
135 | |||
136 | # Now db2 has an exclusive lock on the database file, and db has | ||
137 | # a busy-timeout of 2000 milliseconds. So check that trying to | ||
138 | # access the database using connection db delays for at least 1500 ms. | ||
139 | # | ||
140 | set tm [time { | ||
141 | set result [catchsql { | ||
142 | SELECT * FROM sqlite_master; | ||
143 | } db] | ||
144 | }] | ||
145 | set delay [lindex $tm 0] ;# In microseconds | ||
146 | lappend result [expr {$delay>1500000 && $delay<4000000}] | ||
147 | } {1 {database is locked} 1} | ||
148 | db2 close | ||
149 | |||
150 | #-------------------------------------------------------------------- | ||
151 | # Test that nothing goes horribly wrong when attaching a database | ||
152 | # after the omit_readlock pragma has been exercised. | ||
153 | # | ||
154 | do_test misc7-7.1 { | ||
155 | file delete -force test2.db | ||
156 | file delete -force test2.db-journal | ||
157 | execsql { | ||
158 | PRAGMA omit_readlock = 1; | ||
159 | ATTACH 'test2.db' AS aux; | ||
160 | CREATE TABLE aux.hello(world); | ||
161 | SELECT name FROM aux.sqlite_master; | ||
162 | } | ||
163 | } {hello} | ||
164 | do_test misc7-7.2 { | ||
165 | execsql { | ||
166 | DETACH aux; | ||
167 | } | ||
168 | } {} | ||
169 | |||
170 | # Test the UTF-16 version of the "out of memory" message (used when | ||
171 | # malloc fails during sqlite3_open() ). | ||
172 | # | ||
173 | ifcapable utf16 { | ||
174 | do_test misc7-8 { | ||
175 | encoding convertfrom unicode [sqlite3_errmsg16 0x00000000] | ||
176 | } {out of memory} | ||
177 | } | ||
178 | |||
179 | do_test misc7-9 { | ||
180 | execsql { | ||
181 | SELECT * | ||
182 | FROM (SELECT name+1 AS one FROM sqlite_master LIMIT 1 OFFSET 1) | ||
183 | WHERE one LIKE 'hello%'; | ||
184 | } | ||
185 | } {} | ||
186 | |||
187 | #-------------------------------------------------------------------- | ||
188 | # Improve coverage for vtab code. | ||
189 | # | ||
190 | ifcapable vtab { | ||
191 | # Run some debug code to improve reported coverage | ||
192 | # | ||
193 | |||
194 | # set sqlite_where_trace 1 | ||
195 | do_test misc7-10 { | ||
196 | register_echo_module [sqlite3_connection_pointer db] | ||
197 | execsql { | ||
198 | CREATE VIRTUAL TABLE t1 USING echo(abc); | ||
199 | SELECT a FROM t1 WHERE a = 1 ORDER BY b; | ||
200 | } | ||
201 | } {1} | ||
202 | set sqlite_where_trace 0 | ||
203 | |||
204 | # Specify an ORDER BY clause that cannot be indexed. | ||
205 | do_test misc7-11 { | ||
206 | execsql { | ||
207 | SELECT t1.a, t2.a FROM t1, t1 AS t2 ORDER BY 2 LIMIT 1; | ||
208 | } | ||
209 | } {1 1} | ||
210 | |||
211 | # The whole point of this is to test an error code other than | ||
212 | # SQLITE_NOMEM from the vtab xBestIndex callback. | ||
213 | # | ||
214 | do_ioerr_test misc7-12 -tclprep { | ||
215 | sqlite3 db2 test.db | ||
216 | register_echo_module [sqlite3_connection_pointer db2] | ||
217 | db2 eval { | ||
218 | CREATE TABLE abc(a PRIMARY KEY, b, c); | ||
219 | INSERT INTO abc VALUES(1, 2, 3); | ||
220 | CREATE VIRTUAL TABLE t1 USING echo(abc); | ||
221 | } | ||
222 | db2 close | ||
223 | } -tclbody { | ||
224 | register_echo_module [sqlite3_connection_pointer db] | ||
225 | execsql {SELECT * FROM t1 WHERE a = 1;} | ||
226 | } | ||
227 | |||
228 | # The case where the virtual table module returns a very large number | ||
229 | # as the cost of a scan (greater than SQLITE_BIG_DOUBLE in the code). | ||
230 | # | ||
231 | do_test misc7-13 { | ||
232 | sqlite3 db test.db | ||
233 | register_echo_module [sqlite3_connection_pointer db] | ||
234 | set ::echo_module_cost 2.0e+99 | ||
235 | execsql {SELECT * FROM t1 WHERE a = 1;} | ||
236 | } {1 2 3} | ||
237 | unset ::echo_module_cost | ||
238 | } | ||
239 | |||
240 | db close | ||
241 | file delete -force test.db | ||
242 | file delete -force test.db-journal | ||
243 | sqlite3 db test.db | ||
244 | |||
245 | ifcapable explain { | ||
246 | do_test misc7-14 { | ||
247 | execsql { | ||
248 | CREATE TABLE abc(a PRIMARY KEY, b, c); | ||
249 | } | ||
250 | execsql { | ||
251 | EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid = 1; | ||
252 | } | ||
253 | } {0 0 {TABLE abc AS t2 USING PRIMARY KEY}} | ||
254 | do_test misc7-15 { | ||
255 | execsql { | ||
256 | EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE a = 1; | ||
257 | } | ||
258 | } {0 0 {TABLE abc AS t2 WITH INDEX sqlite_autoindex_abc_1}} | ||
259 | } | ||
260 | |||
261 | db close | ||
262 | file delete -force test.db | ||
263 | file delete -force test.db-journal | ||
264 | sqlite3 db test.db | ||
265 | |||
266 | #-------------------------------------------------------------------- | ||
267 | # This is all to force the pager_remove_from_stmt_list() function | ||
268 | # (inside pager.c) to remove a pager from the middle of the | ||
269 | # statement-list. | ||
270 | # | ||
271 | do_test misc7-15.1 { | ||
272 | execsql { | ||
273 | PRAGMA cache_size = 10; | ||
274 | BEGIN; | ||
275 | CREATE TABLE abc(a PRIMARY KEY, b, c); | ||
276 | INSERT INTO abc | ||
277 | VALUES(randstr(100,100), randstr(100,100), randstr(100,100)); | ||
278 | INSERT INTO abc SELECT | ||
279 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
280 | INSERT INTO abc SELECT | ||
281 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
282 | INSERT INTO abc SELECT | ||
283 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
284 | INSERT INTO abc SELECT | ||
285 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
286 | INSERT INTO abc SELECT | ||
287 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
288 | INSERT INTO abc SELECT | ||
289 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
290 | INSERT INTO abc SELECT | ||
291 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
292 | INSERT INTO abc SELECT | ||
293 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
294 | COMMIT; | ||
295 | } | ||
296 | expr {[file size test.db]>10240} | ||
297 | } {1} | ||
298 | do_test misc7-15.2 { | ||
299 | execsql { | ||
300 | DELETE FROM abc WHERE rowid > 12; | ||
301 | INSERT INTO abc SELECT | ||
302 | randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; | ||
303 | } | ||
304 | } {} | ||
305 | |||
306 | db close | ||
307 | file delete -force test.db | ||
308 | file delete -force test.db-journal | ||
309 | sqlite3 db test.db | ||
310 | |||
311 | do_ioerr_test misc7-16 -sqlprep { | ||
312 | PRAGMA cache_size = 10; | ||
313 | PRAGMA default_cache_size = 10; | ||
314 | CREATE TABLE t3(a, b, UNIQUE(a, b)); | ||
315 | INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); | ||
316 | INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; | ||
317 | INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; | ||
318 | INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; | ||
319 | INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; | ||
320 | INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; | ||
321 | UPDATE t3 | ||
322 | SET b = 'hello world' | ||
323 | WHERE rowid >= (SELECT max(rowid)-1 FROM t3); | ||
324 | } -tclbody { | ||
325 | set rc [catch {db eval { | ||
326 | BEGIN; | ||
327 | PRAGMA cache_size = 10; | ||
328 | INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); | ||
329 | UPDATE t3 SET a = b; | ||
330 | COMMIT; | ||
331 | }} msg] | ||
332 | |||
333 | if {!$rc || ($rc && [string first "columns" $msg]==0)} { | ||
334 | set msg | ||
335 | } else { | ||
336 | error $msg | ||
337 | } | ||
338 | } | ||
339 | |||
340 | sqlite3 db test.db | ||
341 | |||
342 | do_test misc7-16.X { | ||
343 | execsql { | ||
344 | SELECT count(*) FROM t3; | ||
345 | } | ||
346 | } {32} | ||
347 | |||
348 | set sqlite_pager_n_sort_bucket 4 | ||
349 | do_test misc7-17 { | ||
350 | execsql { | ||
351 | PRAGMA integrity_check; | ||
352 | VACUUM; | ||
353 | PRAGMA integrity_check; | ||
354 | } | ||
355 | } {ok ok} | ||
356 | set sqlite_pager_n_sort_bucket 0 | ||
357 | |||
358 | #---------------------------------------------------------------------- | ||
359 | # Test the situation where a hot-journal is discovered but write-access | ||
360 | # to it is denied. This should return SQLITE_BUSY. | ||
361 | # | ||
362 | # These tests do not work on windows due to restrictions in the | ||
363 | # windows file system. | ||
364 | # | ||
365 | if {$tcl_platform(platform)!="windows"} { | ||
366 | do_test misc7-17.1 { | ||
367 | execsql { | ||
368 | BEGIN; | ||
369 | DELETE FROM t3 WHERE (oid%3)==0; | ||
370 | } | ||
371 | copy_file test.db bak.db | ||
372 | copy_file test.db-journal bak.db-journal | ||
373 | execsql { | ||
374 | COMMIT; | ||
375 | } | ||
376 | |||
377 | db close | ||
378 | copy_file bak.db test.db | ||
379 | copy_file bak.db-journal test.db-journal | ||
380 | sqlite3 db test.db | ||
381 | |||
382 | catch {file attributes test.db-journal -permissions r--------} | ||
383 | catch {file attributes test.db-journal -readonly 1} | ||
384 | catchsql { | ||
385 | SELECT count(*) FROM t3; | ||
386 | } | ||
387 | } {1 {database is locked}} | ||
388 | do_test misc7-17.2 { | ||
389 | catch {file attributes test.db-journal -permissions rw-------} | ||
390 | catch {file attributes test.db-journal -readonly 0} | ||
391 | catchsql { | ||
392 | SELECT count(*) FROM t3; | ||
393 | } | ||
394 | } {0 32} | ||
395 | |||
396 | set ::pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1] | ||
397 | do_test misc7-17.3 { | ||
398 | db eval { | ||
399 | pragma writable_schema = true; | ||
400 | UPDATE sqlite_master | ||
401 | SET rootpage = $pending_byte_page | ||
402 | WHERE type = 'table' AND name = 't3'; | ||
403 | } | ||
404 | execsql { | ||
405 | SELECT rootpage FROM sqlite_master WHERE type = 'table' AND name = 't3'; | ||
406 | } | ||
407 | } $::pending_byte_page | ||
408 | |||
409 | do_test misc7-17.4 { | ||
410 | db close | ||
411 | sqlite3 db test.db | ||
412 | catchsql { | ||
413 | SELECT count(*) FROM t3; | ||
414 | } | ||
415 | } {1 {database disk image is malformed}} | ||
416 | } | ||
417 | |||
418 | # Ticket #2470 | ||
419 | # | ||
420 | do_test misc7-18.1 { | ||
421 | execsql { | ||
422 | CREATE TABLE table_1 (col_10); | ||
423 | CREATE TABLE table_2 ( | ||
424 | col_1, col_2, col_3, col_4, col_5, | ||
425 | col_6, col_7, col_8, col_9, col_10 | ||
426 | ); | ||
427 | SELECT col_10 | ||
428 | FROM | ||
429 | (SELECT table_1.col_10 AS col_10 FROM table_1), | ||
430 | (SELECT table_1.col_10, table_2.col_9 AS qcol_9 | ||
431 | FROM table_1, table_2 | ||
432 | GROUP BY table_1.col_10, qcol_9); | ||
433 | } | ||
434 | } {} | ||
435 | |||
436 | db close | ||
437 | file delete -force test.db | ||
438 | |||
439 | finish_test | ||