From: drh Date: Wed, 12 Oct 2016 18:26:26 +0000 (+0000) Subject: Add to sqlite3_analyzer command-line options --version and --tclsh, and also X-Git-Tag: version-3.15.0~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=432697467f03f10800f4cf8e04752004a1e75182;p=thirdparty%2Fsqlite.git Add to sqlite3_analyzer command-line options --version and --tclsh, and also the undocumented --debug option. FossilOrigin-Name: e87d02d289a2016ea3ee074e914b07a8ac22b21f --- diff --git a/manifest b/manifest index e13f42949f..241e0db8a7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\stestcase()\smacros\sto\sensure\scoverage\sof\sthe\sORDER\sBY\sLIMIT\soptimization\ncode\sin\swhere.c. -D 2016-10-12T15:15:30.391 +C Add\sto\ssqlite3_analyzer\scommand-line\soptions\s--version\sand\s--tclsh,\sand\salso\nthe\sundocumented\s--debug\soption. +D 2016-10-12T18:26:26.364 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f @@ -1484,7 +1484,7 @@ F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 F tool/showstat4.c bda40d6e395df7edb6e9ea630784d3d762c35b4b F tool/showwal.c ec79959834f7b21f1e0a2aa52bb7c056d2203977 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe -F tool/spaceanal.tcl 85d90e6674d8298e3eaf82dbcef3abc2d5317f3e +F tool/spaceanal.tcl ab7d9bf68062907282a64b3e12ccbfad47193c5a F tool/speed-check.sh da6ce45957c509ba6343fe3fef167e7e2b306262 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest16.c ecb6542862151c3e6509bbc00509b234562ae81e @@ -1525,7 +1525,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8e2b25f9b8a7ed087d3cece74239814bee19429e -R 85b771c181ab2a587da3b9154662733d +P 61f0526978af667781c57bcc87510e4524efd0d8 +R 939be1793993bb5a0733cfe788e02f4d U drh -Z ed0e3333d86697e18712f68be162b390 +Z 3046f41ed5ee9baf8f6c825aaff1459e diff --git a/manifest.uuid b/manifest.uuid index 704a1a0c21..ceae9890fc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -61f0526978af667781c57bcc87510e4524efd0d8 \ No newline at end of file +e87d02d289a2016ea3ee074e914b07a8ac22b21f \ No newline at end of file diff --git a/tool/spaceanal.tcl b/tool/spaceanal.tcl index eef1192a1d..e7ce846f86 100644 --- a/tool/spaceanal.tcl +++ b/tool/spaceanal.tcl @@ -22,6 +22,33 @@ proc is_without_rowid {tname} { return 0 } +# Read and run TCL commands from standard input. Used to implement +# the --tclsh option. +# +proc tclsh {} { + set line {} + while {![eof stdin]} { + if {$line!=""} { + puts -nonewline "> " + } else { + puts -nonewline "% " + } + flush stdout + append line [gets stdin] + if {[info complete $line]} { + if {[catch {uplevel #0 $line} result]} { + puts stderr "Error: $result" + } elseif {$result!=""} { + puts $result + } + set line {} + } else { + append line \n + } + } +} + + # Get the name of the database to analyze # proc usage {} { @@ -34,22 +61,37 @@ information for the database and its constituent tables and indexes. Options: - --stats Output SQL text that creates a new database containing - statistics about the database that was analyzed + --pageinfo Show how each page of the database-file is used + + --stats Output SQL text that creates a new database containing + statistics about the database that was analyzed + + --tclsh Run the built-in TCL interpreter interactively (for debugging) - --pageinfo Show how each page of the database-file is used + --version Show the version number of SQLite } exit 1 } set file_to_analyze {} set flags(-pageinfo) 0 set flags(-stats) 0 +set flags(-debug) 0 append argv {} foreach arg $argv { if {[regexp {^-+pageinfo$} $arg]} { set flags(-pageinfo) 1 } elseif {[regexp {^-+stats$} $arg]} { set flags(-stats) 1 + } elseif {[regexp {^-+debug$} $arg]} { + set flags(-debug) 1 + } elseif {[regexp {^-+tclsh$} $arg]} { + tclsh + exit 0 + } elseif {[regexp {^-+version$} $arg]} { + sqlite3 mem :memory: + puts [mem one {SELECT sqlite_version()||' '||sqlite_source_id()}] + mem close + exit 0 } elseif {[regexp {^-} $arg]} { puts stderr "Unknown option: $arg" usage @@ -100,6 +142,10 @@ if {[catch {sqlite3 db $file_to_analyze -uri 1} msg]} { puts stderr "error trying to open $file_to_analyze: $msg" exit 1 } +if {$flags(-debug)} { + proc dbtrace {txt} {puts $txt; flush stdout;} + db trace ::dbtrace +} db eval {SELECT count(*) FROM sqlite_master} set pageSize [expr {wide([db one {PRAGMA page_size}])}] @@ -142,12 +188,17 @@ if {$flags(-stats)} { exit 0 } + # In-memory database for collecting statistics. This script loops through # the tables and indices in the database being analyzed, adding a row for each # to an in-memory database (for which the schema is shown below). It then # queries the in-memory db to produce the space-analysis report. # sqlite3 mem :memory: +if {$flags(-debug)} { + proc dbtrace {txt} {puts $txt; flush stdout;} + mem trace ::dbtrace +} set tabledef {CREATE TABLE space_used( name clob, -- Name of a table or index in the database file tblname clob, -- Name of associated table