/usr/share/doc/python-apsw/html/vfs.html is in python-apsw-doc 3.16.2-r1-2build2.
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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | <!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>Virtual File System (VFS) — APSW 3.16.2-r1 documentation</title>
<link rel="stylesheet" href="_static/classic.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.16.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="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="copyright" title="Copyright" href="copyright.html" />
<link rel="top" title="APSW 3.16.2-r1 documentation" href="index.html" />
<link rel="next" title="Shell" href="shell.html" />
<link rel="prev" title="Virtual Tables" href="vtable.html" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26815066-1']);
_gaq.push(['_trackPageview']);
</script>
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<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="shell.html" title="Shell"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="vtable.html" title="Virtual Tables"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">APSW 3.16.2-r1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="virtual-file-system-vfs">
<span id="vfs"></span><h1>Virtual File System (VFS)<a class="headerlink" href="#virtual-file-system-vfs" title="Permalink to this headline">¶</a></h1>
<p>SQLite 3.6 has new <a class="reference external" href="https://sqlite.org/c3ref/vfs.html">VFS functionality</a> which defines the interface
between the SQLite core and the underlying operating system. The
majority of the functionality deals with files. APSW exposes this
functionality letting you provide your own routines. You can also
<em>inherit</em> from an existing vfs making it easy to augment or override
specific routines. For example you could obfuscate your database by
XORing the data implemented by augmenting the read and write
methods. The method names are exactly the same as SQLite uses making
it easier to read the SQLite documentation, trouble tickets, web
searches or mailing lists. The SQLite convention results in names like
xAccess, xCurrentTime and xWrite.</p>
<p>You specify which VFS to use as a parameter to the <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a>
constructor.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">=</span><span class="n">apsw</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span><span class="s">"file"</span><span class="p">,</span> <span class="n">vfs</span><span class="o">=</span><span class="s">"myvfs"</span><span class="p">)</span>
</pre></div>
</div>
<p>The easiest way to get started is to make a <a class="reference internal" href="#apsw.VFS" title="apsw.VFS"><code class="xref py py-class docutils literal"><span class="pre">VFS</span></code></a> derived class
that inherits from the default vfs. Then override methods you want to
change behaviour of. If you want to just change how file operations
are done then you have to override <a class="reference internal" href="#apsw.VFS.xOpen" title="apsw.VFS.xOpen"><code class="xref py py-meth docutils literal"><span class="pre">VFS.xOpen()</span></code></a> to return a file
instance that has your overridden <a class="reference internal" href="#apsw.VFSFile" title="apsw.VFSFile"><code class="xref py py-class docutils literal"><span class="pre">VFSFile</span></code></a> methods. The
<a class="reference internal" href="example.html#example-vfs"><span class="std std-ref">example</span></a> demonstrates obfuscating the database
file contents.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All strings supplied and returned to <a class="reference internal" href="#apsw.VFS" title="apsw.VFS"><code class="xref py py-class docutils literal"><span class="pre">VFS</span></code></a>/<a class="reference internal" href="#apsw.VFSFile" title="apsw.VFSFile"><code class="xref py py-class docutils literal"><span class="pre">VFSFile</span></code></a>
routines are treated as Unicode.</p>
</div>
<div class="section" id="exceptions-and-errors">
<h2>Exceptions and errors<a class="headerlink" href="#exceptions-and-errors" title="Permalink to this headline">¶</a></h2>
<p>To return an error from any routine you should raise an exception. The
exception will be translated into the appropriate SQLite error code
for SQLite. To return a specific SQLite error code use
<a class="reference internal" href="apsw.html#apsw.exceptionfor" title="apsw.exceptionfor"><code class="xref py py-meth docutils literal"><span class="pre">exceptionfor()</span></code></a>. If the exception does not map to any specific
error code then <code class="xref py py-const docutils literal"><span class="pre">SQLITE_ERROR</span></code> which corresponds to
<a class="reference internal" href="exceptions.html#apsw.SQLError" title="apsw.SQLError"><code class="xref py py-exc docutils literal"><span class="pre">SQLError</span></code></a> is returned to SQLite.</p>
<p>The SQLite code that deals with VFS errors behaves in varying
ways. Some routines have no way to return an error (eg <a class="reference external" href="https://sqlite.org/c3ref/vfs.html">xDlOpen</a> just returns zero/NULL on
being unable to load a library, <a class="reference external" href="https://sqlite.org/c3ref/vfs.html">xSleep</a> has no error return
parameter), others are unified (eg almost any
error in xWrite will be returned to the user as disk full
error). Sometimes errors are ignored as they are harmless such as when
a journal can’t be deleted after a commit (the journal is marked as
obsolete before being deleted). Simple operations such as opening a
database can result in many different VFS function calls such as hot
journals being detected, locking, and read/writes for
playback/rollback.</p>
<p>To avoid confusion with exceptions being raised in the VFS and
exceptions from normal code to open Connections or execute SQL
queries, VFS exceptions are not raised in the normal way. (If they
were, only one could be raised and it would obscure whatever
exceptions the <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><code class="xref py py-class docutils literal"><span class="pre">Connection</span></code></a> open or SQL query execute wanted to
raise.) Instead the <a class="reference internal" href="#apsw.VFS.excepthook" title="apsw.VFS.excepthook"><code class="xref py py-meth docutils literal"><span class="pre">VFS.excepthook()</span></code></a> or
<a class="reference internal" href="#apsw.VFSFile.excepthook" title="apsw.VFSFile.excepthook"><code class="xref py py-meth docutils literal"><span class="pre">VFSFile.excepthook()</span></code></a> method is called with a tuple of exception
type, exception value and exception traceback. The default
implementation of <code class="docutils literal"><span class="pre">excepthook</span></code> calls <code class="docutils literal"><span class="pre">sys.excepthook()</span></code> which
under Python 2 shows the stack trace and under Python 3 merely prints
the exception value. (If <code class="docutils literal"><span class="pre">sys.excepthook</span></code> fails then
<code class="docutils literal"><span class="pre">PyErr_Display()</span></code> is called.)</p>
<p>In normal VFS usage there will be no exceptions raised, or specific
expected ones which APSW clears after noting them and returning the
appropriate value back to SQLite. The exception hooking behaviour
helps you find issues in your code or unexpected behaviour of the
external environment. Remember that <a class="reference internal" href="exceptions.html#augmentedstacktraces"><span class="std std-ref">augmented stack traces</span></a> are available which significantly increase
detail about the exceptions.</p>
<p>As an example, lets say you have a divide by zero error in your xWrite
routine. The table below shows what happens with time going down and
across.</p>
<table border="1" class="docutils">
<colgroup>
<col width="37%" />
<col width="26%" />
<col width="37%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Python Query Code</th>
<th class="head">SQLite and APSW C code</th>
<th class="head">Python VFS code</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal"><span class="pre">cursor.execute("update</span> <span class="pre">table</span> <span class="pre">set</span> <span class="pre">foo=3")</span></code></td>
<td> </td>
<td> </td>
</tr>
<tr class="row-odd"><td> </td>
<td>SQLite starts executing query</td>
<td> </td>
</tr>
<tr class="row-even"><td> </td>
<td> </td>
<td>Your VFS routines are called</td>
</tr>
<tr class="row-odd"><td> </td>
<td> </td>
<td>Your xWrite divides by zero</td>
</tr>
<tr class="row-even"><td> </td>
<td> </td>
<td><a class="reference internal" href="#apsw.VFSFile.excepthook" title="apsw.VFSFile.excepthook"><code class="xref py py-meth docutils literal"><span class="pre">VFSFile.excepthook()</span></code></a> is called with
ZeroDivision exception</td>
</tr>
<tr class="row-odd"><td> </td>
<td><code class="xref py py-const docutils literal"><span class="pre">SQLITE_ERROR</span></code> (closest
matching SQLite error code) is
returned to SQLite by APSW</td>
<td> </td>
</tr>
<tr class="row-even"><td> </td>
<td>SQLite error handling and
recovery operates which calls
more VFS routines.</td>
<td>More VFS routines are called. Any
exceptions in these routines will result in
<a class="reference internal" href="#apsw.VFSFile.excepthook" title="apsw.VFSFile.excepthook"><code class="xref py py-meth docutils literal"><span class="pre">VFSFile.excepthook()</span></code></a> being called with
them.</td>
</tr>
<tr class="row-odd"><td> </td>
<td>SQLite returns
<code class="xref py py-const docutils literal"><span class="pre">SQLITE_FULL</span></code> to APSW</td>
<td> </td>
</tr>
<tr class="row-even"><td>APSW returns <a class="reference internal" href="exceptions.html#apsw.FullError" title="apsw.FullError"><code class="xref py py-class docutils literal"><span class="pre">apsw.FullError</span></code></a></td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="vfs-class">
<h2>VFS class<a class="headerlink" href="#vfs-class" title="Permalink to this headline">¶</a></h2>
<span class="target" id="index-0"></span><dl class="class">
<dt id="apsw.VFS">
<em class="property">class </em><code class="descname">VFS</code><span class="sig-paren">(</span><em>name</em><span class="optional">[</span>, <em>base=None</em>, <em>makedefault=False</em>, <em>maxpathname=1024</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFS" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides operating system access. You can get an overview in the
<a class="reference external" href="https://sqlite.org/c3ref/vfs.html">SQLite documentation</a>. To
create a VFS your Python class must inherit from <a class="reference internal" href="#apsw.VFS" title="apsw.VFS"><code class="xref py py-class docutils literal"><span class="pre">VFS</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – The name to register this vfs under. If the name
already exists then this vfs will replace the prior one of the
same name. Use <a class="reference internal" href="apsw.html#apsw.vfsnames" title="apsw.vfsnames"><code class="xref py py-meth docutils literal"><span class="pre">apsw.vfsnames()</span></code></a> to get a list of
registered vfs names. :param base: If you would like to
inherit behaviour from an already registered vfs then give
their name. To inherit from the default vfs, use a zero
length string <code class="docutils literal"><span class="pre">""</span></code> as the name. :param makedefault: If true
then this vfs will be registered as the default, and will be
used by any opens that don’t specify a vfs. :param
maxpathname: The maximum length of database name in bytes when
represented in UTF-8. If a pathname is passed in longer than
this value then SQLite will not <a class="reference external" href="https://sqlite.org/src/tktview/c060923a5422590b3734eb92eae0c94934895b68">be able to open it</a>.</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><strong>ValueError</strong> – If <em>base</em> is not <code class="xref py py-const docutils literal"><span class="pre">None</span></code> and the named vfs is not
currently registered.</td>
</tr>
</tbody>
</table>
<dl class="docutils">
<dt>Calls:</dt>
<dd><ul class="first last simple">
<li><a class="reference external" href="https://sqlite.org/c3ref/vfs_find.html">sqlite3_vfs_register</a></li>
<li><a class="reference external" href="https://sqlite.org/c3ref/vfs_find.html">sqlite3_vfs_find</a></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.excepthook">
<code class="descclassname">VFS.</code><code class="descname">excepthook</code><span class="sig-paren">(</span><em>etype</em>, <em>evalue</em>, <em>etraceback</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFS.excepthook" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when there has been an exception in a <a class="reference internal" href="#apsw.VFS" title="apsw.VFS"><code class="xref py py-class docutils literal"><span class="pre">VFS</span></code></a> routine.
The default implementation calls <code class="docutils literal"><span class="pre">sys.excepthook</span></code> and if that
fails then <code class="docutils literal"><span class="pre">PyErr_Display</span></code>. The three arguments correspond to
what <code class="docutils literal"><span class="pre">sys.exc_info()</span></code> would return.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>etype</strong> – The exception type</li>
<li><strong>evalue</strong> – The exception value</li>
<li><strong>etraceback</strong> – The exception traceback. Note this
includes all frames all the way up to the thread being started.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<span class="target" id="index-1"></span><dl class="method">
<dt id="apsw.VFS.unregister">
<code class="descclassname">VFS.</code><code class="descname">unregister</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFS.unregister" title="Permalink to this definition">¶</a></dt>
<dd><p>Unregisters the VFS making it unavailable to future database
opens. You do not need to call this as the VFS is automatically
unregistered by when the VFS has no more references or open
datatabases using it. It is however useful to call if you have made
your VFS be the default and wish to immediately make it be
unavailable. It is safe to call this routine multiple times.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vfs_find.html">sqlite3_vfs_unregister</a></p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xAccess">
<code class="descclassname">VFS.</code><code class="descname">xAccess</code><span class="sig-paren">(</span><em>pathname</em>, <em>flags</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#apsw.VFS.xAccess" title="Permalink to this definition">¶</a></dt>
<dd><p>SQLite wants to check access permissions. Return True or False
accordingly.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>pathname</strong> – File or directory to check</li>
<li><strong>flags</strong> – One of the <a class="reference external" href="https://sqlite.org/c3ref/c_access_exists.html">access flags</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xCurrentTime">
<code class="descclassname">VFS.</code><code class="descname">xCurrentTime</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → float<a class="headerlink" href="#apsw.VFS.xCurrentTime" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <a class="reference external" href="http://en.wikipedia.org/wiki/Julian_day">Julian Day Number</a> as a floating point
number where the integer portion is the day and the fractional part
is the time. Do not adjust for timezone (ie use <a class="reference external" href="http://en.wikipedia.org/wiki/Universal_Time">UTC</a>).</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xDelete">
<code class="descclassname">VFS.</code><code class="descname">xDelete</code><span class="sig-paren">(</span><em>filename</em>, <em>syncdir</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFS.xDelete" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete the named file.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>SQLite has 3 different behaviours depending on version for how to handle missing files.</p>
<table border="1" class="last docutils">
<colgroup>
<col width="45%" />
<col width="55%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>SQLite < 3.7.8</td>
<td>Raise an <a class="reference internal" href="exceptions.html#apsw.IOError" title="apsw.IOError"><code class="xref py py-exc docutils literal"><span class="pre">IOError</span></code></a> if the file does not
exist.</td>
</tr>
<tr class="row-even"><td>SQLite >= 3.7.8 and SQLite < 3.7.15</td>
<td>Do not raise an exception</td>
</tr>
<tr class="row-odd"><td>SQLite >= 3.7.15</td>
<td>Raise an <a class="reference internal" href="exceptions.html#apsw.IOError" title="apsw.IOError"><code class="xref py py-exc docutils literal"><span class="pre">IOError</span></code></a> exception with
extendedresult <code class="xref py py-const docutils literal"><span class="pre">SQLITE_IOERR_DELETE_NOENT</span></code></td>
</tr>
</tbody>
</table>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>filename</strong> – File to delete</li>
<li><strong>syncdir</strong> – If True then the directory should be synced
ensuring that the file deletion has been recorded on the disk
platters. ie if there was an immediate power failure after this
call returns, on a reboot the file would still be deleted.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xDlClose">
<code class="descclassname">VFS.</code><code class="descname">xDlClose</code><span class="sig-paren">(</span><em>handle</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFS.xDlClose" title="Permalink to this definition">¶</a></dt>
<dd><p>Close and unload the library corresponding to the handle you
returned from <a class="reference internal" href="#apsw.VFS.xDlOpen" title="apsw.VFS.xDlOpen"><code class="xref py py-meth docutils literal"><span class="pre">xDlOpen()</span></code></a>. You can use ctypes to do
this:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="k">def</span> <span class="nf">xDlClose</span><span class="p">(</span><span class="n">handle</span><span class="p">):</span>
<span class="c"># Note leading underscore in _ctypes</span>
<span class="n">_ctypes</span><span class="o">.</span><span class="n">dlclose</span><span class="p">(</span><span class="n">handle</span><span class="p">)</span> <span class="c"># Linux/Mac/Unix</span>
<span class="n">_ctypes</span><span class="o">.</span><span class="n">FreeLibrary</span><span class="p">(</span><span class="n">handle</span><span class="p">)</span> <span class="c"># Windows</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xDlError">
<code class="descclassname">VFS.</code><code class="descname">xDlError</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → string<a class="headerlink" href="#apsw.VFS.xDlError" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an error string describing the last error of
<a class="reference internal" href="#apsw.VFS.xDlOpen" title="apsw.VFS.xDlOpen"><code class="xref py py-meth docutils literal"><span class="pre">xDlOpen()</span></code></a> or <a class="reference internal" href="#apsw.VFS.xDlSym" title="apsw.VFS.xDlSym"><code class="xref py py-meth docutils literal"><span class="pre">xDlSym()</span></code></a> (ie they returned
zero/NULL). If you do not supply this routine then SQLite provides
a generic message. To implement this method, catch exceptions in
<a class="reference internal" href="#apsw.VFS.xDlOpen" title="apsw.VFS.xDlOpen"><code class="xref py py-meth docutils literal"><span class="pre">xDlOpen()</span></code></a> or <a class="reference internal" href="#apsw.VFS.xDlSym" title="apsw.VFS.xDlSym"><code class="xref py py-meth docutils literal"><span class="pre">xDlSym()</span></code></a>, turn them into
strings, save them, and return them in this routine. If you have
an error in this routine or return None then SQLite’s generic
message will be used.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xDlOpen">
<code class="descclassname">VFS.</code><code class="descname">xDlOpen</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span> → number<a class="headerlink" href="#apsw.VFS.xDlOpen" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the shared library. You should return a number which will be
treated as a void pointer at the C level. On error you should
return 0 (NULL). The number is passed as is to
<a class="reference internal" href="#apsw.VFS.xDlSym" title="apsw.VFS.xDlSym"><code class="xref py py-meth docutils literal"><span class="pre">xDlSym()</span></code></a>/<a class="reference internal" href="#apsw.VFS.xDlClose" title="apsw.VFS.xDlClose"><code class="xref py py-meth docutils literal"><span class="pre">xDlClose()</span></code></a> so it can represent
anything that is convenient for you (eg an index into an
array). You can use ctypes to load a library:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="k">def</span> <span class="nf">xDlOpen</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="k">return</span> <span class="n">ctypes</span><span class="o">.</span><span class="n">cdll</span><span class="o">.</span><span class="n">LoadLibrary</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">_handle</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xDlSym">
<code class="descclassname">VFS.</code><code class="descname">xDlSym</code><span class="sig-paren">(</span><em>handle</em>, <em>symbol</em><span class="sig-paren">)</span> → address<a class="headerlink" href="#apsw.VFS.xDlSym" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the address of the named symbol which will be called by
SQLite. On error you should return 0 (NULL). You can use ctypes:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="k">def</span> <span class="nf">xDlSym</span><span class="p">(</span><span class="n">ptr</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
<span class="k">return</span> <span class="n">_ctypes</span><span class="o">.</span><span class="n">dlsym</span> <span class="p">(</span><span class="n">ptr</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="c"># Linux/Unix/Mac etc (note leading underscore)</span>
<span class="k">return</span> <span class="n">ctypes</span><span class="o">.</span><span class="n">win32</span><span class="o">.</span><span class="n">kernel32</span><span class="o">.</span><span class="n">GetProcAddress</span> <span class="p">(</span><span class="n">ptr</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="c"># Windows</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>handle</strong> – The value returned from an earlier <a class="reference internal" href="#apsw.VFS.xDlOpen" title="apsw.VFS.xDlOpen"><code class="xref py py-meth docutils literal"><span class="pre">xDlOpen()</span></code></a> call</li>
<li><strong>symbol</strong> – A string</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">An int/long with the symbol address</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xFullPathname">
<code class="descclassname">VFS.</code><code class="descname">xFullPathname</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span> → string<a class="headerlink" href="#apsw.VFS.xFullPathname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the absolute pathname for name. You can use <code class="docutils literal"><span class="pre">os.path.abspath</span></code> to do this.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xGetLastError">
<code class="descclassname">VFS.</code><code class="descname">xGetLastError</code><span class="sig-paren">(</span><em>) -> (int</em>, <em>string or None</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFS.xGetLastError" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is to return an integer error code and (optional) text describing
the last error that happened in this thread.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">SQLite 3.12 changed the semantics in an incompatible way from
earlier versions. You will need to rewrite earlier implementations.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xGetSystemCall">
<code class="descclassname">VFS.</code><code class="descname">xGetSystemCall</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span> → int<a class="headerlink" href="#apsw.VFS.xGetSystemCall" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a pointer for the current method implementing the named
system call. Return None if the call does not exist.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xNextSystemCall">
<code class="descclassname">VFS.</code><code class="descname">xNextSystemCall</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span> → String or None<a class="headerlink" href="#apsw.VFS.xNextSystemCall" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is repeatedly called to iterate over all of the system
calls in the vfs. When called with None you should return the
name of the first system call. In subsequent calls return the
name after the one passed in. If name is the last system call
then return None.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Because of internal SQLite implementation semantics memory will
be leaked on each call to this function. Consequently you
should build up the list of call names once rather than
repeatedly doing it.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xOpen">
<code class="descclassname">VFS.</code><code class="descname">xOpen</code><span class="sig-paren">(</span><em>name</em>, <em>flags</em><span class="sig-paren">)</span> → VFSFile or similar object<a class="headerlink" href="#apsw.VFS.xOpen" title="Permalink to this definition">¶</a></dt>
<dd><p>This method should return a new file object based on name. You
can return a <a class="reference internal" href="#apsw.VFSFile" title="apsw.VFSFile"><code class="xref py py-class docutils literal"><span class="pre">VFSFile</span></code></a> from a completely different VFS.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> – File to open. Note that <em>name</em> may be <code class="xref py py-const docutils literal"><span class="pre">None</span></code> in which
case you should open a temporary file with a name of your
choosing. May be an instance of <a class="reference internal" href="#apsw.URIFilename" title="apsw.URIFilename"><code class="xref py py-class docutils literal"><span class="pre">URIFilename</span></code></a>.</li>
<li><strong>flags</strong> – A list of two integers <code class="docutils literal"><span class="pre">[inputflags,</span>
<span class="pre">outputflags]</span></code>. Each integer is one or more of the <a class="reference external" href="https://sqlite.org/c3ref/c_open_autoproxy.html">open flags</a> binary orred
together. The <code class="docutils literal"><span class="pre">inputflags</span></code> tells you what SQLite wants. For
example <code class="xref py py-const docutils literal"><span class="pre">SQLITE_OPEN_DELETEONCLOSE</span></code> means the file should
be automatically deleted when closed. The <code class="docutils literal"><span class="pre">outputflags</span></code>
describes how you actually did open the file. For example if you
opened it read only then <code class="xref py py-const docutils literal"><span class="pre">SQLITE_OPEN_READONLY</span></code> should be
set.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xRandomness">
<code class="descclassname">VFS.</code><code class="descname">xRandomness</code><span class="sig-paren">(</span><em>numbytes</em><span class="sig-paren">)</span> → bytes<a class="headerlink" href="#apsw.VFS.xRandomness" title="Permalink to this definition">¶</a></dt>
<dd><p>This method is called once when SQLite needs to seed the random
number generator. It is called on the default VFS only. It is not
called again, even across <a class="reference internal" href="apsw.html#apsw.shutdown" title="apsw.shutdown"><code class="xref py py-meth docutils literal"><span class="pre">apsw.shutdown()</span></code></a> calls. You can
return less than the number of bytes requested including None. If
you return more then the surplus is ignored.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">(Python 2) string, buffer (Python 3) bytes, buffer</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xSetSystemCall">
<code class="descclassname">VFS.</code><code class="descname">xSetSystemCall</code><span class="sig-paren">(</span><em>name</em>, <em>pointer</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#apsw.VFS.xSetSystemCall" title="Permalink to this definition">¶</a></dt>
<dd><p>Change a system call used by the VFS. This is useful for testing
and some other scenarios such as sandboxing.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> – The string name of the system call</li>
<li><strong>pointer</strong> – A pointer provided as an int/long. There is no
reference counting or other memory tracking of the pointer. If
you provide one you need to ensure it is around for the lifetime
of this and any other related VFS.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Raise an exception to return an error. If the system call does
not exist then raise <a class="reference internal" href="exceptions.html#apsw.NotFoundError" title="apsw.NotFoundError"><code class="xref py py-exc docutils literal"><span class="pre">NotFoundError</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">True if the system call was set. False if the system
call is not known.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFS.xSleep">
<code class="descclassname">VFS.</code><code class="descname">xSleep</code><span class="sig-paren">(</span><em>microseconds</em><span class="sig-paren">)</span> → integer<a class="headerlink" href="#apsw.VFS.xSleep" title="Permalink to this definition">¶</a></dt>
<dd><p>Pause exection of the thread for at least the specified number of
microseconds (millionths of a second). This routine is typically called from the busy handler.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">How many microseconds you actually requested the
operating system to sleep for. For example if your operating
system sleep call only takes seconds then you would have to have
rounded the microseconds number up to the nearest second and
should return that rounded up value.</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="vfsfile-class">
<h2>VFSFile class<a class="headerlink" href="#vfsfile-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="apsw.VFSFile">
<em class="property">class </em><code class="descname">VFSFile</code><span class="sig-paren">(</span><em>vfs</em>, <em>name</em>, <em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile" title="Permalink to this definition">¶</a></dt>
<dd><p>Wraps access to a file. You only need to derive from this class
if you want the file object returned from <a class="reference internal" href="#apsw.VFS.xOpen" title="apsw.VFS.xOpen"><code class="xref py py-meth docutils literal"><span class="pre">VFS.xOpen()</span></code></a> to
inherit from an existing VFS implementation.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All file sizes and offsets are 64 bit quantities even on 32 bit
operating systems.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>vfs</strong> – The vfs you want to inherit behaviour from. You can
use an empty string <code class="docutils literal"><span class="pre">""</span></code> to inherit from the default vfs.</li>
<li><strong>name</strong> – The name of the file being opened. May be an instance of <a class="reference internal" href="#apsw.URIFilename" title="apsw.URIFilename"><code class="xref py py-class docutils literal"><span class="pre">URIFilename</span></code></a>.</li>
<li><strong>flags</strong> – A two list <code class="docutils literal"><span class="pre">[inflags,</span> <span class="pre">outflags]</span></code> as detailed in <a class="reference internal" href="#apsw.VFS.xOpen" title="apsw.VFS.xOpen"><code class="xref py py-meth docutils literal"><span class="pre">VFS.xOpen()</span></code></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><strong>ValueError</strong> – If the named VFS is not registered.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If the VFS that you inherit from supports <a class="reference internal" href="tips.html#wal"><span class="std std-ref">write ahead
logging</span></a> then your <a class="reference internal" href="#apsw.VFSFile" title="apsw.VFSFile"><code class="xref py py-class docutils literal"><span class="pre">VFSFile</span></code></a> will also support the
xShm methods necessary to implement wal.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#apsw.VFS.xOpen" title="apsw.VFS.xOpen"><code class="xref py py-meth docutils literal"><span class="pre">VFS.xOpen()</span></code></a></p>
</div>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.excepthook">
<code class="descclassname">VFSFile.</code><code class="descname">excepthook</code><span class="sig-paren">(</span><em>etype</em>, <em>evalue</em>, <em>etraceback</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.excepthook" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when there has been an exception in a <a class="reference internal" href="#apsw.VFSFile" title="apsw.VFSFile"><code class="xref py py-class docutils literal"><span class="pre">VFSFile</span></code></a>
routine. The default implementation calls <code class="docutils literal"><span class="pre">sys.excepthook</span></code> and
if that fails then <code class="docutils literal"><span class="pre">PyErr_Display</span></code>. The three arguments
correspond to what <code class="docutils literal"><span class="pre">sys.exc_info()</span></code> would return.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>etype</strong> – The exception type</li>
<li><strong>evalue</strong> – The exception value</li>
<li><strong>etraceback</strong> – The exception traceback. Note this
includes all frames all the way up to the thread being started.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xCheckReservedLock">
<code class="descclassname">VFSFile.</code><code class="descname">xCheckReservedLock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xCheckReservedLock" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if any database connection (in this or another process)
has a lock other than <a class="reference external" href="https://sqlite.org/c3ref/c_lock_exclusive.html">SQLITE_LOCK_NONE or SQLITE_LOCK_SHARED</a>.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xClose">
<code class="descclassname">VFSFile.</code><code class="descname">xClose</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xClose" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the database. Note that even if you return an error you should
still close the file. It is safe to call this method mutliple
times.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xDeviceCharacteristics">
<code class="descclassname">VFSFile.</code><code class="descname">xDeviceCharacteristics</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → int<a class="headerlink" href="#apsw.VFSFile.xDeviceCharacteristics" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <a class="reference external" href="https://sqlite.org/c3ref/c_iocap_atomic.html">I/O capabilities</a> (bitwise or of
appropriate values). If you do not implement the function or have an
error then 0 (the SQLite default) is returned.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xFileControl">
<code class="descclassname">VFSFile.</code><code class="descname">xFileControl</code><span class="sig-paren">(</span><em>op</em>, <em>ptr</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#apsw.VFSFile.xFileControl" title="Permalink to this definition">¶</a></dt>
<dd><p>Receives <a class="reference external" href="https://sqlite.org/c3ref/file_control.html">file control</a> request typically
issued by <a class="reference internal" href="connection.html#apsw.Connection.filecontrol" title="apsw.Connection.filecontrol"><code class="xref py py-meth docutils literal"><span class="pre">Connection.filecontrol()</span></code></a>. See
<a class="reference internal" href="connection.html#apsw.Connection.filecontrol" title="apsw.Connection.filecontrol"><code class="xref py py-meth docutils literal"><span class="pre">Connection.filecontrol()</span></code></a> for an example of how to pass a
Python object to this routine.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>op</strong> – A numeric code. Codes below 100 are reserved for SQLite
internal use.</li>
<li><strong>ptr</strong> – An integer corresponding to a pointer at the C level.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A boolean indicating if the op was understood</p>
</td>
</tr>
</tbody>
</table>
<p>As of SQLite 3.6.10, this method is called by SQLite if you have
inherited from an underlying VFSFile. Consequently ensure you pass
any unrecognised codes through to your super class. For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="k">def</span> <span class="nf">xFileControl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">op</span><span class="p">,</span> <span class="n">ptr</span><span class="p">):</span>
<span class="k">if</span> <span class="n">op</span><span class="o">==</span><span class="mi">1027</span><span class="p">:</span>
<span class="n">process_quick</span><span class="p">(</span><span class="n">ptr</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">op</span><span class="o">==</span><span class="mi">1028</span><span class="p">:</span>
<span class="n">obj</span><span class="o">=</span><span class="n">ctypes</span><span class="o">.</span><span class="n">py_object</span><span class="o">.</span><span class="n">from_address</span><span class="p">(</span><span class="n">ptr</span><span class="p">)</span><span class="o">.</span><span class="n">value</span>
<span class="k">else</span><span class="p">:</span>
<span class="c"># this ensures superclass implementation is called</span>
<span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyFile</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">xFileControl</span><span class="p">(</span><span class="n">op</span><span class="p">,</span> <span class="n">ptr</span><span class="p">)</span>
<span class="c"># we understood the op</span>
<span class="k">return</span> <span class="k">True</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xFileSize">
<code class="descclassname">VFSFile.</code><code class="descname">xFileSize</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → int<a class="headerlink" href="#apsw.VFSFile.xFileSize" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the size of the file in bytes. Remember that file sizes are
64 bit quantities even on 32 bit operating systems.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xLock">
<code class="descclassname">VFSFile.</code><code class="descname">xLock</code><span class="sig-paren">(</span><em>level</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xLock" title="Permalink to this definition">¶</a></dt>
<dd><p>Increase the lock to the level specified which is one of the
<a class="reference external" href="https://sqlite.org/c3ref/c_lock_exclusive.html">SQLITE_LOCK</a>
family of constants. If you can’t increase the lock level because
someone else has locked it, then raise <a class="reference internal" href="exceptions.html#apsw.BusyError" title="apsw.BusyError"><code class="xref py py-exc docutils literal"><span class="pre">BusyError</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xRead">
<code class="descclassname">VFSFile.</code><code class="descname">xRead</code><span class="sig-paren">(</span><em>amount</em>, <em>offset</em><span class="sig-paren">)</span> → bytes<a class="headerlink" href="#apsw.VFSFile.xRead" title="Permalink to this definition">¶</a></dt>
<dd><p>Read the specified <em>amount</em> of data starting at <em>offset</em>. You
should make every effort to read all the data requested, or return
an error. If you have the file open for non-blocking I/O or if
signals happen then it is possible for the underlying operating
system to do a partial read. You will need to request the
remaining data. Except for empty files SQLite considers short
reads to be a fatal error.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>amount</strong> – Number of bytes to read</li>
<li><strong>offset</strong> – Where to start reading. This number may be 64 bit once the database is larger than 2GB.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">(Python 2) string, buffer. (Python 3) bytes, buffer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xSectorSize">
<code class="descclassname">VFSFile.</code><code class="descname">xSectorSize</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → int<a class="headerlink" href="#apsw.VFSFile.xSectorSize" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the native underlying sector size. SQLite uses the value
returned in determining the default database page size. If you do
not implement the function or have an error then 4096 (the SQLite
default) is returned.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xSync">
<code class="descclassname">VFSFile.</code><code class="descname">xSync</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xSync" title="Permalink to this definition">¶</a></dt>
<dd><p>Ensure data is on the disk platters (ie could survive a power
failure immediately after the call returns) with the <a class="reference external" href="https://sqlite.org/c3ref/c_sync_dataonly.html">sync flags</a> detailing what
needs to be synced. You can sync more than what is requested.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xTruncate">
<code class="descclassname">VFSFile.</code><code class="descname">xTruncate</code><span class="sig-paren">(</span><em>newsize</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xTruncate" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the file length to <em>newsize</em> (which may be more or less than the
current length).</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xUnlock">
<code class="descclassname">VFSFile.</code><code class="descname">xUnlock</code><span class="sig-paren">(</span><em>level</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xUnlock" title="Permalink to this definition">¶</a></dt>
<dd><p>Decrease the lock to the level specified which is one of the
<a class="reference external" href="https://sqlite.org/c3ref/c_lock_exclusive.html">SQLITE_LOCK</a>
family of constants.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.VFSFile.xWrite">
<code class="descclassname">VFSFile.</code><code class="descname">xWrite</code><span class="sig-paren">(</span><em>data</em>, <em>offset</em><span class="sig-paren">)</span><a class="headerlink" href="#apsw.VFSFile.xWrite" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the <em>data</em> starting at absolute <em>offset</em>. You must write all the data
requested, or return an error. If you have the file open for
non-blocking I/O or if signals happen then it is possible for the
underlying operating system to do a partial write. You will need to
write the remaining data.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>offset</strong> – Where to start writing. This number may be 64 bit once the database is larger than 2GB.</li>
<li><strong>data</strong> – (Python 2) string, (Python 3) bytes</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="urifilename-class">
<h2>URIFilename class<a class="headerlink" href="#urifilename-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="apsw.URIFilename">
<em class="property">class </em><code class="descname">URIFilename</code><a class="headerlink" href="#apsw.URIFilename" title="Permalink to this definition">¶</a></dt>
<dd><p>SQLite uses a convoluted method of storing <a class="reference external" href="https://sqlite.org/uri.html">uri parameters</a> after the filename binding the
C filename representation and parameters together. This class
encapsulates that binding. The <a class="reference internal" href="example.html#example-vfs"><span class="std std-ref">example</span></a> shows
usage of this class.</p>
<p>Your <a class="reference internal" href="#apsw.VFS.xOpen" title="apsw.VFS.xOpen"><code class="xref py py-meth docutils literal"><span class="pre">VFS.xOpen()</span></code></a> method will generally be passed one of
these instead of a string as the filename if the URI flag was used
or the main database flag is set.</p>
<p>You can safely pass it on to the <a class="reference internal" href="#apsw.VFSFile" title="apsw.VFSFile"><code class="xref py py-class docutils literal"><span class="pre">VFSFile</span></code></a> constructor
which knows how to get the name back out.</p>
</dd></dl>
<dl class="method">
<dt id="apsw.URIFilename.filename">
<code class="descclassname">URIFilename.</code><code class="descname">filename</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → str<a class="headerlink" href="#apsw.URIFilename.filename" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the filename.</p>
</dd></dl>
<span class="target" id="index-2"></span><dl class="method">
<dt id="apsw.URIFilename.uri_boolean">
<code class="descclassname">URIFilename.</code><code class="descname">uri_boolean</code><span class="sig-paren">(</span><em>name</em>, <em>default</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#apsw.URIFilename.uri_boolean" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the boolean value for parameter <cite>name</cite> or <cite>default</cite> if not
present.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/uri_boolean.html">sqlite3_uri_boolean</a></p>
</dd></dl>
<span class="target" id="index-3"></span><dl class="method">
<dt id="apsw.URIFilename.uri_int">
<code class="descclassname">URIFilename.</code><code class="descname">uri_int</code><span class="sig-paren">(</span><em>name</em>, <em>default</em><span class="sig-paren">)</span> → int<a class="headerlink" href="#apsw.URIFilename.uri_int" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the integer value for parameter <cite>name</cite> or <cite>default</cite> if not
present.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/uri_boolean.html">sqlite3_uri_int64</a></p>
</dd></dl>
<span class="target" id="index-4"></span><dl class="method">
<dt id="apsw.URIFilename.uri_parameter">
<code class="descclassname">URIFilename.</code><code class="descname">uri_parameter</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span> → str<a class="headerlink" href="#apsw.URIFilename.uri_parameter" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the value of parameter <cite>name</cite> or None.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/uri_boolean.html">sqlite3_uri_parameter</a></p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Virtual File System (VFS)</a><ul>
<li><a class="reference internal" href="#exceptions-and-errors">Exceptions and errors</a></li>
<li><a class="reference internal" href="#vfs-class">VFS class</a></li>
<li><a class="reference internal" href="#vfsfile-class">VFSFile class</a></li>
<li><a class="reference internal" href="#urifilename-class">URIFilename class</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="vtable.html"
title="previous chapter">Virtual Tables</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="shell.html"
title="next chapter">Shell</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/vfs.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<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="shell.html" title="Shell"
>next</a> |</li>
<li class="right" >
<a href="vtable.html" title="Virtual Tables"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">APSW 3.16.2-r1 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="copyright.html">Copyright</a> 2004-2016, Roger Binns <rogerb@rogerbinns.com>.
Last updated on Jan 14, 2017.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8.
</div>
</body>
</html>
|