drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 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. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements some common TCL routines used for regression |
| 12 | # testing the SQLite library |
| 13 | # |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 14 | # $Id: tester.tcl,v 1.109 2008/03/21 17:29:38 danielk1977 Exp $ |
drh | fbc3eab | 2001-04-06 16:13:42 +0000 | [diff] [blame] | 15 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 16 | |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 17 | set tcl_precision 15 |
drh | 4928570 | 2005-09-17 15:20:26 +0000 | [diff] [blame] | 18 | set sqlite_pending_byte 0x0010000 |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 19 | |
drh | 3a7fb7c | 2007-08-10 16:41:08 +0000 | [diff] [blame] | 20 | # |
| 21 | # Check the command-line arguments for a default soft-heap-limit. |
| 22 | # Store this default value in the global variable ::soft_limit and |
| 23 | # update the soft-heap-limit each time this script is run. In that |
| 24 | # way if an individual test file changes the soft-heap-limit, it |
| 25 | # will be reset at the start of the next test file. |
| 26 | # |
| 27 | if {![info exists soft_limit]} { |
| 28 | set soft_limit 0 |
| 29 | for {set i 0} {$i<[llength $argv]} {incr i} { |
| 30 | if {[regexp {^--soft-heap-limit=(.+)$} [lindex $argv $i] all value]} { |
| 31 | if {$value!="off"} { |
| 32 | set soft_limit $value |
| 33 | } |
| 34 | set argv [lreplace $argv $i $i] |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | sqlite3_soft_heap_limit $soft_limit |
| 39 | |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 40 | # |
| 41 | # Check the command-line arguments to set the memory debugger |
| 42 | # backtrace depth. |
| 43 | # |
| 44 | # See the sqlite3_memdebug_backtrace() function in mem2.c or |
| 45 | # test_malloc.c for additional information. |
| 46 | # |
| 47 | for {set i 0} {$i<[llength $argv]} {incr i} { |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 48 | if {[lindex $argv $i] eq "--malloctrace"} { |
| 49 | set argv [lreplace $argv $i $i] |
| 50 | sqlite3_memdebug_backtrace 5 |
| 51 | sqlite3_memdebug_log start |
| 52 | set argv [lreplace $argv $i $i] |
| 53 | set tester_do_malloctrace 1 |
| 54 | } |
| 55 | } |
| 56 | for {set i 0} {$i<[llength $argv]} {incr i} { |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 57 | if {[regexp {^--backtrace=(\d+)$} [lindex $argv $i] all value]} { |
| 58 | sqlite3_memdebug_backtrace $value |
| 59 | set argv [lreplace $argv $i $i] |
| 60 | } |
| 61 | } |
| 62 | |
drh | 6a288a3 | 2008-01-07 19:20:24 +0000 | [diff] [blame] | 63 | # |
| 64 | # Check the command-line arguments to set the maximum number of |
| 65 | # errors tolerated before halting. |
| 66 | # |
| 67 | if {![info exists maxErr]} { |
| 68 | set maxErr 1000 |
| 69 | } |
| 70 | for {set i 0} {$i<[llength $argv]} {incr i} { |
| 71 | if {[regexp {^--maxerror=(\d+)$} [lindex $argv $i] all maxErr]} { |
| 72 | set argv [lreplace $argv $i $i] |
| 73 | } |
| 74 | } |
| 75 | #puts "Max error = $maxErr" |
| 76 | |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 77 | |
drh | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame] | 78 | # Use the pager codec if it is available |
| 79 | # |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 80 | if {[sqlite3 -has-codec] && [info command sqlite_orig]==""} { |
| 81 | rename sqlite3 sqlite_orig |
| 82 | proc sqlite3 {args} { |
drh | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame] | 83 | if {[llength $args]==2 && [string index [lindex $args 0] 0]!="-"} { |
| 84 | lappend args -key {xyzzy} |
| 85 | } |
| 86 | uplevel 1 sqlite_orig $args |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame] | 91 | # Create a test database |
| 92 | # |
drh | 254cba2 | 2001-09-20 01:44:42 +0000 | [diff] [blame] | 93 | catch {db close} |
| 94 | file delete -force test.db |
| 95 | file delete -force test.db-journal |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 96 | sqlite3 db ./test.db |
| 97 | set ::DB [sqlite3_connection_pointer db] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 98 | if {[info exists ::SETUP_SQL]} { |
| 99 | db eval $::SETUP_SQL |
| 100 | } |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame] | 101 | |
| 102 | # Abort early if this script has been run before. |
| 103 | # |
| 104 | if {[info exists nTest]} return |
| 105 | |
| 106 | # Set the test counters to zero |
| 107 | # |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 108 | set nErr 0 |
| 109 | set nTest 0 |
drh | 767c200 | 2000-10-19 14:10:08 +0000 | [diff] [blame] | 110 | set skip_test 0 |
drh | a1b351a | 2001-09-14 16:42:12 +0000 | [diff] [blame] | 111 | set failList {} |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 112 | if {![info exists speedTest]} { |
| 113 | set speedTest 0 |
| 114 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 115 | |
| 116 | # Invoke the do_test procedure to run a single test |
| 117 | # |
| 118 | proc do_test {name cmd expected} { |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 119 | global argv nErr nTest skip_test maxErr |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 120 | sqlite3_memdebug_settitle $name |
drh | 767c200 | 2000-10-19 14:10:08 +0000 | [diff] [blame] | 121 | if {$skip_test} { |
| 122 | set skip_test 0 |
| 123 | return |
| 124 | } |
| 125 | if {[llength $argv]==0} { |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 126 | set go 1 |
| 127 | } else { |
| 128 | set go 0 |
| 129 | foreach pattern $argv { |
| 130 | if {[string match $pattern $name]} { |
| 131 | set go 1 |
| 132 | break |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | if {!$go} return |
| 137 | incr nTest |
drh | 5edc312 | 2001-09-13 21:53:09 +0000 | [diff] [blame] | 138 | puts -nonewline $name... |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 139 | flush stdout |
| 140 | if {[catch {uplevel #0 "$cmd;\n"} result]} { |
| 141 | puts "\nError: $result" |
| 142 | incr nErr |
drh | a1b351a | 2001-09-14 16:42:12 +0000 | [diff] [blame] | 143 | lappend ::failList $name |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 144 | if {$nErr>$maxErr} {puts "*** Giving up..."; finalize_testing} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 145 | } elseif {[string compare $result $expected]} { |
| 146 | puts "\nExpected: \[$expected\]\n Got: \[$result\]" |
| 147 | incr nErr |
drh | a1b351a | 2001-09-14 16:42:12 +0000 | [diff] [blame] | 148 | lappend ::failList $name |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 149 | if {$nErr>=$maxErr} {puts "*** Giving up..."; finalize_testing} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 150 | } else { |
| 151 | puts " Ok" |
| 152 | } |
drh | 6558db8 | 2007-04-13 03:23:21 +0000 | [diff] [blame] | 153 | flush stdout |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 154 | } |
| 155 | |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 156 | # Run an SQL script. |
| 157 | # Return the number of microseconds per statement. |
| 158 | # |
drh | 3590f15 | 2006-11-23 21:09:10 +0000 | [diff] [blame] | 159 | proc speed_trial {name numstmt units sql} { |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 160 | puts -nonewline [format {%-21.21s } $name...] |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 161 | flush stdout |
| 162 | set speed [time {sqlite3_exec_nr db $sql}] |
| 163 | set tm [lindex $speed 0] |
danielk1977 | 0ee26d9 | 2008-02-08 18:25:29 +0000 | [diff] [blame] | 164 | if {$tm == 0} { |
| 165 | set rate [format %20s "many"] |
| 166 | } else { |
| 167 | set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]] |
| 168 | } |
drh | 3590f15 | 2006-11-23 21:09:10 +0000 | [diff] [blame] | 169 | set u2 $units/s |
danielk1977 | 0ee26d9 | 2008-02-08 18:25:29 +0000 | [diff] [blame] | 170 | puts [format {%12d uS %s %s} $tm $rate $u2] |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 171 | global total_time |
| 172 | set total_time [expr {$total_time+$tm}] |
| 173 | } |
| 174 | proc speed_trial_init {name} { |
| 175 | global total_time |
| 176 | set total_time 0 |
| 177 | } |
| 178 | proc speed_trial_summary {name} { |
| 179 | global total_time |
| 180 | puts [format {%-21.21s %12d uS TOTAL} $name $total_time] |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 181 | } |
| 182 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 183 | # Run this routine last |
| 184 | # |
| 185 | proc finish_test {} { |
drh | a1b351a | 2001-09-14 16:42:12 +0000 | [diff] [blame] | 186 | finalize_testing |
| 187 | } |
| 188 | proc finalize_testing {} { |
drh | 80788d8 | 2006-09-02 14:50:23 +0000 | [diff] [blame] | 189 | global nTest nErr sqlite_open_file_count |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 190 | |
drh | 6e142f5 | 2000-06-08 13:36:40 +0000 | [diff] [blame] | 191 | catch {db close} |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 192 | catch {db2 close} |
| 193 | catch {db3 close} |
| 194 | |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 195 | vfs_unlink_test |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 196 | sqlite3 db {} |
danielk1977 | cbb8496 | 2006-01-17 16:10:13 +0000 | [diff] [blame] | 197 | # sqlite3_clear_tsd_memdebug |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 198 | db close |
drh | 984bfaa | 2008-03-19 16:08:53 +0000 | [diff] [blame] | 199 | sqlite3_reset_auto_extension |
drh | 3a7fb7c | 2007-08-10 16:41:08 +0000 | [diff] [blame] | 200 | set heaplimit [sqlite3_soft_heap_limit] |
| 201 | if {$heaplimit!=$::soft_limit} { |
| 202 | puts "soft-heap-limit changed by this script\ |
| 203 | from $::soft_limit to $heaplimit" |
| 204 | } elseif {$heaplimit!="" && $heaplimit>0} { |
| 205 | puts "soft-heap-limit set to $heaplimit" |
| 206 | } |
| 207 | sqlite3_soft_heap_limit 0 |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 208 | incr nTest |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 209 | puts "$nErr errors out of $nTest tests" |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 210 | if {$nErr>0} { |
| 211 | puts "Failures on these tests: $::failList" |
| 212 | } |
drh | 80788d8 | 2006-09-02 14:50:23 +0000 | [diff] [blame] | 213 | if {$nErr>0 && ![working_64bit_int]} { |
| 214 | puts "******************************************************************" |
| 215 | puts "N.B.: The version of TCL that you used to build this test harness" |
| 216 | puts "is defective in that it does not support 64-bit integers. Some or" |
| 217 | puts "all of the test failures above might be a result from this defect" |
| 218 | puts "in your TCL build." |
| 219 | puts "******************************************************************" |
drh | db25e38 | 2001-03-15 18:21:22 +0000 | [diff] [blame] | 220 | } |
drh | 94e9203 | 2003-02-16 22:21:32 +0000 | [diff] [blame] | 221 | if {$sqlite_open_file_count} { |
| 222 | puts "$sqlite_open_file_count files were left open" |
| 223 | incr nErr |
| 224 | } |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 225 | if {[sqlite3_memory_used]>0} { |
| 226 | puts "Unfreed memory: [sqlite3_memory_used] bytes" |
| 227 | incr nErr |
drh | 2d7636e | 2008-02-16 16:21:45 +0000 | [diff] [blame] | 228 | ifcapable memdebug||mem5||(mem3&&debug) { |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 229 | puts "Writing unfreed memory log to \"./memleak.txt\"" |
| 230 | sqlite3_memdebug_dump ./memleak.txt |
| 231 | } |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 232 | } else { |
| 233 | puts "All memory allocations freed - no leaks" |
drh | 2d7636e | 2008-02-16 16:21:45 +0000 | [diff] [blame] | 234 | ifcapable memdebug||mem5 { |
drh | d2bb327 | 2007-10-15 19:34:32 +0000 | [diff] [blame] | 235 | sqlite3_memdebug_dump ./memusage.txt |
| 236 | } |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 237 | } |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 238 | puts "Maximum memory usage: [sqlite3_memory_highwater 1] bytes" |
| 239 | puts "Current memory usage: [sqlite3_memory_highwater] bytes" |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 240 | if {[info commands sqlite3_memdebug_malloc_count] ne ""} { |
| 241 | puts "Number of malloc() : [sqlite3_memdebug_malloc_count] calls" |
| 242 | } |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 243 | if {[info exists ::tester_do_malloctrace]} { |
| 244 | puts "Writing mallocs.sql..." |
| 245 | memdebug_log_sql |
| 246 | sqlite3_memdebug_log stop |
| 247 | sqlite3_memdebug_log clear |
| 248 | } |
drh | d9910fe | 2006-10-04 11:55:49 +0000 | [diff] [blame] | 249 | foreach f [glob -nocomplain test.db-*-journal] { |
| 250 | file delete -force $f |
| 251 | } |
| 252 | foreach f [glob -nocomplain test.db-mj*] { |
| 253 | file delete -force $f |
| 254 | } |
drh | db25e38 | 2001-03-15 18:21:22 +0000 | [diff] [blame] | 255 | exit [expr {$nErr>0}] |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 256 | } |
| 257 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 258 | # A procedure to execute SQL |
| 259 | # |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 260 | proc execsql {sql {db db}} { |
drh | acbcdc4 | 2001-01-22 00:31:53 +0000 | [diff] [blame] | 261 | # puts "SQL = $sql" |
danielk1977 | 3bdca9c | 2006-01-17 09:35:01 +0000 | [diff] [blame] | 262 | uplevel [list $db eval $sql] |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 263 | } |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 264 | |
drh | adbca9c | 2001-09-27 15:11:53 +0000 | [diff] [blame] | 265 | # Execute SQL and catch exceptions. |
| 266 | # |
| 267 | proc catchsql {sql {db db}} { |
| 268 | # puts "SQL = $sql" |
| 269 | set r [catch {$db eval $sql} msg] |
| 270 | lappend r $msg |
| 271 | return $r |
| 272 | } |
| 273 | |
drh | 0409648 | 2001-11-09 22:41:44 +0000 | [diff] [blame] | 274 | # Do an VDBE code dump on the SQL given |
| 275 | # |
| 276 | proc explain {sql {db db}} { |
| 277 | puts "" |
danielk1977 | 287fb61 | 2008-01-04 19:10:28 +0000 | [diff] [blame] | 278 | puts "addr opcode p1 p2 p3 p4 p5 #" |
| 279 | puts "---- ------------ ------ ------ ------ --------------- -- -" |
drh | 0409648 | 2001-11-09 22:41:44 +0000 | [diff] [blame] | 280 | $db eval "explain $sql" {} { |
danielk1977 | 287fb61 | 2008-01-04 19:10:28 +0000 | [diff] [blame] | 281 | puts [format {%-4d %-12.12s %-6d %-6d %-6d % -17s %s %s} \ |
| 282 | $addr $opcode $p1 $p2 $p3 $p4 $p5 $comment |
| 283 | ] |
drh | 0409648 | 2001-11-09 22:41:44 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 287 | # Another procedure to execute SQL. This one includes the field |
| 288 | # names in the returned list. |
| 289 | # |
| 290 | proc execsql2 {sql} { |
| 291 | set result {} |
| 292 | db eval $sql data { |
| 293 | foreach f $data(*) { |
| 294 | lappend result $f $data($f) |
| 295 | } |
| 296 | } |
| 297 | return $result |
| 298 | } |
drh | 17a6893 | 2001-01-31 13:28:08 +0000 | [diff] [blame] | 299 | |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 300 | # Use the non-callback API to execute multiple SQL statements |
| 301 | # |
| 302 | proc stepsql {dbptr sql} { |
| 303 | set sql [string trim $sql] |
| 304 | set r 0 |
| 305 | while {[string length $sql]>0} { |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 306 | if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} { |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 307 | return [list 1 $vm] |
| 308 | } |
| 309 | set sql [string trim $sqltail] |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 310 | # while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} { |
| 311 | # foreach v $VAL {lappend r $v} |
| 312 | # } |
| 313 | while {[sqlite3_step $vm]=="SQLITE_ROW"} { |
| 314 | for {set i 0} {$i<[sqlite3_data_count $vm]} {incr i} { |
| 315 | lappend r [sqlite3_column_text $vm $i] |
| 316 | } |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 317 | } |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 318 | if {[catch {sqlite3_finalize $vm} errmsg]} { |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 319 | return [list 1 $errmsg] |
| 320 | } |
| 321 | } |
| 322 | return $r |
| 323 | } |
| 324 | |
drh | 17a6893 | 2001-01-31 13:28:08 +0000 | [diff] [blame] | 325 | # Delete a file or directory |
| 326 | # |
| 327 | proc forcedelete {filename} { |
| 328 | if {[catch {file delete -force $filename}]} { |
| 329 | exec rm -rf $filename |
| 330 | } |
| 331 | } |
drh | 2150432 | 2002-06-25 13:16:02 +0000 | [diff] [blame] | 332 | |
| 333 | # Do an integrity check of the entire database |
| 334 | # |
| 335 | proc integrity_check {name} { |
drh | 27d258a | 2004-10-30 20:23:09 +0000 | [diff] [blame] | 336 | ifcapable integrityck { |
| 337 | do_test $name { |
| 338 | execsql {PRAGMA integrity_check} |
| 339 | } {ok} |
| 340 | } |
| 341 | } |
| 342 | |
danielk1977 | db4e886 | 2008-01-16 08:24:46 +0000 | [diff] [blame] | 343 | proc fix_ifcapable_expr {expr} { |
| 344 | set ret "" |
| 345 | set state 0 |
| 346 | for {set i 0} {$i < [string length $expr]} {incr i} { |
| 347 | set char [string range $expr $i $i] |
| 348 | set newstate [expr {[string is alnum $char] || $char eq "_"}] |
| 349 | if {$newstate && !$state} { |
| 350 | append ret {$::sqlite_options(} |
| 351 | } |
| 352 | if {!$newstate && $state} { |
| 353 | append ret ) |
| 354 | } |
| 355 | append ret $char |
| 356 | set state $newstate |
| 357 | } |
| 358 | if {$state} {append ret )} |
| 359 | return $ret |
| 360 | } |
| 361 | |
drh | 27d258a | 2004-10-30 20:23:09 +0000 | [diff] [blame] | 362 | # Evaluate a boolean expression of capabilities. If true, execute the |
| 363 | # code. Omit the code if false. |
| 364 | # |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 365 | proc ifcapable {expr code {else ""} {elsecode ""}} { |
danielk1977 | db4e886 | 2008-01-16 08:24:46 +0000 | [diff] [blame] | 366 | #regsub -all {[a-z_0-9]+} $expr {$::sqlite_options(&)} e2 |
| 367 | set e2 [fix_ifcapable_expr $expr] |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 368 | if ($e2) { |
| 369 | set c [catch {uplevel 1 $code} r] |
| 370 | } else { |
| 371 | set c [catch {uplevel 1 $elsecode} r] |
| 372 | } |
| 373 | return -code $c $r |
drh | 2150432 | 2002-06-25 13:16:02 +0000 | [diff] [blame] | 374 | } |
danielk1977 | 45901d6 | 2004-11-10 15:27:38 +0000 | [diff] [blame] | 375 | |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 376 | # This proc execs a seperate process that crashes midway through executing |
| 377 | # the SQL script $sql on database test.db. |
| 378 | # |
| 379 | # The crash occurs during a sync() of file $crashfile. When the crash |
| 380 | # occurs a random subset of all unsynced writes made by the process are |
| 381 | # written into the files on disk. Argument $crashdelay indicates the |
| 382 | # number of file syncs to wait before crashing. |
| 383 | # |
| 384 | # The return value is a list of two elements. The first element is a |
| 385 | # boolean, indicating whether or not the process actually crashed or |
| 386 | # reported some other error. The second element in the returned list is the |
| 387 | # error message. This is "child process exited abnormally" if the crash |
| 388 | # occured. |
| 389 | # |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 390 | # crashsql -delay CRASHDELAY -file CRASHFILE ?-blocksize BLOCKSIZE? $sql |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 391 | # |
| 392 | proc crashsql {args} { |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 393 | if {$::tcl_platform(platform)!="unix"} { |
| 394 | error "crashsql should only be used on unix" |
| 395 | } |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 396 | |
| 397 | set blocksize "" |
| 398 | set crashdelay 1 |
drh | cb1f0f6 | 2008-01-08 15:18:52 +0000 | [diff] [blame] | 399 | set prngseed 0 |
drh | f858740 | 2008-01-08 16:03:49 +0000 | [diff] [blame] | 400 | set tclbody {} |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 401 | set crashfile "" |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 402 | set dc "" |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 403 | set sql [lindex $args end] |
| 404 | |
| 405 | for {set ii 0} {$ii < [llength $args]-1} {incr ii 2} { |
| 406 | set z [lindex $args $ii] |
| 407 | set n [string length $z] |
| 408 | set z2 [lindex $args [expr $ii+1]] |
| 409 | |
| 410 | if {$n>1 && [string first $z -delay]==0} {set crashdelay $z2} \ |
drh | cb1f0f6 | 2008-01-08 15:18:52 +0000 | [diff] [blame] | 411 | elseif {$n>1 && [string first $z -seed]==0} {set prngseed $z2} \ |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 412 | elseif {$n>1 && [string first $z -file]==0} {set crashfile $z2} \ |
drh | f858740 | 2008-01-08 16:03:49 +0000 | [diff] [blame] | 413 | elseif {$n>1 && [string first $z -tclbody]==0} {set tclbody $z2} \ |
danielk1977 | 967a4a1 | 2007-08-20 14:23:44 +0000 | [diff] [blame] | 414 | elseif {$n>1 && [string first $z -blocksize]==0} {set blocksize "-s $z2" } \ |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 415 | elseif {$n>1 && [string first $z -characteristics]==0} {set dc "-c {$z2}" } \ |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 416 | else { error "Unrecognized option: $z" } |
| 417 | } |
| 418 | |
| 419 | if {$crashfile eq ""} { |
| 420 | error "Compulsory option -file missing" |
| 421 | } |
| 422 | |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 423 | set cfile [file join [pwd] $crashfile] |
| 424 | |
| 425 | set f [open crash.tcl w] |
danielk1977 | ca0c897 | 2007-09-01 09:02:53 +0000 | [diff] [blame] | 426 | puts $f "sqlite3_crash_enable 1" |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 427 | puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile" |
danielk1977 | 933bbd6 | 2007-03-17 07:22:42 +0000 | [diff] [blame] | 428 | puts $f "set sqlite_pending_byte $::sqlite_pending_byte" |
danielk1977 | 95c8a54 | 2007-09-01 06:51:27 +0000 | [diff] [blame] | 429 | puts $f "sqlite3 db test.db -vfs crash" |
danielk1977 | 933bbd6 | 2007-03-17 07:22:42 +0000 | [diff] [blame] | 430 | |
| 431 | # This block sets the cache size of the main database to 10 |
| 432 | # pages. This is done in case the build is configured to omit |
| 433 | # "PRAGMA cache_size". |
| 434 | puts $f {db eval {SELECT * FROM sqlite_master;}} |
| 435 | puts $f {set bt [btree_from_db db]} |
| 436 | puts $f {btree_set_cache_size $bt 10} |
drh | cb1f0f6 | 2008-01-08 15:18:52 +0000 | [diff] [blame] | 437 | if {$prngseed} { |
| 438 | set seed [expr {$prngseed%10007+1}] |
| 439 | # puts seed=$seed |
| 440 | puts $f "db eval {SELECT randomblob($seed)}" |
| 441 | } |
danielk1977 | 933bbd6 | 2007-03-17 07:22:42 +0000 | [diff] [blame] | 442 | |
drh | f858740 | 2008-01-08 16:03:49 +0000 | [diff] [blame] | 443 | if {[string length $tclbody]>0} { |
| 444 | puts $f $tclbody |
| 445 | } |
| 446 | if {[string length $sql]>0} { |
| 447 | puts $f "db eval {" |
| 448 | puts $f "$sql" |
| 449 | puts $f "}" |
| 450 | } |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 451 | close $f |
| 452 | |
| 453 | set r [catch { |
drh | 9c06c95 | 2005-11-26 00:25:00 +0000 | [diff] [blame] | 454 | exec [info nameofexec] crash.tcl >@stdout |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 455 | } msg] |
| 456 | lappend r $msg |
| 457 | } |
| 458 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 459 | # Usage: do_ioerr_test <test number> <options...> |
| 460 | # |
| 461 | # This proc is used to implement test cases that check that IO errors |
| 462 | # are correctly handled. The first argument, <test number>, is an integer |
| 463 | # used to name the tests executed by this proc. Options are as follows: |
| 464 | # |
| 465 | # -tclprep TCL script to run to prepare test. |
| 466 | # -sqlprep SQL script to run to prepare test. |
| 467 | # -tclbody TCL script to run with IO error simulation. |
| 468 | # -sqlbody TCL script to run with IO error simulation. |
| 469 | # -exclude List of 'N' values not to test. |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 470 | # -erc Use extended result codes |
drh | d5eb79e | 2007-03-15 12:17:42 +0000 | [diff] [blame] | 471 | # -persist Make simulated I/O errors persistent |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 472 | # -start Value of 'N' to begin with (default 1) |
| 473 | # |
| 474 | # -cksum Boolean. If true, test that the database does |
| 475 | # not change during the execution of the test case. |
| 476 | # |
| 477 | proc do_ioerr_test {testname args} { |
| 478 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 479 | set ::ioerropts(-start) 1 |
| 480 | set ::ioerropts(-cksum) 0 |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 481 | set ::ioerropts(-erc) 0 |
drh | c2ee76c | 2007-01-04 14:58:14 +0000 | [diff] [blame] | 482 | set ::ioerropts(-count) 100000000 |
drh | d5eb79e | 2007-03-15 12:17:42 +0000 | [diff] [blame] | 483 | set ::ioerropts(-persist) 1 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 484 | array set ::ioerropts $args |
| 485 | |
| 486 | set ::go 1 |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 487 | #reset_prng_state |
| 488 | save_prng_state |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 489 | for {set n $::ioerropts(-start)} {$::go} {incr n} { |
danielk1977 | 92d4d7a | 2007-05-04 12:05:56 +0000 | [diff] [blame] | 490 | set ::TN $n |
drh | c2ee76c | 2007-01-04 14:58:14 +0000 | [diff] [blame] | 491 | incr ::ioerropts(-count) -1 |
| 492 | if {$::ioerropts(-count)<0} break |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 493 | |
| 494 | # Skip this IO error if it was specified with the "-exclude" option. |
| 495 | if {[info exists ::ioerropts(-exclude)]} { |
| 496 | if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue |
| 497 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 498 | restore_prng_state |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 499 | |
| 500 | # Delete the files test.db and test2.db, then execute the TCL and |
| 501 | # SQL (in that order) to prepare for the test case. |
| 502 | do_test $testname.$n.1 { |
| 503 | set ::sqlite_io_error_pending 0 |
| 504 | catch {db close} |
| 505 | catch {file delete -force test.db} |
| 506 | catch {file delete -force test.db-journal} |
| 507 | catch {file delete -force test2.db} |
| 508 | catch {file delete -force test2.db-journal} |
drh | a34c62d | 2006-01-06 22:11:20 +0000 | [diff] [blame] | 509 | set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db] |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 510 | sqlite3_extended_result_codes $::DB $::ioerropts(-erc) |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 511 | if {[info exists ::ioerropts(-tclprep)]} { |
| 512 | eval $::ioerropts(-tclprep) |
| 513 | } |
| 514 | if {[info exists ::ioerropts(-sqlprep)]} { |
| 515 | execsql $::ioerropts(-sqlprep) |
| 516 | } |
| 517 | expr 0 |
| 518 | } {0} |
| 519 | |
| 520 | # Read the 'checksum' of the database. |
| 521 | if {$::ioerropts(-cksum)} { |
| 522 | set checksum [cksum] |
| 523 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 524 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 525 | # Set the Nth IO error to fail. |
| 526 | do_test $testname.$n.2 [subst { |
drh | d5eb79e | 2007-03-15 12:17:42 +0000 | [diff] [blame] | 527 | set ::sqlite_io_error_persist $::ioerropts(-persist) |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 528 | set ::sqlite_io_error_pending $n |
| 529 | }] $n |
| 530 | |
| 531 | # Create a single TCL script from the TCL and SQL specified |
| 532 | # as the body of the test. |
| 533 | set ::ioerrorbody {} |
| 534 | if {[info exists ::ioerropts(-tclbody)]} { |
| 535 | append ::ioerrorbody "$::ioerropts(-tclbody)\n" |
| 536 | } |
| 537 | if {[info exists ::ioerropts(-sqlbody)]} { |
| 538 | append ::ioerrorbody "db eval {$::ioerropts(-sqlbody)}" |
| 539 | } |
| 540 | |
| 541 | # Execute the TCL Script created in the above block. If |
| 542 | # there are at least N IO operations performed by SQLite as |
| 543 | # a result of the script, the Nth will fail. |
| 544 | do_test $testname.$n.3 { |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 545 | set ::sqlite_io_error_hit 0 |
| 546 | set ::sqlite_io_error_hardhit 0 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 547 | set r [catch $::ioerrorbody msg] |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 548 | set ::errseen $r |
drh | e49f982 | 2006-09-15 12:29:16 +0000 | [diff] [blame] | 549 | set rc [sqlite3_errcode $::DB] |
| 550 | if {$::ioerropts(-erc)} { |
drh | 5f7b5bf | 2007-04-19 12:30:54 +0000 | [diff] [blame] | 551 | # If we are in extended result code mode, make sure all of the |
| 552 | # IOERRs we get back really do have their extended code values. |
| 553 | # If an extended result code is returned, the sqlite3_errcode |
| 554 | # TCLcommand will return a string of the form: SQLITE_IOERR+nnnn |
| 555 | # where nnnn is a number |
drh | e49f982 | 2006-09-15 12:29:16 +0000 | [diff] [blame] | 556 | if {[regexp {^SQLITE_IOERR} $rc] && ![regexp {IOERR\+\d} $rc]} { |
| 557 | return $rc |
| 558 | } |
| 559 | } else { |
drh | 5f7b5bf | 2007-04-19 12:30:54 +0000 | [diff] [blame] | 560 | # If we are not in extended result code mode, make sure no |
| 561 | # extended error codes are returned. |
drh | e49f982 | 2006-09-15 12:29:16 +0000 | [diff] [blame] | 562 | if {[regexp {\+\d} $rc]} { |
| 563 | return $rc |
| 564 | } |
| 565 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 566 | # The test repeats as long as $::go is non-zero. $::go starts out |
| 567 | # as 1. When a test runs to completion without hitting an I/O |
| 568 | # error, that means there is no point in continuing with this test |
| 569 | # case so set $::go to zero. |
| 570 | # |
| 571 | if {$::sqlite_io_error_pending>0} { |
| 572 | set ::go 0 |
| 573 | set q 0 |
| 574 | set ::sqlite_io_error_pending 0 |
| 575 | } else { |
| 576 | set q 1 |
| 577 | } |
| 578 | |
drh | c9ac5ca | 2005-11-04 22:03:30 +0000 | [diff] [blame] | 579 | set s [expr $::sqlite_io_error_hit==0] |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 580 | if {$::sqlite_io_error_hit>$::sqlite_io_error_hardhit && $r==0} { |
| 581 | set r 1 |
| 582 | } |
danielk1977 | f2fa831 | 2006-01-24 13:09:33 +0000 | [diff] [blame] | 583 | set ::sqlite_io_error_hit 0 |
drh | 5f7b5bf | 2007-04-19 12:30:54 +0000 | [diff] [blame] | 584 | |
| 585 | # One of two things must have happened. either |
| 586 | # 1. We never hit the IO error and the SQL returned OK |
| 587 | # 2. An IO error was hit and the SQL failed |
| 588 | # |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 589 | expr { ($s && !$r && !$q) || (!$s && $r && $q) } |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 590 | } {1} |
| 591 | |
| 592 | # If an IO error occured, then the checksum of the database should |
| 593 | # be the same as before the script that caused the IO error was run. |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 594 | if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-cksum)} { |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 595 | do_test $testname.$n.4 { |
| 596 | catch {db close} |
drh | a34c62d | 2006-01-06 22:11:20 +0000 | [diff] [blame] | 597 | set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db] |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 598 | cksum |
| 599 | } $checksum |
| 600 | } |
| 601 | |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 602 | set ::sqlite_io_error_hardhit 0 |
danielk1977 | c4da5b9 | 2006-01-21 12:08:54 +0000 | [diff] [blame] | 603 | set ::sqlite_io_error_pending 0 |
danielk1977 | 105afed | 2005-05-26 15:20:53 +0000 | [diff] [blame] | 604 | if {[info exists ::ioerropts(-cleanup)]} { |
| 605 | catch $::ioerropts(-cleanup) |
| 606 | } |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 607 | } |
| 608 | set ::sqlite_io_error_pending 0 |
drh | 6d54da0 | 2007-03-25 19:08:46 +0000 | [diff] [blame] | 609 | set ::sqlite_io_error_persist 0 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 610 | unset ::ioerropts |
| 611 | } |
| 612 | |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 613 | # Return a checksum based on the contents of the main database associated |
| 614 | # with connection $db |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 615 | # |
| 616 | proc cksum {{db db}} { |
| 617 | set txt [$db eval { |
| 618 | SELECT name, type, sql FROM sqlite_master order by name |
| 619 | }]\n |
| 620 | foreach tbl [$db eval { |
| 621 | SELECT name FROM sqlite_master WHERE type='table' order by name |
| 622 | }] { |
| 623 | append txt [$db eval "SELECT * FROM $tbl"]\n |
| 624 | } |
| 625 | foreach prag {default_synchronous default_cache_size} { |
| 626 | append txt $prag-[$db eval "PRAGMA $prag"]\n |
| 627 | } |
| 628 | set cksum [string length $txt]-[md5 $txt] |
| 629 | # puts $cksum-[file size test.db] |
| 630 | return $cksum |
| 631 | } |
| 632 | |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 633 | # Generate a checksum based on the contents of the main and temp tables |
| 634 | # database $db. If the checksum of two databases is the same, and the |
| 635 | # integrity-check passes for both, the two databases are identical. |
| 636 | # |
drh | 1db639c | 2008-01-17 02:36:28 +0000 | [diff] [blame] | 637 | proc allcksum {{db db}} { |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 638 | set ret [list] |
| 639 | ifcapable tempdb { |
| 640 | set sql { |
| 641 | SELECT name FROM sqlite_master WHERE type = 'table' UNION |
| 642 | SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION |
| 643 | SELECT 'sqlite_master' UNION |
| 644 | SELECT 'sqlite_temp_master' ORDER BY 1 |
| 645 | } |
| 646 | } else { |
| 647 | set sql { |
| 648 | SELECT name FROM sqlite_master WHERE type = 'table' UNION |
| 649 | SELECT 'sqlite_master' ORDER BY 1 |
| 650 | } |
| 651 | } |
| 652 | set tbllist [$db eval $sql] |
| 653 | set txt {} |
| 654 | foreach tbl $tbllist { |
| 655 | append txt [$db eval "SELECT * FROM $tbl"] |
| 656 | } |
| 657 | foreach prag {default_cache_size} { |
| 658 | append txt $prag-[$db eval "PRAGMA $prag"]\n |
| 659 | } |
| 660 | # puts txt=$txt |
| 661 | return [md5 $txt] |
| 662 | } |
| 663 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 664 | proc memdebug_log_sql {{filename mallocs.sql}} { |
| 665 | |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 666 | set data [sqlite3_memdebug_log dump] |
| 667 | set nFrame [expr [llength [lindex $data 0]]-2] |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 668 | if {$nFrame < 0} { return "" } |
| 669 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 670 | set database temp |
| 671 | |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 672 | set tbl "CREATE TABLE ${database}.malloc(nCall, nByte" |
| 673 | for {set ii 1} {$ii <= $nFrame} {incr ii} { |
| 674 | append tbl ", f${ii}" |
| 675 | } |
| 676 | append tbl ");\n" |
| 677 | |
| 678 | set sql "" |
| 679 | foreach e $data { |
| 680 | append sql "INSERT INTO ${database}.malloc VALUES([join $e ,]);\n" |
| 681 | foreach f [lrange $e 2 end] { |
| 682 | set frames($f) 1 |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | set tbl2 "CREATE TABLE ${database}.frame(frame INTEGER PRIMARY KEY, line);\n" |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 687 | set tbl3 "CREATE TABLE ${database}.file(name PRIMARY KEY, content);\n" |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 688 | |
| 689 | foreach f [array names frames] { |
| 690 | set addr [format %x $f] |
| 691 | set cmd "addr2line -e [info nameofexec] $addr" |
| 692 | set line [eval exec $cmd] |
| 693 | append sql "INSERT INTO ${database}.frame VALUES($f, '$line');\n" |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 694 | |
| 695 | set file [lindex [split $line :] 0] |
| 696 | set files($file) 1 |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 697 | } |
| 698 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 699 | foreach f [array names files] { |
| 700 | set contents "" |
| 701 | catch { |
| 702 | set fd [open $f] |
| 703 | set contents [read $fd] |
| 704 | close $fd |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 705 | } |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 706 | set contents [string map {' ''} $contents] |
| 707 | append sql "INSERT INTO ${database}.file VALUES('$f', '$contents');\n" |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 708 | } |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 709 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame^] | 710 | set fd [open $filename w] |
| 711 | puts $fd "BEGIN; ${tbl}${tbl2}${tbl3}${sql} ; COMMIT;" |
| 712 | close $fd |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 713 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 714 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 715 | # Copy file $from into $to. This is used because some versions of |
| 716 | # TCL for windows (notably the 8.4.1 binary package shipped with the |
| 717 | # current mingw release) have a broken "file copy" command. |
| 718 | # |
| 719 | proc copy_file {from to} { |
| 720 | if {$::tcl_platform(platform)=="unix"} { |
| 721 | file copy -force $from $to |
| 722 | } else { |
| 723 | set f [open $from] |
| 724 | fconfigure $f -translation binary |
| 725 | set t [open $to w] |
| 726 | fconfigure $t -translation binary |
| 727 | puts -nonewline $t [read $f [file size $from]] |
| 728 | close $t |
| 729 | close $f |
| 730 | } |
| 731 | } |
| 732 | |
danielk1977 | 45901d6 | 2004-11-10 15:27:38 +0000 | [diff] [blame] | 733 | # If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set |
| 734 | # to non-zero, then set the global variable $AUTOVACUUM to 1. |
| 735 | set AUTOVACUUM $sqlite_options(default_autovacuum) |