diff options
Diffstat (limited to '')
-rw-r--r-- | www/stmt.html | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/www/stmt.html b/www/stmt.html new file mode 100644 index 0000000..1e93fb8 --- /dev/null +++ b/www/stmt.html @@ -0,0 +1,266 @@ +<!DOCTYPE html> +<html><head> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<link href="sqlite.css" rel="stylesheet"> +<title>The SQLITE_STMT Virtual Table</title> +<!-- path= --> +</head> +<body> +<div class=nosearch> +<a href="index.html"> +<img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0"> +</a> +<div><!-- IE hack to prevent disappearing logo --></div> +<div class="tagline desktoponly"> +Small. Fast. Reliable.<br>Choose any three. +</div> +<div class="menu mainmenu"> +<ul> +<li><a href="index.html">Home</a> +<li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a> +<li class='wideonly'><a href='about.html'>About</a> +<li class='desktoponly'><a href="docs.html">Documentation</a> +<li class='desktoponly'><a href="download.html">Download</a> +<li class='wideonly'><a href='copyright.html'>License</a> +<li class='desktoponly'><a href="support.html">Support</a> +<li class='desktoponly'><a href="prosupport.html">Purchase</a> +<li class='search' id='search_menubutton'> +<a href="javascript:void(0)" onclick='toggle_search()'>Search</a> +</ul> +</div> +<div class="menu submenu" id="submenu"> +<ul> +<li><a href='about.html'>About</a> +<li><a href='docs.html'>Documentation</a> +<li><a href='download.html'>Download</a> +<li><a href='support.html'>Support</a> +<li><a href='prosupport.html'>Purchase</a> +</ul> +</div> +<div class="searchmenu" id="searchmenu"> +<form method="GET" action="search"> +<select name="s" id="searchtype"> +<option value="d">Search Documentation</option> +<option value="c">Search Changelog</option> +</select> +<input type="text" name="q" id="searchbox" value=""> +<input type="submit" value="Go"> +</form> +</div> +</div> +<script> +function toggle_div(nm) { +var w = document.getElementById(nm); +if( w.style.display=="block" ){ +w.style.display = "none"; +}else{ +w.style.display = "block"; +} +} +function toggle_search() { +var w = document.getElementById("searchmenu"); +if( w.style.display=="block" ){ +w.style.display = "none"; +} else { +w.style.display = "block"; +setTimeout(function(){ +document.getElementById("searchbox").focus() +}, 30); +} +} +function div_off(nm){document.getElementById(nm).style.display="none";} +window.onbeforeunload = function(e){div_off("submenu");} +/* Disable the Search feature if we are not operating from CGI, since */ +/* Search is accomplished using CGI and will not work without it. */ +if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){ +document.getElementById("search_menubutton").style.display = "none"; +} +/* Used by the Hide/Show button beside syntax diagrams, to toggle the */ +function hideorshow(btn,obj){ +var x = document.getElementById(obj); +var b = document.getElementById(btn); +if( x.style.display!='none' ){ +x.style.display = 'none'; +b.innerHTML='show'; +}else{ +x.style.display = ''; +b.innerHTML='hide'; +} +return false; +} +var antiRobot = 0; +function antiRobotGo(){ +if( antiRobot!=3 ) return; +antiRobot = 7; +var j = document.getElementById("mtimelink"); +if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href"); +} +function antiRobotDefense(){ +document.body.onmousedown=function(){ +antiRobot |= 2; +antiRobotGo(); +document.body.onmousedown=null; +} +document.body.onmousemove=function(){ +antiRobot |= 2; +antiRobotGo(); +document.body.onmousemove=null; +} +setTimeout(function(){ +antiRobot |= 1; +antiRobotGo(); +}, 100) +antiRobotGo(); +} +antiRobotDefense(); +</script> +<div class=fancy> +<div class=nosearch> +<div class="fancy_title"> +The SQLITE_STMT Virtual Table +</div> +</div> + + + + +<h1 id="overview"><span>1. </span>Overview</h1> + +<p> +The SQLITE_STMT extension implements an <a href="vtab.html#epoonlyvtab">eponymous-only virtual table</a> that +provides information about all <a href="c3ref/stmt.html">prepared statements</a> associated with +the <a href="c3ref/sqlite3.html">database connection</a>. +</p> + +<p> +The SQLITE_STMT extension is included in the <a href="amalgamation.html">amalgamation</a> though +it is disabled +by default. Use the <a href="compile.html#enable_stmtvtab">SQLITE_ENABLE_STMTVTAB</a> compile-time option to enable +the SQLITE_STMT extension. The SQLITE_STMT extension can also be +loaded at run-time +by compiling the extension into a shared library or DLL using the source +code at <a href="https://sqlite.org/src/file/ext/misc/stmt.c">https://sqlite.org/src/file/ext/misc/stmt.c</a> and following the +instructions for how to <a href="loadext.html#build">compile loadable extensions</a>. +</p> + +<p> +The SQLITE_STMT extension is enabled in default builds +of the <a href="cli.html">command-line shell</a>. + +</p><h1 id="usage"><span>2. </span>Usage</h1> + +<p> +The SQLITE_STMT virtual table is a read-only table that can be directly +queried to access information about all prepared statements on the +current database connection. For example: + +</p><div class="codeblock"><pre>SELECT * FROM sqlite_stmt; +</pre></div> + +<p> +A statement such as the above can be run immediately prior to invoking +<a href="c3ref/close.html">sqlite3_close()</a> to confirm that all prepared statements have been +<a href="c3ref/finalize.html">finalized</a> and to help identify and track down prepared +statements that have "leaked" and missed finalization. + +</p><p> +The SQLITE_STMT virtual table can also be used to access performance +information about prepared statements, to aid in optimization an application. +For example, +to find out how much memory is being used by <a href="c3ref/stmt.html">prepared statements</a> that have +never been used, one could run: + +</p><div class="codeblock"><pre>SELECT sum(mem) FROM sqlite_stmt WHERE run=0; +</pre></div> + +<h2 id="columns"><span>2.1. </span>Columns</h2> + +<p> +The columns are provided by the SQLITE_STMT virtual table are summarized by +the hypothetical CREATE TABLE statement show here: + +</p><div class="codeblock"><pre>CREATE TABLE sqlite_stmt( + sql TEXT, -- Original SQL text + ncol INT, -- Number of output columns + ro BOOLEAN, -- True for "read only" statements + busy BOOLEAN, -- True if the statement is current running + nscan INT, -- Number of full-scan steps + nsort INT, -- Number of sort operations + naidx INT, -- Number of automatic index inserts + nstep INT, -- Number of byte-code engine steps + reprep INT, -- Number of reprepare operations + run INT, -- Number of times this statement has been run + mem INT -- Heap memory used by this statement +); +</pre></div> + +<p>Future releases may add new output columns and may change the order +of legacy columns. +Further detail about the meaning of each column in the SQLITE_STMT virtual +table is provided below: + +</p><ul> +<li><p><b>sql</b>: +The original SQL text of the prepared statement. If the prepared +statement is compiled using the <a href="c3ref/prepare.html">sqlite3_prepare()</a> interface, then +the SQL text might not have been saved, in which case this column +will be NULL. + +</p></li><li><p><b>ncol</b>: +The number of columns in the result set of a query. +For DML statements, this column has a value of 0. + +</p></li><li><p><b>ro</b>: +The "read only" column. This column is true (non-zero) if the +SQL statement is a query and false (zero) if it is a DML statement. + +</p></li><li><p><b>busy</b>: +This field is true if the prepared statement is currently running. +In other words, this field is true if <a href="c3ref/step.html">sqlite3_step()</a> has been called +on the <a href="c3ref/stmt.html">prepared statement</a> at least once but <a href="c3ref/reset.html">sqlite3_reset()</a> has +not yet been called to reset it. + +</p></li><li><p><b>nscan</b>: +This field is the number of times that the <a href="opcode.html">bytecode engine</a> has stepped +through a table as part of a full-table scan. A large number if this +field may indicate an opportunity to improve performance by adding an +index. This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatusfullscanstep">SQLITE_STMTSTATUS_FULLSCAN_STEP</a> +value. + +</p></li><li><p><b>nsort</b>: +This field is the number of times that the <a href="opcode.html">bytecode engine</a> had to sort. +A positive value in this field may indicate an opportunity to improve +performance by adding an index that will cause the query results to +appear naturally in the desired order. +This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatussort">SQLITE_STMTSTATUS_SORT</a> value. + +</p></li><li><p><b>naidx</b>: +This field is the number of rows that have been inserted into +<a href="optoverview.html#autoindex">automatic indexes</a>. A positive value in this field may indicate +an opportunity to improve performance by adding a named index that +take the place of the automatic index. +This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatusautoindex">SQLITE_STMTSTATUS_AUTOINDEX</a> value. + +</p></li><li><p><b>nstep</b>: +This field is the number of <a href="opcode.html">bytecode engine</a> operations that have +been performed for the prepared statement. This field can be used +as a proxy for how much CPU time a statement has used. +This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatusvmstep">SQLITE_STMTSTATUS_VM_STEP</a> value. + +</p></li><li><p><b>reprep</b>: +This field is the number of times that the statement has had to be +reprepared due to schema changes or changes to parameter bindings. +This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatusreprepare">SQLITE_STMTSTATUS_REPREPARE</a> value. + +</p></li><li><p><b>run</b>: +This field is the number of times that the statement has been run. +This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatusrun">SQLITE_STMTSTATUS_RUN</a> value. + +</p></li><li><p><b>mem</b>: +This field is the number of bytes of heap storage used by the +prepared statement. +This field is equivalent to the <a href="c3ref/c_stmtstatus_counter.html#sqlitestmtstatusmemused">SQLITE_STMTSTATUS_MEMUSED</a> value. +</p></li></ul> +<p align="center"><small><i>This page last modified on <a href="https://sqlite.org/docsrc/honeypot" id="mtimelink" data-href="https://sqlite.org/docsrc/finfo/pages/stmt.in?m=9368174a6e34d9b2c">2017-07-14 15:38:02</a> UTC </small></i></p> + |