blob: fefd5e8a8fc631e62084b74cca2a54f4c7da4dd6 [file] [log] [blame]
drhb19a2bc2001-09-16 00:13:26 +00001# 2001 September 15
drh348784e2000-05-29 20:41:49 +00002#
drhb19a2bc2001-09-16 00:13:26 +00003# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
drh348784e2000-05-29 20:41:49 +00005#
drhb19a2bc2001-09-16 00:13:26 +00006# 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.
drh348784e2000-05-29 20:41:49 +00009#
10#***********************************************************************
11# This file implements some common TCL routines used for regression
12# testing the SQLite library
13#
drhbb77b752009-04-09 01:23:49 +000014# $Id: tester.tcl,v 1.143 2009/04/09 01:23:49 drh Exp $
drhfbc3eab2001-04-06 16:13:42 +000015
danc1a60c52010-06-07 14:28:16 +000016#-------------------------------------------------------------------------
mistachkin1d406e02013-08-29 01:09:14 +000017# The commands provided by the code in this file to help with creating
danc1a60c52010-06-07 14:28:16 +000018# test cases are as follows:
drh8359d8c2008-03-29 11:00:54 +000019#
danc1a60c52010-06-07 14:28:16 +000020# Commands to manipulate the db and the file-system at a high level:
drh8359d8c2008-03-29 11:00:54 +000021#
mistachkinc5484652012-03-05 22:52:33 +000022# is_relative_file
mistachkin4a41f342012-03-06 03:00:49 +000023# test_pwd
mistachkinf8a78462012-03-08 20:00:36 +000024# get_pwd
danc1a60c52010-06-07 14:28:16 +000025# copy_file FROM TO
mistachkinfda06be2011-08-02 00:57:34 +000026# delete_file FILENAME
dan6f343962011-07-01 18:26:40 +000027# drop_all_tables ?DB?
mistachkinfda06be2011-08-02 00:57:34 +000028# forcecopy FROM TO
danc1a60c52010-06-07 14:28:16 +000029# forcedelete FILENAME
30#
31# Test the capability of the SQLite version built into the interpreter to
32# determine if a specific test can be run:
33#
mistachkinc60941f2012-09-13 01:51:02 +000034# capable EXPR
danc1a60c52010-06-07 14:28:16 +000035# ifcapable EXPR
36#
37# Calulate checksums based on database contents:
38#
39# dbcksum DB DBNAME
40# allcksum ?DB?
41# cksum ?DB?
42#
43# Commands to execute/explain SQL statements:
44#
mistachkin1d406e02013-08-29 01:09:14 +000045# memdbsql SQL
danc1a60c52010-06-07 14:28:16 +000046# stepsql DB SQL
47# execsql2 SQL
48# explain_no_trace SQL
49# explain SQL ?DB?
50# catchsql SQL ?DB?
51# execsql SQL ?DB?
52#
53# Commands to run test cases:
54#
55# do_ioerr_test TESTNAME ARGS...
56# crashsql ARGS...
57# integrity_check TESTNAME ?DB?
drh433dccf2013-02-09 15:37:11 +000058# verify_ex_errcode TESTNAME EXPECTED ?DB?
danc1a60c52010-06-07 14:28:16 +000059# do_test TESTNAME SCRIPT EXPECTED
dan153eda02010-06-21 07:45:47 +000060# do_execsql_test TESTNAME SQL EXPECTED
61# do_catchsql_test TESTNAME SQL EXPECTED
drh3c2aeae2014-01-24 14:37:44 +000062# do_timed_execsql_test TESTNAME SQL EXPECTED
danc1a60c52010-06-07 14:28:16 +000063#
dan430e74c2010-06-07 17:47:26 +000064# Commands providing a lower level interface to the global test counters:
danc1a60c52010-06-07 14:28:16 +000065#
66# set_test_counter COUNTER ?VALUE?
mistachkin6c3c1a02011-11-12 03:17:40 +000067# omit_test TESTNAME REASON ?APPEND?
danc1a60c52010-06-07 14:28:16 +000068# fail_test TESTNAME
69# incr_ntest
70#
71# Command run at the end of each test file:
72#
73# finish_test
74#
dan430e74c2010-06-07 17:47:26 +000075# Commands to help create test files that run with the "WAL" and other
76# permutations (see file permutations.test):
danc1a60c52010-06-07 14:28:16 +000077#
78# wal_is_wal_mode
79# wal_set_journal_mode ?DB?
80# wal_check_journal_mode TESTNAME?DB?
dan430e74c2010-06-07 17:47:26 +000081# permutation
dancb79e512010-08-06 13:50:07 +000082# presql
danc1a60c52010-06-07 14:28:16 +000083#
drh348784e2000-05-29 20:41:49 +000084
mistachkin1d406e02013-08-29 01:09:14 +000085# Set the precision of FP arithmatic used by the interpreter. And
danc1a60c52010-06-07 14:28:16 +000086# configure SQLite to take database file locks on the page that begins
87# 64KB into the database file instead of the one 1GB in. This means
88# the code that handles that special case can be tested without creating
89# very large database files.
90#
drh92febd92004-08-20 18:34:20 +000091set tcl_precision 15
drhc7a3bb92009-02-05 16:31:45 +000092sqlite3_test_control_pending_byte 0x0010000
drh92febd92004-08-20 18:34:20 +000093
danc1a60c52010-06-07 14:28:16 +000094
mistachkin1d406e02013-08-29 01:09:14 +000095# If the pager codec is available, create a wrapper for the [sqlite3]
danc1a60c52010-06-07 14:28:16 +000096# command that appends "-key {xyzzy}" to the command line. i.e. this:
drh3a7fb7c2007-08-10 16:41:08 +000097#
danc1a60c52010-06-07 14:28:16 +000098# sqlite3 db test.db
drh4a50aac2007-08-23 02:47:53 +000099#
danc1a60c52010-06-07 14:28:16 +0000100# becomes
drh4a50aac2007-08-23 02:47:53 +0000101#
danc1a60c52010-06-07 14:28:16 +0000102# sqlite3 db test.db -key {xyzzy}
drh9eb9e262004-02-11 02:18:05 +0000103#
dan430e74c2010-06-07 17:47:26 +0000104if {[info command sqlite_orig]==""} {
drhef4ac8f2004-06-19 00:16:31 +0000105 rename sqlite3 sqlite_orig
106 proc sqlite3 {args} {
dan68928b62010-06-22 13:46:43 +0000107 if {[llength $args]>=2 && [string index [lindex $args 0] 0]!="-"} {
dan430e74c2010-06-07 17:47:26 +0000108 # This command is opening a new database connection.
109 #
110 if {[info exists ::G(perm:sqlite3_args)]} {
111 set args [concat $args $::G(perm:sqlite3_args)]
112 }
dan68928b62010-06-22 13:46:43 +0000113 if {[sqlite_orig -has-codec] && ![info exists ::do_not_use_codec]} {
dan430e74c2010-06-07 17:47:26 +0000114 lappend args -key {xyzzy}
115 }
116
dan3ccd20a2010-06-09 19:01:02 +0000117 set res [uplevel 1 sqlite_orig $args]
dan430e74c2010-06-07 17:47:26 +0000118 if {[info exists ::G(perm:presql)]} {
119 [lindex $args 0] eval $::G(perm:presql)
120 }
dan1ce1b4a2010-12-07 14:32:28 +0000121 if {[info exists ::G(perm:dbconfig)]} {
122 set ::dbhandle [lindex $args 0]
123 uplevel #0 $::G(perm:dbconfig)
124 }
dan3ccd20a2010-06-09 19:01:02 +0000125 set res
dan430e74c2010-06-07 17:47:26 +0000126 } else {
mistachkin1d406e02013-08-29 01:09:14 +0000127 # This command is not opening a new database connection. Pass the
mistachkin48864df2013-03-21 21:20:32 +0000128 # arguments through to the C implementation as the are.
dan430e74c2010-06-07 17:47:26 +0000129 #
130 uplevel 1 sqlite_orig $args
drh9eb9e262004-02-11 02:18:05 +0000131 }
drh9eb9e262004-02-11 02:18:05 +0000132 }
133}
134
mistachkinfda06be2011-08-02 00:57:34 +0000135proc getFileRetries {} {
136 if {![info exists ::G(file-retries)]} {
137 #
138 # NOTE: Return the default number of retries for [file] operations. A
139 # value of zero or less here means "disabled".
140 #
mistachkinc60941f2012-09-13 01:51:02 +0000141 return [expr {$::tcl_platform(platform) eq "windows" ? 50 : 0}]
mistachkinfda06be2011-08-02 00:57:34 +0000142 }
143 return $::G(file-retries)
144}
145
146proc getFileRetryDelay {} {
147 if {![info exists ::G(file-retry-delay)]} {
148 #
149 # NOTE: Return the default number of milliseconds to wait when retrying
150 # failed [file] operations. A value of zero or less means "do not
151 # wait".
152 #
153 return 100; # TODO: Good default?
154 }
155 return $::G(file-retry-delay)
156}
157
mistachkinf8a78462012-03-08 20:00:36 +0000158# Return the string representing the name of the current directory. On
159# Windows, the result is "normalized" to whatever our parent command shell
160# is using to prevent case-mismatch issues.
161#
162proc get_pwd {} {
163 if {$::tcl_platform(platform) eq "windows"} {
mistachkin533b8f62012-03-08 20:28:31 +0000164 #
165 # NOTE: Cannot use [file normalize] here because it would alter the
166 # case of the result to what Tcl considers canonical, which would
167 # defeat the purpose of this procedure.
168 #
169 return [string map [list \\ /] \
170 [string trim [exec -- $::env(ComSpec) /c echo %CD%]]]
mistachkinf8a78462012-03-08 20:00:36 +0000171 } else {
172 return [pwd]
173 }
174}
175
mistachkinfda06be2011-08-02 00:57:34 +0000176# Copy file $from into $to. This is used because some versions of
177# TCL for windows (notably the 8.4.1 binary package shipped with the
178# current mingw release) have a broken "file copy" command.
179#
180proc copy_file {from to} {
181 do_copy_file false $from $to
182}
183
184proc forcecopy {from to} {
185 do_copy_file true $from $to
186}
187
188proc do_copy_file {force from to} {
189 set nRetry [getFileRetries] ;# Maximum number of retries.
190 set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
191
192 # On windows, sometimes even a [file copy -force] can fail. The cause is
193 # usually "tag-alongs" - programs like anti-virus software, automatic backup
194 # tools and various explorer extensions that keep a file open a little longer
195 # than we expect, causing the delete to fail.
196 #
197 # The solution is to wait a short amount of time before retrying the copy.
198 #
199 if {$nRetry > 0} {
200 for {set i 0} {$i<$nRetry} {incr i} {
201 set rc [catch {
202 if {$force} {
203 file copy -force $from $to
204 } else {
205 file copy $from $to
206 }
207 } msg]
208 if {$rc==0} break
209 if {$nDelay > 0} { after $nDelay }
210 }
211 if {$rc} { error $msg }
212 } else {
213 if {$force} {
214 file copy -force $from $to
215 } else {
216 file copy $from $to
217 }
218 }
219}
220
mistachkinc5484652012-03-05 22:52:33 +0000221# Check if a file name is relative
222#
223proc is_relative_file { file } {
224 return [expr {[file pathtype $file] != "absolute"}]
225}
226
mistachkin4a41f342012-03-06 03:00:49 +0000227# If the VFS supports using the current directory, returns [pwd];
228# otherwise, it returns only the provided suffix string (which is
229# empty by default).
230#
231proc test_pwd { args } {
232 if {[llength $args] > 0} {
233 set suffix1 [lindex $args 0]
234 if {[llength $args] > 1} {
235 set suffix2 [lindex $args 1]
236 } else {
237 set suffix2 $suffix1
238 }
239 } else {
240 set suffix1 ""; set suffix2 ""
241 }
242 ifcapable curdir {
mistachkin6aa18c92012-03-08 20:22:42 +0000243 return "[get_pwd]$suffix1"
mistachkin4a41f342012-03-06 03:00:49 +0000244 } else {
245 return $suffix2
246 }
247}
248
mistachkinfda06be2011-08-02 00:57:34 +0000249# Delete a file or directory
250#
251proc delete_file {args} {
252 do_delete_file false {*}$args
253}
254
255proc forcedelete {args} {
256 do_delete_file true {*}$args
257}
258
259proc do_delete_file {force args} {
260 set nRetry [getFileRetries] ;# Maximum number of retries.
261 set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
262
263 foreach filename $args {
264 # On windows, sometimes even a [file delete -force] can fail just after
265 # a file is closed. The cause is usually "tag-alongs" - programs like
266 # anti-virus software, automatic backup tools and various explorer
267 # extensions that keep a file open a little longer than we expect, causing
268 # the delete to fail.
269 #
270 # The solution is to wait a short amount of time before retrying the
271 # delete.
272 #
273 if {$nRetry > 0} {
274 for {set i 0} {$i<$nRetry} {incr i} {
275 set rc [catch {
276 if {$force} {
277 file delete -force $filename
278 } else {
279 file delete $filename
280 }
281 } msg]
282 if {$rc==0} break
283 if {$nDelay > 0} { after $nDelay }
284 }
285 if {$rc} { error $msg }
286 } else {
287 if {$force} {
288 file delete -force $filename
289 } else {
290 file delete $filename
291 }
292 }
293 }
294}
295
mistachkin1d406e02013-08-29 01:09:14 +0000296if {$::tcl_platform(platform) eq "windows"} {
297 proc do_remove_win32_dir {args} {
298 set nRetry [getFileRetries] ;# Maximum number of retries.
299 set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
300
301 foreach dirName $args {
302 # On windows, sometimes even a [remove_win32_dir] can fail just after
303 # a directory is emptied. The cause is usually "tag-alongs" - programs
304 # like anti-virus software, automatic backup tools and various explorer
305 # extensions that keep a file open a little longer than we expect,
306 # causing the delete to fail.
307 #
308 # The solution is to wait a short amount of time before retrying the
309 # removal.
310 #
311 if {$nRetry > 0} {
312 for {set i 0} {$i < $nRetry} {incr i} {
313 set rc [catch {
314 remove_win32_dir $dirName
315 } msg]
316 if {$rc == 0} break
317 if {$nDelay > 0} { after $nDelay }
318 }
319 if {$rc} { error $msg }
320 } else {
321 remove_win32_dir $dirName
322 }
323 }
324 }
325
326 proc do_delete_win32_file {args} {
327 set nRetry [getFileRetries] ;# Maximum number of retries.
328 set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
329
330 foreach fileName $args {
331 # On windows, sometimes even a [delete_win32_file] can fail just after
332 # a file is closed. The cause is usually "tag-alongs" - programs like
333 # anti-virus software, automatic backup tools and various explorer
334 # extensions that keep a file open a little longer than we expect,
335 # causing the delete to fail.
336 #
337 # The solution is to wait a short amount of time before retrying the
338 # delete.
339 #
340 if {$nRetry > 0} {
341 for {set i 0} {$i < $nRetry} {incr i} {
342 set rc [catch {
343 delete_win32_file $fileName
344 } msg]
345 if {$rc == 0} break
346 if {$nDelay > 0} { after $nDelay }
347 }
348 if {$rc} { error $msg }
349 } else {
350 delete_win32_file $fileName
351 }
352 }
353 }
354}
355
dancb354602010-07-08 09:44:42 +0000356proc execpresql {handle args} {
357 trace remove execution $handle enter [list execpresql $handle]
358 if {[info exists ::G(perm:presql)]} {
359 $handle eval $::G(perm:presql)
360 }
361}
362
dan68928b62010-06-22 13:46:43 +0000363# This command should be called after loading tester.tcl from within
364# all test scripts that are incompatible with encryption codecs.
365#
366proc do_not_use_codec {} {
367 set ::do_not_use_codec 1
368 reset_db
369}
370
dan430e74c2010-06-07 17:47:26 +0000371# The following block only runs the first time this file is sourced. It
372# does not run in slave interpreters (since the ::cmdlinearg array is
373# populated before the test script is run in slave interpreters).
drhbec2bf42000-05-29 23:48:22 +0000374#
danc1a60c52010-06-07 14:28:16 +0000375if {[info exists cmdlinearg]==0} {
376
mistachkin1d406e02013-08-29 01:09:14 +0000377 # Parse any options specified in the $argv array. This script accepts the
378 # following options:
danc1a60c52010-06-07 14:28:16 +0000379 #
380 # --pause
381 # --soft-heap-limit=NN
382 # --maxerror=NN
383 # --malloctrace=N
384 # --backtrace=N
385 # --binarylog=N
dan0626dfc2010-06-15 06:56:37 +0000386 # --soak=N
mistachkinfda06be2011-08-02 00:57:34 +0000387 # --file-retries=N
388 # --file-retry-delay=N
dan6a64d672011-04-04 15:38:16 +0000389 # --start=[$permutation:]$testfile
mistachkin6c3c1a02011-11-12 03:17:40 +0000390 # --match=$pattern
danc1a60c52010-06-07 14:28:16 +0000391 #
392 set cmdlinearg(soft-heap-limit) 0
393 set cmdlinearg(maxerror) 1000
394 set cmdlinearg(malloctrace) 0
395 set cmdlinearg(backtrace) 10
396 set cmdlinearg(binarylog) 0
dan0626dfc2010-06-15 06:56:37 +0000397 set cmdlinearg(soak) 0
mistachkinfda06be2011-08-02 00:57:34 +0000398 set cmdlinearg(file-retries) 0
399 set cmdlinearg(file-retry-delay) 0
mistachkin6c3c1a02011-11-12 03:17:40 +0000400 set cmdlinearg(start) ""
401 set cmdlinearg(match) ""
danc1a60c52010-06-07 14:28:16 +0000402
403 set leftover [list]
404 foreach a $argv {
405 switch -regexp -- $a {
406 {^-+pause$} {
mistachkin1d406e02013-08-29 01:09:14 +0000407 # Wait for user input before continuing. This is to give the user an
danc1a60c52010-06-07 14:28:16 +0000408 # opportunity to connect profiling tools to the process.
409 puts -nonewline "Press RETURN to begin..."
410 flush stdout
411 gets stdin
412 }
413 {^-+soft-heap-limit=.+$} {
414 foreach {dummy cmdlinearg(soft-heap-limit)} [split $a =] break
415 }
416 {^-+maxerror=.+$} {
417 foreach {dummy cmdlinearg(maxerror)} [split $a =] break
418 }
419 {^-+malloctrace=.+$} {
420 foreach {dummy cmdlinearg(malloctrace)} [split $a =] break
421 if {$cmdlinearg(malloctrace)} {
422 sqlite3_memdebug_log start
423 }
424 }
425 {^-+backtrace=.+$} {
426 foreach {dummy cmdlinearg(backtrace)} [split $a =] break
dan0626dfc2010-06-15 06:56:37 +0000427 sqlite3_memdebug_backtrace $value
danc1a60c52010-06-07 14:28:16 +0000428 }
danc1a60c52010-06-07 14:28:16 +0000429 {^-+binarylog=.+$} {
430 foreach {dummy cmdlinearg(binarylog)} [split $a =] break
431 }
dan0626dfc2010-06-15 06:56:37 +0000432 {^-+soak=.+$} {
433 foreach {dummy cmdlinearg(soak)} [split $a =] break
434 set ::G(issoak) $cmdlinearg(soak)
435 }
mistachkinfda06be2011-08-02 00:57:34 +0000436 {^-+file-retries=.+$} {
437 foreach {dummy cmdlinearg(file-retries)} [split $a =] break
438 set ::G(file-retries) $cmdlinearg(file-retries)
439 }
440 {^-+file-retry-delay=.+$} {
441 foreach {dummy cmdlinearg(file-retry-delay)} [split $a =] break
442 set ::G(file-retry-delay) $cmdlinearg(file-retry-delay)
443 }
dan6a64d672011-04-04 15:38:16 +0000444 {^-+start=.+$} {
445 foreach {dummy cmdlinearg(start)} [split $a =] break
446
447 set ::G(start:file) $cmdlinearg(start)
448 if {[regexp {(.*):(.*)} $cmdlinearg(start) -> s.perm s.file]} {
449 set ::G(start:permutation) ${s.perm}
450 set ::G(start:file) ${s.file}
451 }
452 if {$::G(start:file) == ""} {unset ::G(start:file)}
453 }
mistachkin6c3c1a02011-11-12 03:17:40 +0000454 {^-+match=.+$} {
455 foreach {dummy cmdlinearg(match)} [split $a =] break
456
457 set ::G(match) $cmdlinearg(match)
458 if {$::G(match) == ""} {unset ::G(match)}
459 }
danc1a60c52010-06-07 14:28:16 +0000460 default {
461 lappend leftover $a
462 }
463 }
464 }
465 set argv $leftover
466
dan430e74c2010-06-07 17:47:26 +0000467 # Install the malloc layer used to inject OOM errors. And the 'automatic'
468 # extensions. This only needs to be done once for the process.
469 #
mistachkin1d406e02013-08-29 01:09:14 +0000470 sqlite3_shutdown
471 install_malloc_faultsim 1
danielk1977f7b9d662008-06-23 18:49:43 +0000472 sqlite3_initialize
drhbb77b752009-04-09 01:23:49 +0000473 autoinstall_test_functions
danc1a60c52010-06-07 14:28:16 +0000474
dan430e74c2010-06-07 17:47:26 +0000475 # If the --binarylog option was specified, create the logging VFS. This
476 # call installs the new VFS as the default for all SQLite connections.
477 #
danc1a60c52010-06-07 14:28:16 +0000478 if {$cmdlinearg(binarylog)} {
danfbefb892010-05-12 19:02:35 +0000479 vfslog new binarylog {} vfslog.bin
danc1a60c52010-06-07 14:28:16 +0000480 }
481
482 # Set the backtrace depth, if malloc tracing is enabled.
483 #
484 if {$cmdlinearg(malloctrace)} {
485 sqlite3_memdebug_backtrace $cmdlinearg(backtrace)
danielk1977185eac92008-07-12 15:55:54 +0000486 }
danielk1977f7b9d662008-06-23 18:49:43 +0000487}
danielk197703ba3fa2009-01-09 10:49:14 +0000488
danc1a60c52010-06-07 14:28:16 +0000489# Update the soft-heap-limit each time this script is run. In that
490# way if an individual test file changes the soft-heap-limit, it
491# will be reset at the start of the next test file.
492#
493sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
494
495# Create a test database
496#
danielk197703ba3fa2009-01-09 10:49:14 +0000497proc reset_db {} {
498 catch {db close}
mistachkinfda06be2011-08-02 00:57:34 +0000499 forcedelete test.db
500 forcedelete test.db-journal
501 forcedelete test.db-wal
danielk197703ba3fa2009-01-09 10:49:14 +0000502 sqlite3 db ./test.db
503 set ::DB [sqlite3_connection_pointer db]
504 if {[info exists ::SETUP_SQL]} {
505 db eval $::SETUP_SQL
506 }
drhcd61c282002-03-06 22:01:34 +0000507}
danielk197703ba3fa2009-01-09 10:49:14 +0000508reset_db
drhbec2bf42000-05-29 23:48:22 +0000509
510# Abort early if this script has been run before.
511#
danc1a60c52010-06-07 14:28:16 +0000512if {[info exists TC(count)]} return
drhbec2bf42000-05-29 23:48:22 +0000513
drhce2198c2010-09-10 13:22:59 +0000514# Make sure memory statistics are enabled.
515#
516sqlite3_config_memstatus 1
517
danc1a60c52010-06-07 14:28:16 +0000518# Initialize the test counters and set up commands to access them.
519# Or, if this is a slave interpreter, set up aliases to write the
520# counters in the parent interpreter.
drhbec2bf42000-05-29 23:48:22 +0000521#
danc1a60c52010-06-07 14:28:16 +0000522if {0==[info exists ::SLAVE]} {
523 set TC(errors) 0
524 set TC(count) 0
525 set TC(fail_list) [list]
526 set TC(omit_list) [list]
drhcca17c32013-04-19 12:32:52 +0000527 set TC(warn_list) [list]
danc1a60c52010-06-07 14:28:16 +0000528
529 proc set_test_counter {counter args} {
530 if {[llength $args]} {
531 set ::TC($counter) [lindex $args 0]
532 }
533 set ::TC($counter)
534 }
drhb62c3352006-11-23 09:39:16 +0000535}
drh348784e2000-05-29 20:41:49 +0000536
drh521cc842008-04-15 02:36:33 +0000537# Record the fact that a sequence of tests were omitted.
538#
mistachkin6c3c1a02011-11-12 03:17:40 +0000539proc omit_test {name reason {append 1}} {
danc1a60c52010-06-07 14:28:16 +0000540 set omitList [set_test_counter omit_list]
mistachkin6c3c1a02011-11-12 03:17:40 +0000541 if {$append} {
542 lappend omitList [list $name $reason]
543 }
danc1a60c52010-06-07 14:28:16 +0000544 set_test_counter omit_list $omitList
drh521cc842008-04-15 02:36:33 +0000545}
546
danc1a60c52010-06-07 14:28:16 +0000547# Record the fact that a test failed.
548#
549proc fail_test {name} {
550 set f [set_test_counter fail_list]
551 lappend f $name
552 set_test_counter fail_list $f
553 set_test_counter errors [expr [set_test_counter errors] + 1]
554
555 set nFail [set_test_counter errors]
556 if {$nFail>=$::cmdlinearg(maxerror)} {
557 puts "*** Giving up..."
558 finalize_testing
559 }
560}
561
drhcca17c32013-04-19 12:32:52 +0000562# Remember a warning message to be displayed at the conclusion of all testing
563#
564proc warning {msg {append 1}} {
565 puts "Warning: $msg"
566 set warnList [set_test_counter warn_list]
567 if {$append} {
568 lappend warnList $msg
569 }
570 set_test_counter warn_list $warnList
571}
572
573
danc1a60c52010-06-07 14:28:16 +0000574# Increment the number of tests run
575#
576proc incr_ntest {} {
577 set_test_counter count [expr [set_test_counter count] + 1]
578}
579
580
mistachkin1d406e02013-08-29 01:09:14 +0000581# Invoke the do_test procedure to run a single test
drh348784e2000-05-29 20:41:49 +0000582#
583proc do_test {name cmd expected} {
danc1a60c52010-06-07 14:28:16 +0000584 global argv cmdlinearg
585
dan8c408002010-11-01 17:38:24 +0000586 fix_testname name
587
drh4a50aac2007-08-23 02:47:53 +0000588 sqlite3_memdebug_settitle $name
danc1a60c52010-06-07 14:28:16 +0000589
mistachkin1d406e02013-08-29 01:09:14 +0000590# if {[llength $argv]==0} {
dan92d516a2010-07-05 14:54:48 +0000591# set go 1
592# } else {
593# set go 0
594# foreach pattern $argv {
595# if {[string match $pattern $name]} {
596# set go 1
597# break
598# }
599# }
600# }
dan430e74c2010-06-07 17:47:26 +0000601
dand506de02010-07-03 13:59:01 +0000602 if {[info exists ::G(perm:prefix)]} {
603 set name "$::G(perm:prefix)$name"
dan430e74c2010-06-07 17:47:26 +0000604 }
605
danc1a60c52010-06-07 14:28:16 +0000606 incr_ntest
drh5edc3122001-09-13 21:53:09 +0000607 puts -nonewline $name...
drh348784e2000-05-29 20:41:49 +0000608 flush stdout
mistachkin6c3c1a02011-11-12 03:17:40 +0000609
610 if {![info exists ::G(match)] || [string match $::G(match) $name]} {
611 if {[catch {uplevel #0 "$cmd;\n"} result]} {
612 puts "\nError: $result"
613 fail_test $name
mistachkin6c3c1a02011-11-12 03:17:40 +0000614 } else {
drh3f17aef2012-04-27 01:08:02 +0000615 if {[regexp {^~?/.*/$} $expected]} {
drh70bdcc72013-05-30 19:28:34 +0000616 # "expected" is of the form "/PATTERN/" then the result if correct if
617 # regular expression PATTERN matches the result. "~/PATTERN/" means
618 # the regular expression must not match.
drh3f17aef2012-04-27 01:08:02 +0000619 if {[string index $expected 0]=="~"} {
drhc2b23e72013-11-13 15:32:15 +0000620 set re [string range $expected 2 end-1]
621 if {[string index $re 0]=="*"} {
622 # If the regular expression begins with * then treat it as a glob instead
623 set ok [string match $re $result]
624 } else {
625 set re [string map {# {[-0-9.]+}} $re]
626 set ok [regexp $re $result]
627 }
628 set ok [expr {!$ok}]
drh3f17aef2012-04-27 01:08:02 +0000629 } else {
drhc2b23e72013-11-13 15:32:15 +0000630 set re [string range $expected 1 end-1]
631 if {[string index $re 0]=="*"} {
632 # If the regular expression begins with * then treat it as a glob instead
633 set ok [string match $re $result]
634 } else {
635 set re [string map {# {[-0-9.]+}} $re]
636 set ok [regexp $re $result]
637 }
drh3f17aef2012-04-27 01:08:02 +0000638 }
drh70bdcc72013-05-30 19:28:34 +0000639 } elseif {[regexp {^~?\*.*\*$} $expected]} {
640 # "expected" is of the form "*GLOB*" then the result if correct if
641 # glob pattern GLOB matches the result. "~/GLOB/" means
642 # the glob must not match.
643 if {[string index $expected 0]=="~"} {
644 set e [string range $expected 1 end]
645 set ok [expr {![string match $e $result]}]
646 } else {
647 set ok [string match $expected $result]
648 }
drh3f17aef2012-04-27 01:08:02 +0000649 } else {
650 set ok [expr {[string compare $result $expected]==0}]
651 }
652 if {!$ok} {
mistachkinc60941f2012-09-13 01:51:02 +0000653 # if {![info exists ::testprefix] || $::testprefix eq ""} {
654 # error "no test prefix"
655 # }
drh3f17aef2012-04-27 01:08:02 +0000656 puts "\nExpected: \[$expected\]\n Got: \[$result\]"
657 fail_test $name
658 } else {
659 puts " Ok"
660 }
mistachkin6c3c1a02011-11-12 03:17:40 +0000661 }
drh348784e2000-05-29 20:41:49 +0000662 } else {
mistachkin6c3c1a02011-11-12 03:17:40 +0000663 puts " Omitted"
664 omit_test $name "pattern mismatch" 0
drh348784e2000-05-29 20:41:49 +0000665 }
drh6558db82007-04-13 03:23:21 +0000666 flush stdout
drh348784e2000-05-29 20:41:49 +0000667}
dana3f51082010-09-30 18:43:14 +0000668
drh8df91852012-04-24 12:46:05 +0000669proc catchcmd {db {cmd ""}} {
670 global CLI
671 set out [open cmds.txt w]
672 puts $out $cmd
673 close $out
674 set line "exec $CLI $db < cmds.txt"
675 set rc [catch { eval $line } msg]
676 list $rc $msg
677}
678
shaneh55505172011-06-21 19:30:19 +0000679proc filepath_normalize {p} {
680 # test cases should be written to assume "unix"-like file paths
shaneh285a18f2011-06-21 19:39:59 +0000681 if {$::tcl_platform(platform)!="unix"} {
shaneh55505172011-06-21 19:30:19 +0000682 # lreverse*2 as a hack to remove any unneeded {} after the string map
683 lreverse [lreverse [string map {\\ /} [regsub -nocase -all {[a-z]:[/\\]+} $p {/}]]]
shanehc4896402011-06-21 19:38:16 +0000684 } {
685 set p
shaneh55505172011-06-21 19:30:19 +0000686 }
687}
688proc do_filepath_test {name cmd expected} {
689 uplevel [list do_test $name [
690 subst -nocommands { filepath_normalize [ $cmd ] }
691 ] [filepath_normalize $expected]]
692}
693
dan33f53792011-05-05 19:44:22 +0000694proc realnum_normalize {r} {
shaneh4f529e82011-06-20 17:41:41 +0000695 # different TCL versions display floating point values differently.
696 string map {1.#INF inf Inf inf .0e e} [regsub -all {(e[+-])0+} $r {\1}]
dan33f53792011-05-05 19:44:22 +0000697}
698proc do_realnum_test {name cmd expected} {
699 uplevel [list do_test $name [
700 subst -nocommands { realnum_normalize [ $cmd ] }
701 ] [realnum_normalize $expected]]
702}
703
dana3f51082010-09-30 18:43:14 +0000704proc fix_testname {varname} {
705 upvar $varname testname
mistachkin1d406e02013-08-29 01:09:14 +0000706 if {[info exists ::testprefix]
dana3f51082010-09-30 18:43:14 +0000707 && [string is digit [string range $testname 0 0]]
708 } {
709 set testname "${::testprefix}-$testname"
710 }
711}
mistachkin1d406e02013-08-29 01:09:14 +0000712
dan57f7f4b2010-10-01 19:04:37 +0000713proc do_execsql_test {testname sql {result {}}} {
dana3f51082010-09-30 18:43:14 +0000714 fix_testname testname
dan99ebad92011-06-13 09:11:01 +0000715 uplevel do_test [list $testname] [list "execsql {$sql}"] [list [list {*}$result]]
dan153eda02010-06-21 07:45:47 +0000716}
717proc do_catchsql_test {testname sql result} {
dana3f51082010-09-30 18:43:14 +0000718 fix_testname testname
dan99ebad92011-06-13 09:11:01 +0000719 uplevel do_test [list $testname] [list "catchsql {$sql}"] [list $result]
dan153eda02010-06-21 07:45:47 +0000720}
drh3c2aeae2014-01-24 14:37:44 +0000721proc do_timed_execsql_test {testname sql {result {}}} {
722 fix_testname testname
723 uplevel do_test [list $testname] [list "execsql_timed {$sql}"]\
724 [list [list {*}$result]]
725}
dan39854792010-11-15 16:12:58 +0000726proc do_eqp_test {name sql res} {
727 uplevel do_execsql_test $name [list "EXPLAIN QUERY PLAN $sql"] [list $res]
728}
dan153eda02010-06-21 07:45:47 +0000729
dan51f06982010-09-18 19:00:12 +0000730#-------------------------------------------------------------------------
731# Usage: do_select_tests PREFIX ?SWITCHES? TESTLIST
732#
733# Where switches are:
734#
735# -errorformat FMTSTRING
736# -count
danaf1dcab2010-09-20 19:17:53 +0000737# -query SQL
dana16d1062010-09-28 17:37:28 +0000738# -tclquery TCL
danaf7626f2010-09-23 18:47:36 +0000739# -repair TCL
dan51f06982010-09-18 19:00:12 +0000740#
741proc do_select_tests {prefix args} {
742
743 set testlist [lindex $args end]
744 set switches [lrange $args 0 end-1]
745
746 set errfmt ""
747 set countonly 0
dana16d1062010-09-28 17:37:28 +0000748 set tclquery ""
danaf7626f2010-09-23 18:47:36 +0000749 set repair ""
dan51f06982010-09-18 19:00:12 +0000750
751 for {set i 0} {$i < [llength $switches]} {incr i} {
752 set s [lindex $switches $i]
753 set n [string length $s]
danaf1dcab2010-09-20 19:17:53 +0000754 if {$n>=2 && [string equal -length $n $s "-query"]} {
dana16d1062010-09-28 17:37:28 +0000755 set tclquery [list execsql [lindex $switches [incr i]]]
756 } elseif {$n>=2 && [string equal -length $n $s "-tclquery"]} {
757 set tclquery [lindex $switches [incr i]]
danaf1dcab2010-09-20 19:17:53 +0000758 } elseif {$n>=2 && [string equal -length $n $s "-errorformat"]} {
dan51f06982010-09-18 19:00:12 +0000759 set errfmt [lindex $switches [incr i]]
danaf7626f2010-09-23 18:47:36 +0000760 } elseif {$n>=2 && [string equal -length $n $s "-repair"]} {
761 set repair [lindex $switches [incr i]]
dan51f06982010-09-18 19:00:12 +0000762 } elseif {$n>=2 && [string equal -length $n $s "-count"]} {
763 set countonly 1
764 } else {
765 error "unknown switch: $s"
766 }
767 }
768
769 if {$countonly && $errfmt!=""} {
770 error "Cannot use -count and -errorformat together"
771 }
772 set nTestlist [llength $testlist]
773 if {$nTestlist%3 || $nTestlist==0 } {
774 error "SELECT test list contains [llength $testlist] elements"
775 }
776
danaf7626f2010-09-23 18:47:36 +0000777 eval $repair
dan51f06982010-09-18 19:00:12 +0000778 foreach {tn sql res} $testlist {
dana16d1062010-09-28 17:37:28 +0000779 if {$tclquery != ""} {
danaf1dcab2010-09-20 19:17:53 +0000780 execsql $sql
dana16d1062010-09-28 17:37:28 +0000781 uplevel do_test ${prefix}.$tn [list $tclquery] [list [list {*}$res]]
782 } elseif {$countonly} {
dan51f06982010-09-18 19:00:12 +0000783 set nRow 0
784 db eval $sql {incr nRow}
785 uplevel do_test ${prefix}.$tn [list [list set {} $nRow]] [list $res]
786 } elseif {$errfmt==""} {
787 uplevel do_execsql_test ${prefix}.${tn} [list $sql] [list [list {*}$res]]
788 } else {
789 set res [list 1 [string trim [format $errfmt {*}$res]]]
790 uplevel do_catchsql_test ${prefix}.${tn} [list $sql] [list $res]
791 }
danaf7626f2010-09-23 18:47:36 +0000792 eval $repair
dan51f06982010-09-18 19:00:12 +0000793 }
danaf7626f2010-09-23 18:47:36 +0000794
dan51f06982010-09-18 19:00:12 +0000795}
796
danb04757a2010-09-21 16:59:16 +0000797proc delete_all_data {} {
798 db eval {SELECT tbl_name AS t FROM sqlite_master WHERE type = 'table'} {
799 db eval "DELETE FROM '[string map {' ''} $t]'"
800 }
801}
drh348784e2000-05-29 20:41:49 +0000802
mistachkin1d406e02013-08-29 01:09:14 +0000803# Run an SQL script.
drhb62c3352006-11-23 09:39:16 +0000804# Return the number of microseconds per statement.
805#
drh3590f152006-11-23 21:09:10 +0000806proc speed_trial {name numstmt units sql} {
drhdd924312007-03-31 22:34:16 +0000807 puts -nonewline [format {%-21.21s } $name...]
drhb62c3352006-11-23 09:39:16 +0000808 flush stdout
809 set speed [time {sqlite3_exec_nr db $sql}]
810 set tm [lindex $speed 0]
danielk19770ee26d92008-02-08 18:25:29 +0000811 if {$tm == 0} {
812 set rate [format %20s "many"]
813 } else {
814 set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
815 }
drh3590f152006-11-23 21:09:10 +0000816 set u2 $units/s
danielk19770ee26d92008-02-08 18:25:29 +0000817 puts [format {%12d uS %s %s} $tm $rate $u2]
drhdd924312007-03-31 22:34:16 +0000818 global total_time
819 set total_time [expr {$total_time+$tm}]
dana975b592010-10-08 16:09:43 +0000820 lappend ::speed_trial_times $name $tm
drhdd924312007-03-31 22:34:16 +0000821}
drh45c236d2008-03-22 01:08:00 +0000822proc speed_trial_tcl {name numstmt units script} {
823 puts -nonewline [format {%-21.21s } $name...]
824 flush stdout
825 set speed [time {eval $script}]
826 set tm [lindex $speed 0]
827 if {$tm == 0} {
828 set rate [format %20s "many"]
829 } else {
830 set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
831 }
832 set u2 $units/s
833 puts [format {%12d uS %s %s} $tm $rate $u2]
834 global total_time
835 set total_time [expr {$total_time+$tm}]
dana975b592010-10-08 16:09:43 +0000836 lappend ::speed_trial_times $name $tm
drh45c236d2008-03-22 01:08:00 +0000837}
drhdd924312007-03-31 22:34:16 +0000838proc speed_trial_init {name} {
839 global total_time
840 set total_time 0
dana975b592010-10-08 16:09:43 +0000841 set ::speed_trial_times [list]
drhbb810a92010-07-03 12:00:53 +0000842 sqlite3 versdb :memory:
843 set vers [versdb one {SELECT sqlite_source_id()}]
844 versdb close
845 puts "SQLite $vers"
drhdd924312007-03-31 22:34:16 +0000846}
847proc speed_trial_summary {name} {
848 global total_time
849 puts [format {%-21.21s %12d uS TOTAL} $name $total_time]
dana975b592010-10-08 16:09:43 +0000850
851 if { 0 } {
852 sqlite3 versdb :memory:
853 set vers [lindex [versdb one {SELECT sqlite_source_id()}] 0]
854 versdb close
855 puts "CREATE TABLE IF NOT EXISTS time(version, script, test, us);"
856 foreach {test us} $::speed_trial_times {
857 puts "INSERT INTO time VALUES('$vers', '$name', '$test', $us);"
858 }
859 }
drhb62c3352006-11-23 09:39:16 +0000860}
861
drh348784e2000-05-29 20:41:49 +0000862# Run this routine last
863#
864proc finish_test {} {
danc1a60c52010-06-07 14:28:16 +0000865 catch {db close}
866 catch {db2 close}
867 catch {db3 close}
868 if {0==[info exists ::SLAVE]} { finalize_testing }
drha1b351a2001-09-14 16:42:12 +0000869}
870proc finalize_testing {} {
danc1a60c52010-06-07 14:28:16 +0000871 global sqlite_open_file_count
872
873 set omitList [set_test_counter omit_list]
danielk19772e588c72005-12-09 14:25:08 +0000874
drh6e142f52000-06-08 13:36:40 +0000875 catch {db close}
danielk19772e588c72005-12-09 14:25:08 +0000876 catch {db2 close}
877 catch {db3 close}
878
drh9bc54492007-10-23 14:49:59 +0000879 vfs_unlink_test
drhb4bc7052006-01-11 23:40:33 +0000880 sqlite3 db {}
danielk1977cbb84962006-01-17 16:10:13 +0000881 # sqlite3_clear_tsd_memdebug
drhb4bc7052006-01-11 23:40:33 +0000882 db close
drh984bfaa2008-03-19 16:08:53 +0000883 sqlite3_reset_auto_extension
danc1a60c52010-06-07 14:28:16 +0000884
drh3a7fb7c2007-08-10 16:41:08 +0000885 sqlite3_soft_heap_limit 0
danc1a60c52010-06-07 14:28:16 +0000886 set nTest [incr_ntest]
887 set nErr [set_test_counter errors]
888
drhef866372013-05-22 20:49:02 +0000889 set nKnown 0
890 if {[file readable known-problems.txt]} {
891 set fd [open known-problems.txt]
892 set content [read $fd]
893 close $fd
894 foreach x $content {set known_error($x) 1}
895 foreach x [set_test_counter fail_list] {
896 if {[info exists known_error($x)]} {incr nKnown}
897 }
898 }
899 if {$nKnown>0} {
900 puts "[expr {$nErr-$nKnown}] new errors and $nKnown known errors\
901 out of $nTest tests"
902 } else {
903 puts "$nErr errors out of $nTest tests"
904 }
905 if {$nErr>$nKnown} {
906 puts -nonewline "Failures on these tests:"
907 foreach x [set_test_counter fail_list] {
908 if {![info exists known_error($x)]} {puts -nonewline " $x"}
909 }
910 puts ""
drhf3a65f72007-08-22 20:18:21 +0000911 }
drhcca17c32013-04-19 12:32:52 +0000912 foreach warning [set_test_counter warn_list] {
913 puts "Warning: $warning"
914 }
danielk1977ee8b7992009-03-26 17:13:06 +0000915 run_thread_tests 1
drh521cc842008-04-15 02:36:33 +0000916 if {[llength $omitList]>0} {
917 puts "Omitted test cases:"
918 set prec {}
919 foreach {rec} [lsort $omitList] {
920 if {$rec==$prec} continue
921 set prec $rec
922 puts [format { %-12s %s} [lindex $rec 0] [lindex $rec 1]]
923 }
924 }
drh80788d82006-09-02 14:50:23 +0000925 if {$nErr>0 && ![working_64bit_int]} {
926 puts "******************************************************************"
927 puts "N.B.: The version of TCL that you used to build this test harness"
928 puts "is defective in that it does not support 64-bit integers. Some or"
929 puts "all of the test failures above might be a result from this defect"
930 puts "in your TCL build."
931 puts "******************************************************************"
drhdb25e382001-03-15 18:21:22 +0000932 }
danc1a60c52010-06-07 14:28:16 +0000933 if {$::cmdlinearg(binarylog)} {
danfbefb892010-05-12 19:02:35 +0000934 vfslog finalize binarylog
danielk1977374177e2008-05-08 15:58:06 +0000935 }
drh94e92032003-02-16 22:21:32 +0000936 if {$sqlite_open_file_count} {
937 puts "$sqlite_open_file_count files were left open"
938 incr nErr
939 }
drheafc43b2010-07-26 18:43:40 +0000940 if {[lindex [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] 1]>0 ||
941 [sqlite3_memory_used]>0} {
942 puts "Unfreed memory: [sqlite3_memory_used] bytes in\
943 [lindex [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] 1] allocations"
drhf3a65f72007-08-22 20:18:21 +0000944 incr nErr
drh2d7636e2008-02-16 16:21:45 +0000945 ifcapable memdebug||mem5||(mem3&&debug) {
drh4a50aac2007-08-23 02:47:53 +0000946 puts "Writing unfreed memory log to \"./memleak.txt\""
947 sqlite3_memdebug_dump ./memleak.txt
948 }
drhf3a65f72007-08-22 20:18:21 +0000949 } else {
950 puts "All memory allocations freed - no leaks"
drh2d7636e2008-02-16 16:21:45 +0000951 ifcapable memdebug||mem5 {
drhd2bb3272007-10-15 19:34:32 +0000952 sqlite3_memdebug_dump ./memusage.txt
953 }
drhf3a65f72007-08-22 20:18:21 +0000954 }
drhf7141992008-06-19 00:16:08 +0000955 show_memstats
drh91fd4d42008-01-19 20:11:25 +0000956 puts "Maximum memory usage: [sqlite3_memory_highwater 1] bytes"
957 puts "Current memory usage: [sqlite3_memory_highwater] bytes"
danielk1977a7a8e142008-02-13 18:25:27 +0000958 if {[info commands sqlite3_memdebug_malloc_count] ne ""} {
959 puts "Number of malloc() : [sqlite3_memdebug_malloc_count] calls"
960 }
danc1a60c52010-06-07 14:28:16 +0000961 if {$::cmdlinearg(malloctrace)} {
danielk197735754ac2008-03-21 17:29:37 +0000962 puts "Writing mallocs.sql..."
963 memdebug_log_sql
964 sqlite3_memdebug_log stop
965 sqlite3_memdebug_log clear
danielk1977dbdc4d42008-03-28 07:42:53 +0000966
967 if {[sqlite3_memory_used]>0} {
968 puts "Writing leaks.sql..."
969 sqlite3_memdebug_log sync
970 memdebug_log_sql leaks.sql
971 }
danielk197735754ac2008-03-21 17:29:37 +0000972 }
drhd9910fe2006-10-04 11:55:49 +0000973 foreach f [glob -nocomplain test.db-*-journal] {
mistachkinfda06be2011-08-02 00:57:34 +0000974 forcedelete $f
drhd9910fe2006-10-04 11:55:49 +0000975 }
976 foreach f [glob -nocomplain test.db-mj*] {
mistachkinfda06be2011-08-02 00:57:34 +0000977 forcedelete $f
drhd9910fe2006-10-04 11:55:49 +0000978 }
drhdb25e382001-03-15 18:21:22 +0000979 exit [expr {$nErr>0}]
drh348784e2000-05-29 20:41:49 +0000980}
981
drhf7141992008-06-19 00:16:08 +0000982# Display memory statistics for analysis and debugging purposes.
983#
984proc show_memstats {} {
985 set x [sqlite3_status SQLITE_STATUS_MEMORY_USED 0]
drhe50135e2008-08-05 17:53:22 +0000986 set y [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0]
987 set val [format {now %10d max %10d max-size %10d} \
988 [lindex $x 1] [lindex $x 2] [lindex $y 2]]
drhf7141992008-06-19 00:16:08 +0000989 puts "Memory used: $val"
drheafc43b2010-07-26 18:43:40 +0000990 set x [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0]
991 set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]]
992 puts "Allocation count: $val"
drhf7141992008-06-19 00:16:08 +0000993 set x [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0]
drhe50135e2008-08-05 17:53:22 +0000994 set y [sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 0]
995 set val [format {now %10d max %10d max-size %10d} \
996 [lindex $x 1] [lindex $x 2] [lindex $y 2]]
drhf7141992008-06-19 00:16:08 +0000997 puts "Page-cache used: $val"
998 set x [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0]
999 set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]]
1000 puts "Page-cache overflow: $val"
1001 set x [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0]
1002 set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]]
1003 puts "Scratch memory used: $val"
1004 set x [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0]
drhe50135e2008-08-05 17:53:22 +00001005 set y [sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 0]
1006 set val [format {now %10d max %10d max-size %10d} \
1007 [lindex $x 1] [lindex $x 2] [lindex $y 2]]
drhf7141992008-06-19 00:16:08 +00001008 puts "Scratch overflow: $val"
drhec424a52008-07-25 15:39:03 +00001009 ifcapable yytrackmaxstackdepth {
1010 set x [sqlite3_status SQLITE_STATUS_PARSER_STACK 0]
1011 set val [format { max %10d} [lindex $x 2]]
1012 puts "Parser stack depth: $val"
1013 }
drhf7141992008-06-19 00:16:08 +00001014}
1015
drh348784e2000-05-29 20:41:49 +00001016# A procedure to execute SQL
1017#
drhc4a3c772001-04-04 11:48:57 +00001018proc execsql {sql {db db}} {
drhacbcdc42001-01-22 00:31:53 +00001019 # puts "SQL = $sql"
danielk19773bdca9c2006-01-17 09:35:01 +00001020 uplevel [list $db eval $sql]
drh348784e2000-05-29 20:41:49 +00001021}
drh3c2aeae2014-01-24 14:37:44 +00001022proc execsql_timed {sql {db db}} {
1023 set tm [time {
1024 set x [uplevel [list $db eval $sql]]
1025 } 1]
1026 set tm [lindex $tm 0]
1027 puts -nonewline " ([expr {$tm*0.001}]ms) "
1028 set x
1029}
drh3aadb2e2000-05-31 17:59:25 +00001030
drhadbca9c2001-09-27 15:11:53 +00001031# Execute SQL and catch exceptions.
1032#
1033proc catchsql {sql {db db}} {
1034 # puts "SQL = $sql"
dan81fa6dc2009-11-28 12:40:32 +00001035 set r [catch [list uplevel [list $db eval $sql]] msg]
drhadbca9c2001-09-27 15:11:53 +00001036 lappend r $msg
1037 return $r
1038}
1039
drh04096482001-11-09 22:41:44 +00001040# Do an VDBE code dump on the SQL given
1041#
1042proc explain {sql {db db}} {
1043 puts ""
danielk1977287fb612008-01-04 19:10:28 +00001044 puts "addr opcode p1 p2 p3 p4 p5 #"
1045 puts "---- ------------ ------ ------ ------ --------------- -- -"
drh04096482001-11-09 22:41:44 +00001046 $db eval "explain $sql" {} {
danielk1977287fb612008-01-04 19:10:28 +00001047 puts [format {%-4d %-12.12s %-6d %-6d %-6d % -17s %s %s} \
1048 $addr $opcode $p1 $p2 $p3 $p4 $p5 $comment
1049 ]
drh04096482001-11-09 22:41:44 +00001050 }
1051}
1052
dane83267d2013-11-05 14:19:22 +00001053proc explain_i {sql {db db}} {
1054 puts ""
1055 puts "addr opcode p1 p2 p3 p4 p5 #"
1056 puts "---- ------------ ------ ------ ------ ---------------- -- -"
1057
dane83267d2013-11-05 14:19:22 +00001058
dan5c663c32013-11-06 14:52:40 +00001059 # Set up colors for the different opcodes. Scheme is as follows:
1060 #
1061 # Red: Opcodes that write to a b-tree.
1062 # Blue: Opcodes that reposition or seek a cursor.
1063 # Green: The ResultRow opcode.
1064 #
1065 set R "\033\[31;1m" ;# Red fg
1066 set G "\033\[32;1m" ;# Green fg
1067 set B "\033\[34;1m" ;# Red fg
1068 set D "\033\[39;0m" ;# Default fg
1069 foreach opcode {
1070 Seek SeekGe SeekGt SeekLe SeekLt NotFound Last Rewind
dane3ab7292013-11-12 12:30:09 +00001071 NoConflict Next Prev VNext VPrev VFilter
dan5c663c32013-11-06 14:52:40 +00001072 } {
1073 set color($opcode) $B
1074 }
1075 foreach opcode {ResultRow} {
1076 set color($opcode) $G
1077 }
1078 foreach opcode {IdxInsert Insert Delete IdxDelete} {
1079 set color($opcode) $R
1080 }
1081
dan427ebba2013-11-05 16:39:31 +00001082 set bSeenGoto 0
dane83267d2013-11-05 14:19:22 +00001083 $db eval "explain $sql" {} {
1084 set x($addr) 0
1085 set op($addr) $opcode
1086
dan427ebba2013-11-05 16:39:31 +00001087 if {$opcode == "Goto" && ($bSeenGoto==0 || ($p2 > $addr+10))} {
1088 set linebreak($p2) 1
1089 set bSeenGoto 1
dane83267d2013-11-05 14:19:22 +00001090 }
1091
dane3ab7292013-11-12 12:30:09 +00001092 if {$opcode=="Next" || $opcode=="Prev"
1093 || $opcode=="VNext" || $opcode=="VPrev"
1094 } {
dane83267d2013-11-05 14:19:22 +00001095 for {set i $p2} {$i<$addr} {incr i} {
1096 incr x($i) 2
1097 }
1098 }
1099
1100 if {$opcode == "Goto" && $p2<$addr && $op($p2)=="Yield"} {
1101 for {set i [expr $p2+1]} {$i<$addr} {incr i} {
1102 incr x($i) 2
1103 }
1104 }
dan427ebba2013-11-05 16:39:31 +00001105
1106 if {$opcode == "Halt" && $comment == "End of coroutine"} {
1107 set linebreak([expr $addr+1]) 1
1108 }
dane83267d2013-11-05 14:19:22 +00001109 }
1110
1111 $db eval "explain $sql" {} {
dan427ebba2013-11-05 16:39:31 +00001112 if {[info exists linebreak($addr)]} {
dane83267d2013-11-05 14:19:22 +00001113 puts ""
1114 }
1115 set I [string repeat " " $x($addr)]
dan5c663c32013-11-06 14:52:40 +00001116
1117 set col ""
1118 catch { set col $color($opcode) }
1119
1120 puts [format {%-4d %s%s%-12.12s%s %-6d %-6d %-6d % -17s %s %s} \
1121 $addr $I $col $opcode $D $p1 $p2 $p3 $p4 $p5 $comment
dane83267d2013-11-05 14:19:22 +00001122 ]
dane83267d2013-11-05 14:19:22 +00001123 }
1124 puts "---- ------------ ------ ------ ------ ---------------- -- -"
1125}
1126
drhdafc0ce2008-04-17 19:14:02 +00001127# Show the VDBE program for an SQL statement but omit the Trace
1128# opcode at the beginning. This procedure can be used to prove
1129# that different SQL statements generate exactly the same VDBE code.
1130#
1131proc explain_no_trace {sql} {
1132 set tr [db eval "EXPLAIN $sql"]
1133 return [lrange $tr 7 end]
1134}
1135
drh3aadb2e2000-05-31 17:59:25 +00001136# Another procedure to execute SQL. This one includes the field
1137# names in the returned list.
1138#
1139proc execsql2 {sql} {
1140 set result {}
1141 db eval $sql data {
1142 foreach f $data(*) {
1143 lappend result $f $data($f)
1144 }
1145 }
1146 return $result
1147}
drh17a68932001-01-31 13:28:08 +00001148
mistachkin1d406e02013-08-29 01:09:14 +00001149# Use a temporary in-memory database to execute SQL statements
1150#
1151proc memdbsql {sql} {
1152 sqlite3 memdb :memory:
1153 set result [memdb eval $sql]
1154 memdb close
1155 return $result
1156}
1157
drhdde85d92003-03-01 19:45:34 +00001158# Use the non-callback API to execute multiple SQL statements
1159#
1160proc stepsql {dbptr sql} {
1161 set sql [string trim $sql]
1162 set r 0
1163 while {[string length $sql]>0} {
danielk19774ad17132004-05-21 01:47:26 +00001164 if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} {
drhdde85d92003-03-01 19:45:34 +00001165 return [list 1 $vm]
1166 }
1167 set sql [string trim $sqltail]
danielk1977fbcd5852004-06-15 02:44:18 +00001168# while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} {
1169# foreach v $VAL {lappend r $v}
1170# }
1171 while {[sqlite3_step $vm]=="SQLITE_ROW"} {
1172 for {set i 0} {$i<[sqlite3_data_count $vm]} {incr i} {
1173 lappend r [sqlite3_column_text $vm $i]
1174 }
drhdde85d92003-03-01 19:45:34 +00001175 }
danielk1977106bb232004-05-21 10:08:53 +00001176 if {[catch {sqlite3_finalize $vm} errmsg]} {
drhdde85d92003-03-01 19:45:34 +00001177 return [list 1 $errmsg]
1178 }
1179 }
1180 return $r
1181}
1182
drh21504322002-06-25 13:16:02 +00001183# Do an integrity check of the entire database
1184#
danielk197704103022009-02-03 16:51:24 +00001185proc integrity_check {name {db db}} {
drh27d258a2004-10-30 20:23:09 +00001186 ifcapable integrityck {
danielk197704103022009-02-03 16:51:24 +00001187 do_test $name [list execsql {PRAGMA integrity_check} $db] {ok}
drh27d258a2004-10-30 20:23:09 +00001188 }
1189}
1190
drh433dccf2013-02-09 15:37:11 +00001191# Check the extended error code
1192#
1193proc verify_ex_errcode {name expected {db db}} {
1194 do_test $name [list sqlite3_extended_errcode $db] $expected
1195}
1196
danc6055c72011-04-28 18:46:46 +00001197
1198# Return true if the SQL statement passed as the second argument uses a
1199# statement transaction.
1200#
1201proc sql_uses_stmt {db sql} {
1202 set stmt [sqlite3_prepare $db $sql -1 dummy]
1203 set uses [uses_stmt_journal $stmt]
1204 sqlite3_finalize $stmt
1205 return $uses
1206}
1207
danielk1977db4e8862008-01-16 08:24:46 +00001208proc fix_ifcapable_expr {expr} {
1209 set ret ""
1210 set state 0
1211 for {set i 0} {$i < [string length $expr]} {incr i} {
1212 set char [string range $expr $i $i]
1213 set newstate [expr {[string is alnum $char] || $char eq "_"}]
1214 if {$newstate && !$state} {
1215 append ret {$::sqlite_options(}
1216 }
1217 if {!$newstate && $state} {
1218 append ret )
1219 }
1220 append ret $char
1221 set state $newstate
1222 }
1223 if {$state} {append ret )}
1224 return $ret
1225}
1226
mistachkinc60941f2012-09-13 01:51:02 +00001227# Returns non-zero if the capabilities are present; zero otherwise.
1228#
1229proc capable {expr} {
1230 set e [fix_ifcapable_expr $expr]; return [expr ($e)]
1231}
1232
drh27d258a2004-10-30 20:23:09 +00001233# Evaluate a boolean expression of capabilities. If true, execute the
1234# code. Omit the code if false.
1235#
danielk19773e8c37e2005-01-21 03:12:14 +00001236proc ifcapable {expr code {else ""} {elsecode ""}} {
danielk1977db4e8862008-01-16 08:24:46 +00001237 #regsub -all {[a-z_0-9]+} $expr {$::sqlite_options(&)} e2
1238 set e2 [fix_ifcapable_expr $expr]
danielk19773e8c37e2005-01-21 03:12:14 +00001239 if ($e2) {
1240 set c [catch {uplevel 1 $code} r]
1241 } else {
1242 set c [catch {uplevel 1 $elsecode} r]
1243 }
1244 return -code $c $r
drh21504322002-06-25 13:16:02 +00001245}
danielk197745901d62004-11-10 15:27:38 +00001246
danielk1977aca790a2005-01-13 11:07:52 +00001247# This proc execs a seperate process that crashes midway through executing
1248# the SQL script $sql on database test.db.
1249#
1250# The crash occurs during a sync() of file $crashfile. When the crash
1251# occurs a random subset of all unsynced writes made by the process are
1252# written into the files on disk. Argument $crashdelay indicates the
1253# number of file syncs to wait before crashing.
1254#
1255# The return value is a list of two elements. The first element is a
1256# boolean, indicating whether or not the process actually crashed or
1257# reported some other error. The second element in the returned list is the
1258# error message. This is "child process exited abnormally" if the crash
mistachkin48864df2013-03-21 21:20:32 +00001259# occurred.
danielk1977aca790a2005-01-13 11:07:52 +00001260#
danielk1977f8940ae2007-08-23 11:07:10 +00001261# crashsql -delay CRASHDELAY -file CRASHFILE ?-blocksize BLOCKSIZE? $sql
danielk197759a33f92007-03-17 10:26:59 +00001262#
1263proc crashsql {args} {
danielk197759a33f92007-03-17 10:26:59 +00001264
1265 set blocksize ""
1266 set crashdelay 1
drhcb1f0f62008-01-08 15:18:52 +00001267 set prngseed 0
dan999cd082013-12-09 20:42:03 +00001268 set opendb { sqlite3 db test.db -vfs crash }
drhf8587402008-01-08 16:03:49 +00001269 set tclbody {}
danielk197759a33f92007-03-17 10:26:59 +00001270 set crashfile ""
danielk1977f8940ae2007-08-23 11:07:10 +00001271 set dc ""
danielk197759a33f92007-03-17 10:26:59 +00001272 set sql [lindex $args end]
mistachkin1d406e02013-08-29 01:09:14 +00001273
danielk197759a33f92007-03-17 10:26:59 +00001274 for {set ii 0} {$ii < [llength $args]-1} {incr ii 2} {
1275 set z [lindex $args $ii]
1276 set n [string length $z]
1277 set z2 [lindex $args [expr $ii+1]]
1278
1279 if {$n>1 && [string first $z -delay]==0} {set crashdelay $z2} \
dan999cd082013-12-09 20:42:03 +00001280 elseif {$n>1 && [string first $z -opendb]==0} {set opendb $z2} \
drhcb1f0f62008-01-08 15:18:52 +00001281 elseif {$n>1 && [string first $z -seed]==0} {set prngseed $z2} \
danielk197759a33f92007-03-17 10:26:59 +00001282 elseif {$n>1 && [string first $z -file]==0} {set crashfile $z2} \
drhf8587402008-01-08 16:03:49 +00001283 elseif {$n>1 && [string first $z -tclbody]==0} {set tclbody $z2} \
danielk1977967a4a12007-08-20 14:23:44 +00001284 elseif {$n>1 && [string first $z -blocksize]==0} {set blocksize "-s $z2" } \
danielk1977f8940ae2007-08-23 11:07:10 +00001285 elseif {$n>1 && [string first $z -characteristics]==0} {set dc "-c {$z2}" } \
danielk197759a33f92007-03-17 10:26:59 +00001286 else { error "Unrecognized option: $z" }
1287 }
1288
1289 if {$crashfile eq ""} {
1290 error "Compulsory option -file missing"
1291 }
1292
mistachkin1d406e02013-08-29 01:09:14 +00001293 # $crashfile gets compared to the native filename in
shanehf2c08822010-07-08 16:30:44 +00001294 # cfSync(), which can be different then what TCL uses by
1295 # default, so here we force it to the "nativename" format.
mistachkinf8a78462012-03-08 20:00:36 +00001296 set cfile [string map {\\ \\\\} [file nativename [file join [get_pwd] $crashfile]]]
danielk1977aca790a2005-01-13 11:07:52 +00001297
1298 set f [open crash.tcl w]
danielk1977ca0c8972007-09-01 09:02:53 +00001299 puts $f "sqlite3_crash_enable 1"
danielk1977f8940ae2007-08-23 11:07:10 +00001300 puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile"
drhc7a3bb92009-02-05 16:31:45 +00001301 puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte"
dan999cd082013-12-09 20:42:03 +00001302 puts $f $opendb
danielk1977933bbd62007-03-17 07:22:42 +00001303
1304 # This block sets the cache size of the main database to 10
1305 # pages. This is done in case the build is configured to omit
1306 # "PRAGMA cache_size".
1307 puts $f {db eval {SELECT * FROM sqlite_master;}}
1308 puts $f {set bt [btree_from_db db]}
1309 puts $f {btree_set_cache_size $bt 10}
dan999cd082013-12-09 20:42:03 +00001310
drhcb1f0f62008-01-08 15:18:52 +00001311 if {$prngseed} {
1312 set seed [expr {$prngseed%10007+1}]
1313 # puts seed=$seed
1314 puts $f "db eval {SELECT randomblob($seed)}"
1315 }
danielk1977933bbd62007-03-17 07:22:42 +00001316
drhf8587402008-01-08 16:03:49 +00001317 if {[string length $tclbody]>0} {
1318 puts $f $tclbody
1319 }
1320 if {[string length $sql]>0} {
1321 puts $f "db eval {"
1322 puts $f "$sql"
1323 puts $f "}"
1324 }
danielk1977aca790a2005-01-13 11:07:52 +00001325 close $f
danielk1977aca790a2005-01-13 11:07:52 +00001326 set r [catch {
drh9c06c952005-11-26 00:25:00 +00001327 exec [info nameofexec] crash.tcl >@stdout
danielk1977aca790a2005-01-13 11:07:52 +00001328 } msg]
mistachkin1d406e02013-08-29 01:09:14 +00001329
shanehf2c08822010-07-08 16:30:44 +00001330 # Windows/ActiveState TCL returns a slightly different
1331 # error message. We map that to the expected message
1332 # so that we don't have to change all of the test
1333 # cases.
1334 if {$::tcl_platform(platform)=="windows"} {
1335 if {$msg=="child killed: unknown signal"} {
1336 set msg "child process exited abnormally"
1337 }
1338 }
mistachkin1d406e02013-08-29 01:09:14 +00001339
danielk1977aca790a2005-01-13 11:07:52 +00001340 lappend r $msg
1341}
1342
danb88e24f2013-02-23 18:58:11 +00001343proc run_ioerr_prep {} {
1344 set ::sqlite_io_error_pending 0
1345 catch {db close}
1346 catch {db2 close}
1347 catch {forcedelete test.db}
1348 catch {forcedelete test.db-journal}
1349 catch {forcedelete test2.db}
1350 catch {forcedelete test2.db-journal}
1351 set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
1352 sqlite3_extended_result_codes $::DB $::ioerropts(-erc)
1353 if {[info exists ::ioerropts(-tclprep)]} {
1354 eval $::ioerropts(-tclprep)
1355 }
1356 if {[info exists ::ioerropts(-sqlprep)]} {
1357 execsql $::ioerropts(-sqlprep)
1358 }
1359 expr 0
1360}
1361
danielk197732554c12005-01-22 03:39:39 +00001362# Usage: do_ioerr_test <test number> <options...>
1363#
1364# This proc is used to implement test cases that check that IO errors
mistachkin1d406e02013-08-29 01:09:14 +00001365# are correctly handled. The first argument, <test number>, is an integer
danielk197732554c12005-01-22 03:39:39 +00001366# used to name the tests executed by this proc. Options are as follows:
1367#
1368# -tclprep TCL script to run to prepare test.
1369# -sqlprep SQL script to run to prepare test.
1370# -tclbody TCL script to run with IO error simulation.
1371# -sqlbody TCL script to run with IO error simulation.
1372# -exclude List of 'N' values not to test.
drh4ac285a2006-09-15 07:28:50 +00001373# -erc Use extended result codes
drhd5eb79e2007-03-15 12:17:42 +00001374# -persist Make simulated I/O errors persistent
danielk197732554c12005-01-22 03:39:39 +00001375# -start Value of 'N' to begin with (default 1)
1376#
1377# -cksum Boolean. If true, test that the database does
1378# not change during the execution of the test case.
1379#
1380proc do_ioerr_test {testname args} {
1381
danielk197732554c12005-01-22 03:39:39 +00001382 set ::ioerropts(-start) 1
1383 set ::ioerropts(-cksum) 0
drh4ac285a2006-09-15 07:28:50 +00001384 set ::ioerropts(-erc) 0
drhc2ee76c2007-01-04 14:58:14 +00001385 set ::ioerropts(-count) 100000000
drhd5eb79e2007-03-15 12:17:42 +00001386 set ::ioerropts(-persist) 1
danielk19774abd5442008-05-05 15:26:50 +00001387 set ::ioerropts(-ckrefcount) 0
danielk1977861f7452008-06-05 11:39:11 +00001388 set ::ioerropts(-restoreprng) 1
danielk197732554c12005-01-22 03:39:39 +00001389 array set ::ioerropts $args
1390
danielk197747cd39c2008-05-12 12:41:15 +00001391 # TEMPORARY: For 3.5.9, disable testing of extended result codes. There are
1392 # a couple of obscure IO errors that do not return them.
1393 set ::ioerropts(-erc) 0
mistachkin1d406e02013-08-29 01:09:14 +00001394
danb88e24f2013-02-23 18:58:11 +00001395 # Create a single TCL script from the TCL and SQL specified
1396 # as the body of the test.
1397 set ::ioerrorbody {}
1398 if {[info exists ::ioerropts(-tclbody)]} {
1399 append ::ioerrorbody "$::ioerropts(-tclbody)\n"
1400 }
1401 if {[info exists ::ioerropts(-sqlbody)]} {
1402 append ::ioerrorbody "db eval {$::ioerropts(-sqlbody)}"
1403 }
1404
1405 save_prng_state
1406 if {$::ioerropts(-cksum)} {
1407 run_ioerr_prep
1408 eval $::ioerrorbody
1409 set ::goodcksum [cksum]
1410 }
danielk197747cd39c2008-05-12 12:41:15 +00001411
danielk197732554c12005-01-22 03:39:39 +00001412 set ::go 1
drh93aed5a2008-01-16 17:46:38 +00001413 #reset_prng_state
danielk1977ef165ce2009-04-06 17:50:03 +00001414 for {set n $::ioerropts(-start)} {$::go} {incr n} {
danielk197792d4d7a2007-05-04 12:05:56 +00001415 set ::TN $n
drhc2ee76c2007-01-04 14:58:14 +00001416 incr ::ioerropts(-count) -1
1417 if {$::ioerropts(-count)<0} break
mistachkin1d406e02013-08-29 01:09:14 +00001418
danielk197732554c12005-01-22 03:39:39 +00001419 # Skip this IO error if it was specified with the "-exclude" option.
1420 if {[info exists ::ioerropts(-exclude)]} {
1421 if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue
1422 }
danielk1977861f7452008-06-05 11:39:11 +00001423 if {$::ioerropts(-restoreprng)} {
1424 restore_prng_state
1425 }
danielk197732554c12005-01-22 03:39:39 +00001426
mistachkin1d406e02013-08-29 01:09:14 +00001427 # Delete the files test.db and test2.db, then execute the TCL and
danielk197732554c12005-01-22 03:39:39 +00001428 # SQL (in that order) to prepare for the test case.
1429 do_test $testname.$n.1 {
danb88e24f2013-02-23 18:58:11 +00001430 run_ioerr_prep
danielk197732554c12005-01-22 03:39:39 +00001431 } {0}
1432
1433 # Read the 'checksum' of the database.
1434 if {$::ioerropts(-cksum)} {
danb88e24f2013-02-23 18:58:11 +00001435 set ::checksum [cksum]
danielk197732554c12005-01-22 03:39:39 +00001436 }
drh93aed5a2008-01-16 17:46:38 +00001437
danielk197732554c12005-01-22 03:39:39 +00001438 # Set the Nth IO error to fail.
1439 do_test $testname.$n.2 [subst {
drhd5eb79e2007-03-15 12:17:42 +00001440 set ::sqlite_io_error_persist $::ioerropts(-persist)
danielk197732554c12005-01-22 03:39:39 +00001441 set ::sqlite_io_error_pending $n
1442 }] $n
danielk197732554c12005-01-22 03:39:39 +00001443
danb88e24f2013-02-23 18:58:11 +00001444 # Execute the TCL script created for the body of this test. If
mistachkin1d406e02013-08-29 01:09:14 +00001445 # at least N IO operations performed by SQLite as a result of
danb88e24f2013-02-23 18:58:11 +00001446 # the script, the Nth will fail.
danielk197732554c12005-01-22 03:39:39 +00001447 do_test $testname.$n.3 {
drh1aa5af12008-03-07 19:51:14 +00001448 set ::sqlite_io_error_hit 0
1449 set ::sqlite_io_error_hardhit 0
danielk197732554c12005-01-22 03:39:39 +00001450 set r [catch $::ioerrorbody msg]
drh1aa5af12008-03-07 19:51:14 +00001451 set ::errseen $r
drhe49f9822006-09-15 12:29:16 +00001452 set rc [sqlite3_errcode $::DB]
1453 if {$::ioerropts(-erc)} {
drh5f7b5bf2007-04-19 12:30:54 +00001454 # If we are in extended result code mode, make sure all of the
1455 # IOERRs we get back really do have their extended code values.
1456 # If an extended result code is returned, the sqlite3_errcode
1457 # TCLcommand will return a string of the form: SQLITE_IOERR+nnnn
1458 # where nnnn is a number
drhe49f9822006-09-15 12:29:16 +00001459 if {[regexp {^SQLITE_IOERR} $rc] && ![regexp {IOERR\+\d} $rc]} {
1460 return $rc
1461 }
1462 } else {
drh5f7b5bf2007-04-19 12:30:54 +00001463 # If we are not in extended result code mode, make sure no
1464 # extended error codes are returned.
drhe49f9822006-09-15 12:29:16 +00001465 if {[regexp {\+\d} $rc]} {
1466 return $rc
1467 }
1468 }
drh93aed5a2008-01-16 17:46:38 +00001469 # The test repeats as long as $::go is non-zero. $::go starts out
1470 # as 1. When a test runs to completion without hitting an I/O
1471 # error, that means there is no point in continuing with this test
1472 # case so set $::go to zero.
1473 #
1474 if {$::sqlite_io_error_pending>0} {
1475 set ::go 0
1476 set q 0
1477 set ::sqlite_io_error_pending 0
1478 } else {
1479 set q 1
1480 }
1481
drhc9ac5ca2005-11-04 22:03:30 +00001482 set s [expr $::sqlite_io_error_hit==0]
drh1aa5af12008-03-07 19:51:14 +00001483 if {$::sqlite_io_error_hit>$::sqlite_io_error_hardhit && $r==0} {
1484 set r 1
1485 }
danielk1977f2fa8312006-01-24 13:09:33 +00001486 set ::sqlite_io_error_hit 0
drh5f7b5bf2007-04-19 12:30:54 +00001487
1488 # One of two things must have happened. either
1489 # 1. We never hit the IO error and the SQL returned OK
1490 # 2. An IO error was hit and the SQL failed
1491 #
dand41a29a2010-05-06 15:56:28 +00001492 #puts "s=$s r=$r q=$q"
drh93aed5a2008-01-16 17:46:38 +00001493 expr { ($s && !$r && !$q) || (!$s && $r && $q) }
danielk197732554c12005-01-22 03:39:39 +00001494 } {1}
1495
danielk197780daec62008-05-12 10:57:02 +00001496 set ::sqlite_io_error_hit 0
1497 set ::sqlite_io_error_pending 0
1498
mistachkin1d406e02013-08-29 01:09:14 +00001499 # Check that no page references were leaked. There should be
1500 # a single reference if there is still an active transaction,
danielk197752b472a2008-05-05 16:23:55 +00001501 # or zero otherwise.
1502 #
danielk197781620542008-06-07 05:19:37 +00001503 # UPDATE: If the IO error occurs after a 'BEGIN' but before any
mistachkin1d406e02013-08-29 01:09:14 +00001504 # locks are established on database files (i.e. if the error
danielk197781620542008-06-07 05:19:37 +00001505 # occurs while attempting to detect a hot-journal file), then
1506 # there may 0 page references and an active transaction according
1507 # to [sqlite3_get_autocommit].
1508 #
danielk19774abd5442008-05-05 15:26:50 +00001509 if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-ckrefcount)} {
danielk19774abd5442008-05-05 15:26:50 +00001510 do_test $testname.$n.4 {
1511 set bt [btree_from_db db]
1512 db_enter db
1513 array set stats [btree_pager_stats $bt]
1514 db_leave db
danielk197781620542008-06-07 05:19:37 +00001515 set nRef $stats(ref)
1516 expr {$nRef == 0 || ([sqlite3_get_autocommit db]==0 && $nRef == 1)}
1517 } {1}
danielk19774abd5442008-05-05 15:26:50 +00001518 }
1519
mistachkin1d406e02013-08-29 01:09:14 +00001520 # If there is an open database handle and no open transaction,
danielk197752b472a2008-05-05 16:23:55 +00001521 # and the pager is not running in exclusive-locking mode,
1522 # check that the pager is in "unlocked" state. Theoretically,
1523 # if a call to xUnlock() failed due to an IO error the underlying
1524 # file may still be locked.
1525 #
1526 ifcapable pragma {
1527 if { [info commands db] ne ""
danielk19770259fbe2008-05-05 17:14:53 +00001528 && $::ioerropts(-ckrefcount)
danielk197752b472a2008-05-05 16:23:55 +00001529 && [db one {pragma locking_mode}] eq "normal"
1530 && [sqlite3_get_autocommit db]
1531 } {
1532 do_test $testname.$n.5 {
1533 set bt [btree_from_db db]
1534 db_enter db
1535 array set stats [btree_pager_stats $bt]
1536 db_leave db
1537 set stats(state)
1538 } 0
1539 }
1540 }
1541
mistachkin48864df2013-03-21 21:20:32 +00001542 # If an IO error occurred, then the checksum of the database should
danielk197732554c12005-01-22 03:39:39 +00001543 # be the same as before the script that caused the IO error was run.
danielk197752b472a2008-05-05 16:23:55 +00001544 #
drh1aa5af12008-03-07 19:51:14 +00001545 if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-cksum)} {
danielk19770259fbe2008-05-05 17:14:53 +00001546 do_test $testname.$n.6 {
danielk197732554c12005-01-22 03:39:39 +00001547 catch {db close}
danielk1977a9613392008-07-08 12:07:32 +00001548 catch {db2 close}
drha34c62d2006-01-06 22:11:20 +00001549 set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
danb88e24f2013-02-23 18:58:11 +00001550 set nowcksum [cksum]
1551 set res [expr {$nowcksum==$::checksum || $nowcksum==$::goodcksum}]
1552 if {$res==0} {
1553 puts "now=$nowcksum"
1554 puts "the=$::checksum"
1555 puts "fwd=$::goodcksum"
1556 }
1557 set res
1558 } 1
danielk197732554c12005-01-22 03:39:39 +00001559 }
1560
drh1aa5af12008-03-07 19:51:14 +00001561 set ::sqlite_io_error_hardhit 0
danielk1977c4da5b92006-01-21 12:08:54 +00001562 set ::sqlite_io_error_pending 0
danielk1977105afed2005-05-26 15:20:53 +00001563 if {[info exists ::ioerropts(-cleanup)]} {
1564 catch $::ioerropts(-cleanup)
1565 }
danielk197732554c12005-01-22 03:39:39 +00001566 }
1567 set ::sqlite_io_error_pending 0
drh6d54da02007-03-25 19:08:46 +00001568 set ::sqlite_io_error_persist 0
danielk197732554c12005-01-22 03:39:39 +00001569 unset ::ioerropts
1570}
1571
drh93aed5a2008-01-16 17:46:38 +00001572# Return a checksum based on the contents of the main database associated
1573# with connection $db
danielk197732554c12005-01-22 03:39:39 +00001574#
1575proc cksum {{db db}} {
1576 set txt [$db eval {
1577 SELECT name, type, sql FROM sqlite_master order by name
1578 }]\n
1579 foreach tbl [$db eval {
1580 SELECT name FROM sqlite_master WHERE type='table' order by name
1581 }] {
1582 append txt [$db eval "SELECT * FROM $tbl"]\n
1583 }
1584 foreach prag {default_synchronous default_cache_size} {
1585 append txt $prag-[$db eval "PRAGMA $prag"]\n
1586 }
1587 set cksum [string length $txt]-[md5 $txt]
1588 # puts $cksum-[file size test.db]
1589 return $cksum
1590}
1591
drh93aed5a2008-01-16 17:46:38 +00001592# Generate a checksum based on the contents of the main and temp tables
1593# database $db. If the checksum of two databases is the same, and the
1594# integrity-check passes for both, the two databases are identical.
1595#
drh1db639c2008-01-17 02:36:28 +00001596proc allcksum {{db db}} {
drh93aed5a2008-01-16 17:46:38 +00001597 set ret [list]
1598 ifcapable tempdb {
1599 set sql {
1600 SELECT name FROM sqlite_master WHERE type = 'table' UNION
1601 SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION
1602 SELECT 'sqlite_master' UNION
1603 SELECT 'sqlite_temp_master' ORDER BY 1
1604 }
1605 } else {
1606 set sql {
1607 SELECT name FROM sqlite_master WHERE type = 'table' UNION
1608 SELECT 'sqlite_master' ORDER BY 1
1609 }
1610 }
1611 set tbllist [$db eval $sql]
1612 set txt {}
1613 foreach tbl $tbllist {
1614 append txt [$db eval "SELECT * FROM $tbl"]
1615 }
1616 foreach prag {default_cache_size} {
1617 append txt $prag-[$db eval "PRAGMA $prag"]\n
1618 }
1619 # puts txt=$txt
1620 return [md5 $txt]
1621}
1622
drhdc2c4912009-02-04 22:46:47 +00001623# Generate a checksum based on the contents of a single database with
mistachkin1d406e02013-08-29 01:09:14 +00001624# a database connection. The name of the database is $dbname.
drhdc2c4912009-02-04 22:46:47 +00001625# Examples of $dbname are "temp" or "main".
1626#
1627proc dbcksum {db dbname} {
1628 if {$dbname=="temp"} {
1629 set master sqlite_temp_master
1630 } else {
1631 set master $dbname.sqlite_master
1632 }
1633 set alltab [$db eval "SELECT name FROM $master WHERE type='table'"]
1634 set txt [$db eval "SELECT * FROM $master"]\n
1635 foreach tab $alltab {
1636 append txt [$db eval "SELECT * FROM $dbname.$tab"]\n
1637 }
1638 return [md5 $txt]
1639}
1640
danielk197735754ac2008-03-21 17:29:37 +00001641proc memdebug_log_sql {{filename mallocs.sql}} {
1642
danielk19776f332c12008-03-21 14:22:44 +00001643 set data [sqlite3_memdebug_log dump]
1644 set nFrame [expr [llength [lindex $data 0]]-2]
danielk19776f332c12008-03-21 14:22:44 +00001645 if {$nFrame < 0} { return "" }
1646
danielk197735754ac2008-03-21 17:29:37 +00001647 set database temp
1648
danielk19776ab3a2e2009-02-19 14:39:25 +00001649 set tbl "CREATE TABLE ${database}.malloc(zTest, nCall, nByte, lStack);"
danielk19776f332c12008-03-21 14:22:44 +00001650
1651 set sql ""
1652 foreach e $data {
danielk19776ab3a2e2009-02-19 14:39:25 +00001653 set nCall [lindex $e 0]
1654 set nByte [lindex $e 1]
1655 set lStack [lrange $e 2 end]
1656 append sql "INSERT INTO ${database}.malloc VALUES"
1657 append sql "('test', $nCall, $nByte, '$lStack');\n"
1658 foreach f $lStack {
danielk19776f332c12008-03-21 14:22:44 +00001659 set frames($f) 1
1660 }
1661 }
1662
1663 set tbl2 "CREATE TABLE ${database}.frame(frame INTEGER PRIMARY KEY, line);\n"
danielk197735754ac2008-03-21 17:29:37 +00001664 set tbl3 "CREATE TABLE ${database}.file(name PRIMARY KEY, content);\n"
danielk19776f332c12008-03-21 14:22:44 +00001665
1666 foreach f [array names frames] {
1667 set addr [format %x $f]
1668 set cmd "addr2line -e [info nameofexec] $addr"
1669 set line [eval exec $cmd]
1670 append sql "INSERT INTO ${database}.frame VALUES($f, '$line');\n"
danielk197735754ac2008-03-21 17:29:37 +00001671
1672 set file [lindex [split $line :] 0]
1673 set files($file) 1
danielk19776f332c12008-03-21 14:22:44 +00001674 }
1675
danielk197735754ac2008-03-21 17:29:37 +00001676 foreach f [array names files] {
1677 set contents ""
1678 catch {
1679 set fd [open $f]
1680 set contents [read $fd]
1681 close $fd
danielk19776f332c12008-03-21 14:22:44 +00001682 }
danielk197735754ac2008-03-21 17:29:37 +00001683 set contents [string map {' ''} $contents]
1684 append sql "INSERT INTO ${database}.file VALUES('$f', '$contents');\n"
danielk19776f332c12008-03-21 14:22:44 +00001685 }
danielk19776f332c12008-03-21 14:22:44 +00001686
danielk197735754ac2008-03-21 17:29:37 +00001687 set fd [open $filename w]
1688 puts $fd "BEGIN; ${tbl}${tbl2}${tbl3}${sql} ; COMMIT;"
1689 close $fd
danielk19776f332c12008-03-21 14:22:44 +00001690}
drh93aed5a2008-01-16 17:46:38 +00001691
danf5894502009-10-07 18:41:19 +00001692# Drop all tables in database [db]
1693proc drop_all_tables {{db db}} {
shaneh4e7b32f2009-12-17 22:12:51 +00001694 ifcapable trigger&&foreignkey {
1695 set pk [$db one "PRAGMA foreign_keys"]
1696 $db eval "PRAGMA foreign_keys = OFF"
1697 }
drh9a6ffc82010-02-15 18:03:20 +00001698 foreach {idx name file} [db eval {PRAGMA database_list}] {
1699 if {$idx==1} {
1700 set master sqlite_temp_master
1701 } else {
1702 set master $name.sqlite_master
1703 }
1704 foreach {t type} [$db eval "
1705 SELECT name, type FROM $master
dana16d1062010-09-28 17:37:28 +00001706 WHERE type IN('table', 'view') AND name NOT LIKE 'sqliteX_%' ESCAPE 'X'
drh9a6ffc82010-02-15 18:03:20 +00001707 "] {
dana16d1062010-09-28 17:37:28 +00001708 $db eval "DROP $type \"$t\""
drh9a6ffc82010-02-15 18:03:20 +00001709 }
danf5894502009-10-07 18:41:19 +00001710 }
shaneh4e7b32f2009-12-17 22:12:51 +00001711 ifcapable trigger&&foreignkey {
1712 $db eval "PRAGMA foreign_keys = $pk"
1713 }
danf5894502009-10-07 18:41:19 +00001714}
1715
dan71cb5182010-04-26 12:39:03 +00001716#-------------------------------------------------------------------------
dan430e74c2010-06-07 17:47:26 +00001717# If a test script is executed with global variable $::G(perm:name) set to
mistachkin1d406e02013-08-29 01:09:14 +00001718# "wal", then the tests are run in WAL mode. Otherwise, they should be run
1719# in rollback mode. The following Tcl procs are used to make this less
dan430e74c2010-06-07 17:47:26 +00001720# intrusive:
dan71cb5182010-04-26 12:39:03 +00001721#
1722# wal_set_journal_mode ?DB?
1723#
1724# If running a WAL test, execute "PRAGMA journal_mode = wal" using
1725# connection handle DB. Otherwise, this command is a no-op.
1726#
1727# wal_check_journal_mode TESTNAME ?DB?
1728#
1729# If running a WAL test, execute a tests case that fails if the main
1730# database for connection handle DB is not currently a WAL database.
1731# Otherwise (if not running a WAL permutation) this is a no-op.
1732#
1733# wal_is_wal_mode
mistachkin1d406e02013-08-29 01:09:14 +00001734#
dan71cb5182010-04-26 12:39:03 +00001735# Returns true if this test should be run in WAL mode. False otherwise.
mistachkin1d406e02013-08-29 01:09:14 +00001736#
dan71cb5182010-04-26 12:39:03 +00001737proc wal_is_wal_mode {} {
dan430e74c2010-06-07 17:47:26 +00001738 expr {[permutation] eq "wal"}
dan71cb5182010-04-26 12:39:03 +00001739}
1740proc wal_set_journal_mode {{db db}} {
1741 if { [wal_is_wal_mode] } {
1742 $db eval "PRAGMA journal_mode = WAL"
1743 }
1744}
1745proc wal_check_journal_mode {testname {db db}} {
1746 if { [wal_is_wal_mode] } {
1747 $db eval { SELECT * FROM sqlite_master }
1748 do_test $testname [list $db eval "PRAGMA main.journal_mode"] {wal}
1749 }
1750}
1751
dan430e74c2010-06-07 17:47:26 +00001752proc permutation {} {
1753 set perm ""
1754 catch {set perm $::G(perm:name)}
1755 set perm
1756}
dancb79e512010-08-06 13:50:07 +00001757proc presql {} {
1758 set presql ""
1759 catch {set presql $::G(perm:presql)}
1760 set presql
1761}
dan430e74c2010-06-07 17:47:26 +00001762
danc1a60c52010-06-07 14:28:16 +00001763#-------------------------------------------------------------------------
1764#
1765proc slave_test_script {script} {
1766
1767 # Create the interpreter used to run the test script.
1768 interp create tinterp
1769
1770 # Populate some global variables that tester.tcl expects to see.
1771 foreach {var value} [list \
1772 ::argv0 $::argv0 \
1773 ::argv {} \
1774 ::SLAVE 1 \
1775 ] {
1776 interp eval tinterp [list set $var $value]
1777 }
1778
1779 # The alias used to access the global test counters.
1780 tinterp alias set_test_counter set_test_counter
1781
1782 # Set up the ::cmdlinearg array in the slave.
1783 interp eval tinterp [list array set ::cmdlinearg [array get ::cmdlinearg]]
1784
dan430e74c2010-06-07 17:47:26 +00001785 # Set up the ::G array in the slave.
1786 interp eval tinterp [list array set ::G [array get ::G]]
1787
danc1a60c52010-06-07 14:28:16 +00001788 # Load the various test interfaces implemented in C.
1789 load_testfixture_extensions tinterp
1790
1791 # Run the test script.
1792 interp eval tinterp $script
1793
danea5542d2010-07-06 11:26:15 +00001794 # Check if the interpreter call [run_thread_tests]
1795 if { [interp eval tinterp {info exists ::run_thread_tests_called}] } {
1796 set ::run_thread_tests_called 1
1797 }
1798
danc1a60c52010-06-07 14:28:16 +00001799 # Delete the interpreter used to run the test script.
1800 interp delete tinterp
1801}
1802
dan430e74c2010-06-07 17:47:26 +00001803proc slave_test_file {zFile} {
dan0626dfc2010-06-15 06:56:37 +00001804 set tail [file tail $zFile]
dan430e74c2010-06-07 17:47:26 +00001805
dan6a64d672011-04-04 15:38:16 +00001806 if {[info exists ::G(start:permutation)]} {
1807 if {[permutation] != $::G(start:permutation)} return
1808 unset ::G(start:permutation)
1809 }
1810 if {[info exists ::G(start:file)]} {
1811 if {$tail != $::G(start:file) && $tail!="$::G(start:file).test"} return
1812 unset ::G(start:file)
1813 }
1814
dan92d516a2010-07-05 14:54:48 +00001815 # Remember the value of the shared-cache setting. So that it is possible
1816 # to check afterwards that it was not modified by the test script.
1817 #
1818 ifcapable shared_cache { set scs [sqlite3_enable_shared_cache] }
dan0626dfc2010-06-15 06:56:37 +00001819
dan92d516a2010-07-05 14:54:48 +00001820 # Run the test script in a slave interpreter.
1821 #
danea5542d2010-07-06 11:26:15 +00001822 unset -nocomplain ::run_thread_tests_called
dan0626dfc2010-06-15 06:56:37 +00001823 reset_prng_state
1824 set ::sqlite_open_file_count 0
1825 set time [time { slave_test_script [list source $zFile] }]
1826 set ms [expr [lindex $time 0] / 1000]
1827
dan92d516a2010-07-05 14:54:48 +00001828 # Test that all files opened by the test script were closed. Omit this
1829 # if the test script has "thread" in its name. The open file counter
1830 # is not thread-safe.
dan0626dfc2010-06-15 06:56:37 +00001831 #
danea5542d2010-07-06 11:26:15 +00001832 if {[info exists ::run_thread_tests_called]==0} {
dan92d516a2010-07-05 14:54:48 +00001833 do_test ${tail}-closeallfiles { expr {$::sqlite_open_file_count>0} } {0}
1834 }
dan430e74c2010-06-07 17:47:26 +00001835 set ::sqlite_open_file_count 0
1836
mistachkin1d406e02013-08-29 01:09:14 +00001837 # Test that the global "shared-cache" setting was not altered by
dan0626dfc2010-06-15 06:56:37 +00001838 # the test script.
1839 #
mistachkin1d406e02013-08-29 01:09:14 +00001840 ifcapable shared_cache {
dan0626dfc2010-06-15 06:56:37 +00001841 set res [expr {[sqlite3_enable_shared_cache] == $scs}]
1842 do_test ${tail}-sharedcachesetting [list set {} $res] 1
1843 }
dan430e74c2010-06-07 17:47:26 +00001844
dan92d516a2010-07-05 14:54:48 +00001845 # Add some info to the output.
1846 #
dan0626dfc2010-06-15 06:56:37 +00001847 puts "Time: $tail $ms ms"
dan430e74c2010-06-07 17:47:26 +00001848 show_memstats
danc1a60c52010-06-07 14:28:16 +00001849}
1850
dan59257dc2010-08-04 11:34:31 +00001851# Open a new connection on database test.db and execute the SQL script
1852# supplied as an argument. Before returning, close the new conection and
1853# restore the 4 byte fields starting at header offsets 28, 92 and 96
1854# to the values they held before the SQL was executed. This simulates
1855# a write by a pre-3.7.0 client.
1856#
1857proc sql36231 {sql} {
1858 set B [hexio_read test.db 92 8]
1859 set A [hexio_read test.db 28 4]
1860 sqlite3 db36231 test.db
1861 catch { db36231 func a_string a_string }
1862 execsql $sql db36231
1863 db36231 close
1864 hexio_write test.db 28 $A
1865 hexio_write test.db 92 $B
1866 return ""
1867}
danf5894502009-10-07 18:41:19 +00001868
danccc7ff42010-11-29 12:06:45 +00001869proc db_save {} {
1870 foreach f [glob -nocomplain sv_test.db*] { forcedelete $f }
1871 foreach f [glob -nocomplain test.db*] {
1872 set f2 "sv_$f"
mistachkinfda06be2011-08-02 00:57:34 +00001873 forcecopy $f $f2
danccc7ff42010-11-29 12:06:45 +00001874 }
1875}
1876proc db_save_and_close {} {
1877 db_save
1878 catch { db close }
1879 return ""
1880}
1881proc db_restore {} {
1882 foreach f [glob -nocomplain test.db*] { forcedelete $f }
1883 foreach f2 [glob -nocomplain sv_test.db*] {
1884 set f [string range $f2 3 end]
mistachkinfda06be2011-08-02 00:57:34 +00001885 forcecopy $f2 $f
danccc7ff42010-11-29 12:06:45 +00001886 }
1887}
1888proc db_restore_and_reopen {{dbfile test.db}} {
1889 catch { db close }
1890 db_restore
1891 sqlite3 db $dbfile
1892}
1893proc db_delete_and_reopen {{file test.db}} {
1894 catch { db close }
mistachkinfda06be2011-08-02 00:57:34 +00001895 foreach f [glob -nocomplain test.db*] { forcedelete $f }
danccc7ff42010-11-29 12:06:45 +00001896 sqlite3 db $file
1897}
1898
danielk197745901d62004-11-10 15:27:38 +00001899# If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set
1900# to non-zero, then set the global variable $AUTOVACUUM to 1.
1901set AUTOVACUUM $sqlite_options(default_autovacuum)
danielk1977ee8b7992009-03-26 17:13:06 +00001902
dan64b95bb2012-05-12 05:30:29 +00001903# Make sure the FTS enhanced query syntax is disabled.
1904set sqlite_fts3_enable_parentheses 0
1905
drh09fe6142013-11-29 15:06:27 +00001906# During testing, assume that all database files are well-formed. The
1907# few test cases that deliberately corrupt database files should rescind
1908# this setting by invoking "database_can_be_corrupt"
1909#
1910database_never_corrupt
1911
danielk1977ee8b7992009-03-26 17:13:06 +00001912source $testdir/thread_common.tcl
danddf80eb2010-10-25 12:47:43 +00001913source $testdir/malloc_common.tcl