/usr/share/doc/python-apsw/html/execution.html is in python-apsw-doc 3.8.2-r1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Execution and tracing — APSW 3.8.2-r1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '3.8.2-r1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="copyright" title="Copyright" href="copyright.html" />
<link rel="top" title="APSW 3.8.2-r1 documentation" href="index.html" />
<link rel="next" title="DBAPI notes" href="dbapi.html" />
<link rel="prev" title="Types" href="types.html" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26815066-1']);
_gaq.push(['_trackPageview']);
</script>
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="dbapi.html" title="DBAPI notes"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="types.html" title="Types"
accesskey="P">previous</a> |</li>
<li><a href="index.html">APSW 3.8.2-r1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="execution-and-tracing">
<h1>Execution and tracing<a class="headerlink" href="#execution-and-tracing" title="Permalink to this headline">¶</a></h1>
<div class="section" id="execution-model">
<span id="executionmodel"></span><h2>Execution model<a class="headerlink" href="#execution-model" title="Permalink to this headline">¶</a></h2>
<p>This section only matters if you give multiple SQL statements in one go to <a class="reference internal" href="cursor.html#apsw.Cursor.execute" title="apsw.Cursor.execute"><tt class="xref py py-exc docutils literal"><span class="pre">Cursor.execute</span></tt></a>.
(Statements are seperated by semi-colons.)</p>
<p>SQLite does execution in two steps. First a statement is prepared,
which verifies the syntax, tables and fields and converts the
statement into an internal representation. The prepared statement is
then run. Execution stops when a row is available, there is an error
or the statement is complete.</p>
<p>The <a class="reference internal" href="cursor.html#apsw.Cursor.execute" title="apsw.Cursor.execute"><tt class="xref py py-meth docutils literal"><span class="pre">Cursor.execute()</span></tt></a> method automatically does the preparing and
starts execution. If none of the statements return rows then execution
will go to the end. If a row is returned then you need to call
<a class="reference internal" href="cursor.html#apsw.Cursor.next" title="apsw.Cursor.next"><tt class="xref py py-meth docutils literal"><span class="pre">Cursor.next()</span></tt></a> to get the row values or use the cursor as an
iterator. Execution will resume as necessary to satisfy
<a class="reference internal" href="cursor.html#apsw.Cursor.next" title="apsw.Cursor.next"><tt class="xref py py-meth docutils literal"><span class="pre">next()</span></tt></a> calls.</p>
<p>However this means that if you don’t read the rows returned then the
rest of your statements won’t be executed. APSW will detect
unexecuted previous statements and generate an exception. For
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">"select * from foo ; create table bar(x,y,z)"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">"create table bam(x,y,z)"</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n">?</span>
<span class="gr">apsw.IncompleteExecutionError</span>: <span class="n">Error: there are still remaining sql statements to execute</span>
</pre></div>
</div>
<p>Because I didn’t read the results of <tt class="docutils literal"><span class="pre">select</span> <span class="pre">*</span> <span class="pre">from</span> <span class="pre">foo</span></tt> then the
following create table command didn’t have a chance to get
executed. On the next execute that condition is detected and an
exception raised.</p>
</div>
<div class="section" id="multi-threading-and-re-entrancy">
<h2>Multi-threading and re-entrancy<a class="headerlink" href="#multi-threading-and-re-entrancy" title="Permalink to this headline">¶</a></h2>
<p>ASPW lets you use SQLite in multi-threaded programs and will let other
threads execute while SQLite is working. (Technically the <a class="reference external" href="http://www.python.org/doc/2.3.4/api/threads.html">GIL</a> is released when
<a class="reference external" href="https://sqlite.org/c3ref/prepare.html">sqlite3_prepare_v2</a>,
<a class="reference external" href="https://sqlite.org/c3ref/step.html">sqlite3_step</a> or
<a class="reference external" href="https://sqlite.org/c3ref/open.html">sqlite3_open_v2</a> are running, as
well as all other functions that could take more than a trivial amount
of time or use the SQLite mutex. The GIL is re-acquired while user
defined functions, collations and the various hooks/handlers run.)</p>
<p>Note that you cannot use the same cursor object in multiple threads
concurrently to execute statements. APSW will detect this and throw an
exception. It is safe to use the object serially (eg calling
<a class="reference internal" href="cursor.html#apsw.Cursor.execute" title="apsw.Cursor.execute"><tt class="xref py py-meth docutils literal"><span class="pre">Cursor.execute()</span></tt></a> in one thread and <a class="reference internal" href="cursor.html#apsw.Cursor.next" title="apsw.Cursor.next"><tt class="xref py py-meth docutils literal"><span class="pre">Cursor.next()</span></tt></a> in
another. You also can’t do things like try to
<a class="reference internal" href="connection.html#apsw.Connection.close" title="apsw.Connection.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> a Connection concurrently in two threads.</p>
<p>If you have multiple threads and/or multiple programs accessing the
same database then there may be contention for the file. SQLite will
return SQLITE_BUSY which will be raised as BusyError. You can call
<a class="reference internal" href="connection.html#apsw.Connection.setbusytimeout" title="apsw.Connection.setbusytimeout"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.setbusytimeout()</span></tt></a> to set how long SQLite will retry
for or <a class="reference internal" href="connection.html#apsw.Connection.setbusyhandler" title="apsw.Connection.setbusyhandler"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.setbusyhandler()</span></tt></a> to install your own busy
handler. Note that SQLite won’t call the busy handler or timeout if it
believes a deadlock has arisen. SQLite’s locking and concurrency is
described <a class="reference external" href="https://sqlite.org/lockingv3.html">here</a>.</p>
<p>A cursor object can only be executing one query at a time. You cannot
issue a new query from inside a trace function or from a user defined
function or collation since these are called while executing a
query. You can however make new cursors and use those without
issue. You may want to remember the Connection object when you set
your trace or user defined functions.</p>
</div>
<div class="section" id="bit-hosts-python-2-5">
<span id="x64bitpy25"></span><h2>64 bit hosts, Python 2.5+<a class="headerlink" href="#bit-hosts-python-2-5" title="Permalink to this headline">¶</a></h2>
<p>Prior to Python 2.5, you were limited to 32 bit quantities for items
in Python such as the length of strings, number of items in a sequence
etc. Python 2.5 and above use 64 bit limits on 64 bit hosts. APSW
will work correctly with those items in Python 2.5 and above that use
64 bits. Unfortunately SQLite is limited to 32 bit quantities for
strings, blobs, number of columns etc even when compiled for 64
bit. Consequently you will get a TooBig exception from APSW which
checks if strings/buffers longer than 1GB or 2GB (depends on internal
storage) are used. See <a class="reference external" href="https://sqlite.org/cvstrac/tktview?tn=2125">SQLite ticket #2125</a> and <a class="reference external" href="https://sqlite.org/cvstrac/tktview?tn=3246">SQLite ticket #3246</a> for
more details.</p>
</div>
<div class="section" id="statement-cache">
<span id="statementcache"></span><h2>Statement Cache<a class="headerlink" href="#statement-cache" title="Permalink to this headline">¶</a></h2>
<p>Each <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> maintains a cache mapping SQL queries to a
<a class="reference external" href="https://sqlite.org/c3ref/stmt.html">prepared statement</a> to avoid
the overhead of <a class="reference external" href="https://sqlite.org/c3ref/prepare.html">repreparing</a> queries that are executed
multiple times. This is a classic tradeoff using more memory to
reduce CPU consumption.</p>
<p>By default there are up to 100 entries in the cache. Once the cache
is full, the least recently used item is discarded to make space for
new items.</p>
<p>You should pick a larger cache size if you have more than 100 unique
queries that you run. For example if you have 101 different queries
you run in order then the cache will not help.</p>
<p>You can also <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><tt class="xref py py-class docutils literal"><span class="pre">specify</span> <span class="pre">zero</span></tt></a> which will disable the
statement cache.</p>
<p>If you are using <a class="reference internal" href="connection.html#apsw.Connection.setauthorizer" title="apsw.Connection.setauthorizer"><tt class="xref py py-meth docutils literal"><span class="pre">authorizers</span></tt></a> then
you should disable the statement cache. This is because the
authorizer callback is only called while statements are being
prepared.</p>
</div>
<div class="section" id="tracing">
<span id="id1"></span><h2>Tracing<a class="headerlink" href="#tracing" title="Permalink to this headline">¶</a></h2>
<p>You can install tracers on <a class="reference internal" href="cursor.html#apsw.Cursor" title="apsw.Cursor"><tt class="xref py py-class docutils literal"><span class="pre">cursors</span></tt></a> or
<a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><tt class="xref py py-class docutils literal"><span class="pre">connections</span></tt></a> as an easy way of seeing exactly
what gets executed and what is returned. The tracers can also abort
execution and cause different values to be returned. This is very
useful for diagnostics and testing without having to modify your main
code.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>You cannot issue new execute statements against the cursor
your tracer was called from. If you would like to make more queries
in the tracer then do them from a new cursor object. For example:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">exectracer</span><span class="p">(</span><span class="n">cursor</span><span class="p">,</span> <span class="n">sql</span><span class="p">,</span> <span class="n">bindings</span><span class="p">):</span>
<span class="n">cursor</span><span class="o">.</span><span class="n">getconnection</span><span class="p">()</span><span class="o">.</span><span class="n">cursor</span><span class="p">(</span><span class="s">"insert into log values(?,?)"</span><span class="p">,</span> <span class="p">(</span><span class="n">sql</span><span class="p">,</span><span class="nb">str</span><span class="p">(</span><span class="n">bindings</span><span class="p">)))</span>
<span class="k">return</span> <span class="bp">True</span>
</pre></div>
</div>
</div>
<div class="section" id="execution-tracer">
<span id="executiontracer"></span><h3>Execution Tracer<a class="headerlink" href="#execution-tracer" title="Permalink to this headline">¶</a></h3>
<p>The execution tracer is called after an SQL statement has been
prepared. (ie syntax errors will have caused an exception during
preparation so you won’t see them with a tracer). It is called with
three arguments.</p>
<blockquote>
<div><dl class="docutils">
<dt>cursor</dt>
<dd>The cursor executing the statement</dd>
<dt>sql</dt>
<dd>The SQL text being executed</dd>
<dt>bindings</dt>
<dd>The bindings being used. This may be <tt class="xref py py-const docutils literal"><span class="pre">None</span></tt>, a dictionary or
a tuple.</dd>
</dl>
</div></blockquote>
<p>If the tracer return value evaluates to False/None then execution is
aborted with an <a class="reference internal" href="exceptions.html#apsw.ExecTraceAbort" title="apsw.ExecTraceAbort"><tt class="xref py py-exc docutils literal"><span class="pre">ExecTraceAbort</span></tt></a> exception. See the
<a class="reference internal" href="example.html#example-exectrace"><em>example</em></a>.</p>
<p>Execution tracers can be installed on a specific cursor by calling
<a class="reference internal" href="cursor.html#apsw.Cursor.setexectrace" title="apsw.Cursor.setexectrace"><tt class="xref py py-meth docutils literal"><span class="pre">Cursor.setexectrace()</span></tt></a> or for all cursors by calling
<a class="reference internal" href="connection.html#apsw.Connection.setexectrace" title="apsw.Connection.setexectrace"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.setexectrace()</span></tt></a>, with the cursor tracer taking
priority.</p>
<p>If you use the Connection <a class="reference internal" href="connection.html#apsw.Connection.__enter__" title="apsw.Connection.__enter__"><tt class="xref py py-meth docutils literal"><span class="pre">with</span></tt></a> statement
and have a Connection execution tracer then your callback will also be
called when APSW creates and releases/rollbacks savepoints. Instead
of the first argument being a cursor, it will be the connection itself
since there is no cursor involved.</p>
</div>
<div class="section" id="row-tracer">
<span id="rowtracer"></span><h3>Row Tracer<a class="headerlink" href="#row-tracer" title="Permalink to this headline">¶</a></h3>
<p>The row tracer is called before each row is returned. It is called with
two arguments.</p>
<blockquote>
<div><dl class="docutils">
<dt>cursor</dt>
<dd>The cursor returning the row</dd>
<dt>row</dt>
<dd>A tuple of the values about to be returned</dd>
</dl>
</div></blockquote>
<p>Whatever you return from the tracer is what is actually returned to
the caller of <a class="reference internal" href="cursor.html#apsw.Cursor.execute" title="apsw.Cursor.execute"><tt class="xref py py-meth docutils literal"><span class="pre">execute()</span></tt></a>. If you return None then the
whole row is skipped. See the <a class="reference internal" href="example.html#example-rowtrace"><em>example</em></a>.</p>
<p>Row tracers can be installed on a specific cursor by calling
<a class="reference internal" href="cursor.html#apsw.Cursor.setrowtrace" title="apsw.Cursor.setrowtrace"><tt class="xref py py-meth docutils literal"><span class="pre">Cursor.setrowtrace()</span></tt></a> or for all cursors by calling
<a class="reference internal" href="connection.html#apsw.Connection.setrowtrace" title="apsw.Connection.setrowtrace"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.setrowtrace()</span></tt></a>, with the cursor tracer taking
priority.</p>
</div>
</div>
<div class="section" id="apsw-trace">
<span id="apswtrace"></span><h2>APSW Trace<a class="headerlink" href="#apsw-trace" title="Permalink to this headline">¶</a></h2>
<p>APSW includes a tracing script as part of the <a class="reference internal" href="download.html#source-and-binaries"><em>source
distribution</em></a> named <tt class="file docutils literal"><span class="pre">apswtrace.py</span></tt>, or you
can get a copy directly from <a class="reference external" href="https://code.google.com/p/apsw/source/browse/tools/apswtrace.py">source control</a>
(choose “View Raw File”). This script lets you easily trace SQL
execution as well as providing a summary report without modifying your
code. If it is installed anywhere on your <span class="target" id="index-0"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PYTHONPATH</span></tt> then
you can invoke it with <tt class="docutils literal"><span class="pre">-m</span></tt>:</p>
<div class="highlight-python"><pre>$ python -m apswtrace [apswtrace options] yourscript.py [your options]</pre>
</div>
<p>You can also invoke it directly:</p>
<div class="highlight-python"><pre>$ python /path/to/apswtrace.py [apswtrace options] yourscript.py [your options]</pre>
</div>
<p>All output is UTF-8 encoded. The following options are available:</p>
<div class="highlight-text"><div class="highlight"><pre>$ python apswtrace.py --help
Usage: apswtrace.py [options] pythonscript.py [pythonscriptoptions]
This script runs a Python program that uses APSW and reports on SQL queries
without modifying the program. This is done by using connection_hooks and
registering row and execution tracers. See APSW documentation for more
details on the output.
Options:
-h, --help show this help message and exit
-o OUTPUT, --output=OUTPUT
Where to send the output. Use a filename, a single
dash for stdout, or the words stdout and stderr.
[stdout]
-s, --sql Log SQL statements as they are executed. [False]
-r, --rows Log returned rows as they are returned (turns on sql).
[False]
-t, --timestamps Include timestamps in logging
-i, --thread Include thread id in logging
-l LENGTH, --length=LENGTH
Max amount of a string to print [30]
--no-report A summary report is normally generated at program
exit. This turns off the report and saves memory.
--report-items=N How many items to report in top lists [15]
--reports=REPORTS Which reports to show
[summary,popular,aggregate,individual]
</pre></div>
</div>
<p>This is sample output with the following options: <em class="xref std std-option">--sql</em>,
<em class="xref std std-option">--rows</em>, <em class="xref std std-option">--timestamps</em>, <em class="xref std std-option">--thread</em></p>
<div class="highlight-text"><div class="highlight"><pre>1e0e5a0 0.152 7fccea8456e0 OPEN: ":memory:" unix READWRITE|CREATE
1f72ac0 0.161 7fccea8456e0 OPEN: "testdb" unix READWRITE|CREATE
1f6b8d0 0.162 7fccea8456e0 CURSORFROM: 1f72ac0 DB: "testdb"
1f6b8d0 0.162 7fccea8456e0 SQL: create table foo(x,y,z)
1f6b8d0 0.239 7fccea8456e0 CURSORFROM: 1f72ac0 DB: "testdb"
1f6b8d0 0.239 7fccea8456e0 SQL: insert into foo values(?,?,?) BINDINGS: ("kjfhgk", "gkjlfdhgjkhsdfkjg", "gklsdfjgkldfjhnbnvc,mnxb,mnxcv..")
1f6b8d0 0.242 7fccea8456e0 CURSORFROM: 1f72ac0 DB: "testdb"
1f6b8d0 0.242 7fccea8456e0 SQL: insert into foo values(?,?,?) BINDINGS: ("gdfklhj", ":gjkhgfdsgfd", "gjkfhgjkhdfkjh")
1f6b8d0 0.244 7fccea8456e0 CURSORFROM: 1f72ac0 DB: "testdb"
1f6b8d0 0.245 7fccea8456e0 SQL: insert into foo values(?,?,?) BINDINGS: ("gdfjkhg", "gkjlfd", "")
1f6b8d0 0.247 7fccea8456e0 CURSORFROM: 1f72ac0 DB: "testdb"
1f6b8d0 0.247 7fccea8456e0 SQL: insert into foo values(?,?,?) BINDINGS: (1, 2, 30)
1f6b8d0 0.257 7fccea8456e0 CURSORFROM: 1f72ac0 DB: "testdb"
1f6b8d0 0.257 7fccea8456e0 SQL: select longest(x,y,z) from foo
1f6b8d0 0.257 7fccea8456e0 ROW: ("gklsdfjgkldfjhnbnvc,mnxb,mnxcv..")
</pre></div>
</div>
<p>Each row starts with the following fields:</p>
<blockquote>
<div><dl class="docutils">
<dt>id</dt>
<dd>This is the <a class="reference external" href="http://docs.python.org/library/functions.html#id">id</a> of the
<a class="reference internal" href="cursor.html#apsw.Cursor" title="apsw.Cursor"><tt class="xref py py-class docutils literal"><span class="pre">Cursor</span></tt></a> or <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>. You can easily <a class="reference external" href="http://en.wikipedia.org/wiki/Grep">filter</a> the log if you just want to
find out what happened on a specific cursor or connection.</dd>
<dt>timestamp</dt>
<dd>This is time since the program started in seconds</dd>
<dt>threadid</dt>
<dd>The unique <a class="reference external" href="http://docs.python.org/library/thread.html#thread.get_ident">thread identifier</a></dd>
</dl>
</div></blockquote>
<p>The remainder of the line has one of the following forms:</p>
<blockquote>
<div><dl class="docutils">
<dt>OPEN: “dbname” vfs open_flags</dt>
<dd>A <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> has been opened. The <em>dbname</em> is the
filename exactly as given in the call to
<a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>. <em>vfs</em> is the name of the <a class="reference internal" href="vfs.html#vfs"><em>VFS</em></a>
used to open the database. <em>open_flags</em> is the set of <a class="reference internal" href="apsw.html#apsw.mapping_open_flags" title="apsw.mapping_open_flags"><tt class="xref py py-data docutils literal"><span class="pre">flags</span></tt></a> supplied with the leading <em>SQLITE_OPEN</em>
prefix omitted.</dd>
<dt>CURSORFROM: connectionid DB: “dbname”</dt>
<dd>A cursor has been allocated. The <em>id</em> at the begining of this row
is of the new cursor. <em>connectionid</em> is the id of the Connection
it was created from. The <em>dbname</em> is provided for convenience.
This message is logged the first time a cursor issues a query.</dd>
<dt>SQL: query BINDINGS: bindings</dt>
<dd>A query was issued on a cursor.</dd>
<dt>ROW: row</dt>
<dd>A result row was returned by a cursor.</dd>
</dl>
</div></blockquote>
<p>A report is also generated by default. This is example output from
running the test suite. When calculating time for queries, your code
execution time is included as well. For example if your query
returned 10 rows and you slept for 1 second on reading each row then
the time for the query will be recorded as 10 seconds. Because you
can have multiple queries active at the same time, as well as across
multiple threads, the total processing time can be larger than the
program run time. The processing time is only recorded for queries
that have no results or where you read all the result rows.
Processing time also includes waiting time on busy connections.</p>
<blockquote>
<div><div class="highlight-text"><div class="highlight"><pre>APSW TRACE SUMMARY REPORT
Program run time 83.073 seconds
Total connections 1308
Total cursors 3082
Number of threads used for queries 21
Total queries 127973
Number of distinct queries 578
Number of rows returned 2369
Time spent processing queries 120.530 seconds
</pre></div>
</div>
</div></blockquote>
<p>This shows how many times each query was run.</p>
<blockquote>
<div><div class="highlight-text"><div class="highlight"><pre>MOST POPULAR QUERIES
121451 insert into foo values(?)
1220 insert into abc values(1,2,?)
1118 select x from foo
909 select timesten(x) from foo where x=? order by x
654 select * from foo
426 update t1 set b=b||a||b
146 begin
88 create table foo(x,y)
79 insert into foo values(1,2)
76 rollback
71 pragma locking_mode=exclusive
71 insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz')
71 insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz')
71 insert into t1 select 4-a, b from t2
71 insert into foo values(date('now'), date('now'))
</pre></div>
</div>
</div></blockquote>
<p>This shows how many times a query was run and the sum of the
processing times in seconds. The <tt class="docutils literal"><span class="pre">begin</span> <span class="pre">immediate</span></tt> query
illustrates how time spent busy waiting is included.</p>
<blockquote>
<div><div class="highlight-text"><div class="highlight"><pre>LONGEST RUNNING - AGGREGATE
413 94.305 select timesten(x) from foo where x=? order by x
120637 12.941 select * from foo
12 4.115 begin immediate
121449 2.179 insert into foo values(?)
1220 1.509 insert into abc values(1,2,?)
3 1.380 create index foo_x on foo(x)
426 0.715 update t1 set b=b||a||b
38 0.420 insert into foo values(?,?)
71 0.241 create table t1(a unique, b)
88 0.206 create table foo(x,y)
61 0.170 create table abc(a,b,c)
27 0.165 insert into foo values(?,?,?)
1 0.158 select row,x,snap(x) from foo
80 0.150 insert into foo values(1,2)
71 0.127 insert into foo values(date('now'), date('now'))
</pre></div>
</div>
</div></blockquote>
<p>This shows the longest running queries with time in seconds.</p>
<blockquote>
<div><div class="highlight-text"><div class="highlight"><pre>LONGEST RUNNING - INDIVIDUAL
3.001 begin immediate
1.377 create index foo_x on foo(x)
1.102 begin immediate
0.944 select timesten(x) from foo where x=? order by x
0.893 select timesten(x) from foo where x=? order by x
0.817 select timesten(x) from foo where x=? order by x
0.816 select timesten(x) from foo where x=? order by x
0.786 select timesten(x) from foo where x=? order by x
0.783 select timesten(x) from foo where x=? order by x
0.713 select timesten(x) from foo where x=? order by x
0.701 select timesten(x) from foo where x=? order by x
0.651 select timesten(x) from foo where x=? order by x
0.646 select timesten(x) from foo where x=? order by x
0.631 select timesten(x) from foo where x=? order by x
0.620 select timesten(x) from foo where x=? order by x
</pre></div>
</div>
</div></blockquote>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Execution and tracing</a><ul>
<li><a class="reference internal" href="#execution-model">Execution model</a></li>
<li><a class="reference internal" href="#multi-threading-and-re-entrancy">Multi-threading and re-entrancy</a></li>
<li><a class="reference internal" href="#bit-hosts-python-2-5">64 bit hosts, Python 2.5+</a></li>
<li><a class="reference internal" href="#statement-cache">Statement Cache</a></li>
<li><a class="reference internal" href="#tracing">Tracing</a><ul>
<li><a class="reference internal" href="#execution-tracer">Execution Tracer</a></li>
<li><a class="reference internal" href="#row-tracer">Row Tracer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#apsw-trace">APSW Trace</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="types.html"
title="previous chapter">Types</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="dbapi.html"
title="next chapter">DBAPI notes</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/execution.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="dbapi.html" title="DBAPI notes"
>next</a> |</li>
<li class="right" >
<a href="types.html" title="Types"
>previous</a> |</li>
<li><a href="index.html">APSW 3.8.2-r1 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© <a href="copyright.html">Copyright</a> 2004-2013, Roger Binns <rogerb@rogerbinns.com>.
Last updated on Dec 08, 2013.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
</div>
</body>
</html>
|