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 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
|
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Virtual Tables — APSW 3.46.0.1 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=72bcf2f2" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
<link rel="stylesheet" type="text/css" href="_static/apsw.css?v=3c7e2631" />
<link rel="shortcut icon" href="_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d98f5d2b"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
<link rel="author" title="About these documents" href="about.html" />
<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="next" title="Virtual File System (VFS)" href="vfs.html" />
<link rel="prev" title="Backup" href="backup.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home">
APSW
<img src="_static/apswlogo.png" class="logo" alt="Logo"/>
</a>
<div class="version">
3.46.0.1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
<li class="toctree-l1"><a class="reference internal" href="tips.html">Tips</a></li>
<li class="toctree-l1"><a class="reference internal" href="example.html">Example/Tour</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation and customization</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">Extensions</a></li>
<li class="toctree-l1"><a class="reference internal" href="apsw.html">APSW Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="connection.html">Connections to a database</a></li>
<li class="toctree-l1"><a class="reference internal" href="cursor.html">Cursors (executing SQL)</a></li>
<li class="toctree-l1"><a class="reference internal" href="blob.html">Blob Input/Output</a></li>
<li class="toctree-l1"><a class="reference internal" href="backup.html">Backup</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Virtual Tables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#indexinfo-class">IndexInfo class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.IndexInfo"><code class="docutils literal notranslate"><span class="pre">IndexInfo</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.colUsed"><code class="docutils literal notranslate"><span class="pre">IndexInfo.colUsed</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.distinct"><code class="docutils literal notranslate"><span class="pre">IndexInfo.distinct</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.estimatedCost"><code class="docutils literal notranslate"><span class="pre">IndexInfo.estimatedCost</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.estimatedRows"><code class="docutils literal notranslate"><span class="pre">IndexInfo.estimatedRows</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraintUsage_argvIndex"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraintUsage_argvIndex()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraintUsage_in"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraintUsage_in()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraintUsage_omit"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraintUsage_omit()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraint_collation"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraint_collation()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraint_iColumn"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraint_iColumn()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraint_op"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraint_op()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraint_rhs"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraint_rhs()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aConstraint_usable"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aConstraint_usable()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aOrderBy_desc"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aOrderBy_desc()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.get_aOrderBy_iColumn"><code class="docutils literal notranslate"><span class="pre">IndexInfo.get_aOrderBy_iColumn()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.idxFlags"><code class="docutils literal notranslate"><span class="pre">IndexInfo.idxFlags</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.idxNum"><code class="docutils literal notranslate"><span class="pre">IndexInfo.idxNum</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.idxStr"><code class="docutils literal notranslate"><span class="pre">IndexInfo.idxStr</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.nConstraint"><code class="docutils literal notranslate"><span class="pre">IndexInfo.nConstraint</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.nOrderBy"><code class="docutils literal notranslate"><span class="pre">IndexInfo.nOrderBy</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.orderByConsumed"><code class="docutils literal notranslate"><span class="pre">IndexInfo.orderByConsumed</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.set_aConstraintUsage_argvIndex"><code class="docutils literal notranslate"><span class="pre">IndexInfo.set_aConstraintUsage_argvIndex()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.set_aConstraintUsage_in"><code class="docutils literal notranslate"><span class="pre">IndexInfo.set_aConstraintUsage_in()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IndexInfo.set_aConstraintUsage_omit"><code class="docutils literal notranslate"><span class="pre">IndexInfo.set_aConstraintUsage_omit()</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#vtmodule-class">VTModule class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.VTModule"><code class="docutils literal notranslate"><span class="pre">VTModule</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTModule.Connect"><code class="docutils literal notranslate"><span class="pre">VTModule.Connect()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTModule.Create"><code class="docutils literal notranslate"><span class="pre">VTModule.Create()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTModule.ShadowName"><code class="docutils literal notranslate"><span class="pre">VTModule.ShadowName()</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#vttable-class">VTTable class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.VTTable"><code class="docutils literal notranslate"><span class="pre">VTTable</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Begin"><code class="docutils literal notranslate"><span class="pre">VTTable.Begin()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.BestIndex"><code class="docutils literal notranslate"><span class="pre">VTTable.BestIndex()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.BestIndexObject"><code class="docutils literal notranslate"><span class="pre">VTTable.BestIndexObject()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Commit"><code class="docutils literal notranslate"><span class="pre">VTTable.Commit()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Destroy"><code class="docutils literal notranslate"><span class="pre">VTTable.Destroy()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Disconnect"><code class="docutils literal notranslate"><span class="pre">VTTable.Disconnect()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.FindFunction"><code class="docutils literal notranslate"><span class="pre">VTTable.FindFunction()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Integrity"><code class="docutils literal notranslate"><span class="pre">VTTable.Integrity()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Open"><code class="docutils literal notranslate"><span class="pre">VTTable.Open()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Release"><code class="docutils literal notranslate"><span class="pre">VTTable.Release()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Rename"><code class="docutils literal notranslate"><span class="pre">VTTable.Rename()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Rollback"><code class="docutils literal notranslate"><span class="pre">VTTable.Rollback()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Savepoint"><code class="docutils literal notranslate"><span class="pre">VTTable.Savepoint()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.Sync"><code class="docutils literal notranslate"><span class="pre">VTTable.Sync()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.UpdateChangeRow"><code class="docutils literal notranslate"><span class="pre">VTTable.UpdateChangeRow()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.UpdateDeleteRow"><code class="docutils literal notranslate"><span class="pre">VTTable.UpdateDeleteRow()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTTable.UpdateInsertRow"><code class="docutils literal notranslate"><span class="pre">VTTable.UpdateInsertRow()</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#vtcursor-class">VTCursor class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.VTCursor"><code class="docutils literal notranslate"><span class="pre">VTCursor</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.Close"><code class="docutils literal notranslate"><span class="pre">VTCursor.Close()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.Column"><code class="docutils literal notranslate"><span class="pre">VTCursor.Column()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.ColumnNoChange"><code class="docutils literal notranslate"><span class="pre">VTCursor.ColumnNoChange()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.Eof"><code class="docutils literal notranslate"><span class="pre">VTCursor.Eof()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.Filter"><code class="docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.Next"><code class="docutils literal notranslate"><span class="pre">VTCursor.Next()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VTCursor.Rowid"><code class="docutils literal notranslate"><span class="pre">VTCursor.Rowid()</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="vfs.html">Virtual File System (VFS)</a></li>
<li class="toctree-l1"><a class="reference internal" href="shell.html">Shell</a></li>
<li class="toctree-l1"><a class="reference internal" href="bestpractice.html">Best Practice</a></li>
<li class="toctree-l1"><a class="reference internal" href="ext.html">Various interesting and useful bits of functionality</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">Exceptions and Errors</a></li>
<li class="toctree-l1"><a class="reference internal" href="execution.html">Execution and tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="dbapi.html">DBAPI notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="pysqlite.html">sqlite3 module differences</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmarking.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="copyright.html">Copyright and License</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Change History</a></li>
<li class="toctree-l1"><a class="reference internal" href="py-modindex.html">Module Index</a></li>
<li class="toctree-l1"><a class="reference internal" href="genindex.html">Index</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">APSW</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Virtual Tables</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/vtable.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
<a href="backup.html" class="btn btn-neutral float-left" title="Backup" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="vfs.html" class="btn btn-neutral float-right" title="Virtual File System (VFS)" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="virtual-tables">
<span id="virtualtables"></span><h1>Virtual Tables<a class="headerlink" href="#virtual-tables" title="Link to this heading"></a></h1>
<p><a class="reference external" href="https://sqlite.org/vtab.html">Virtual Tables</a> let a developer
provide an underlying table implementations, while still presenting
a normal SQL interface to the user. The person writing SQL doesn’t
need to know or care that some of the tables come from elsewhere.</p>
<p>Some examples of how you might use this:</p>
<ul class="simple">
<li><p>Translating to/from information stored in other formats</p></li>
<li><p>Accessing the data remotely (eg you could make a table that backends into the cloud)</p></li>
<li><p>Dynamic information (eg currently running processes, files and directories, objects in your program)</p></li>
<li><p>There are other examples on the <a class="reference external" href="https://sqlite.org/vtab.html">SQLite page</a></p></li>
</ul>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>You’ll find initial development a lot quicker by using
<a class="reference internal" href="ext.html#apsw.ext.make_virtual_module" title="apsw.ext.make_virtual_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">apsw.ext.make_virtual_module()</span></code></a> which lets you
export a Python function as a virtual table, being
able to provide positional and keyword arguments as
part of your query.</p>
<p>See <a class="reference internal" href="example.html#example-virtual-tables"><span class="std std-ref">the example</span></a>.</p>
</div>
<p>To write a virtual table, you need to have 3 types of object. A
<a class="reference internal" href="#apsw.VTModule" title="apsw.VTModule"><code class="xref py py-class docutils literal notranslate"><span class="pre">module</span></code></a> providing the module, a <a class="reference internal" href="#apsw.VTTable" title="apsw.VTTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">virtual</span> <span class="pre">table</span></code></a>,
and a <a class="reference internal" href="#apsw.VTCursor" title="apsw.VTCursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">cursor</span></code></a> that moves through a table.</p>
<section id="indexinfo-class">
<h2>IndexInfo class<a class="headerlink" href="#indexinfo-class" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="apsw.IndexInfo">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">IndexInfo</span></span><a class="headerlink" href="#apsw.IndexInfo" title="Link to this definition"></a></dt>
<dd><p>IndexInfo represents the <a class="reference external" href="https://www.sqlite.org/c3ref/index_info.html">sqlite3_index_info</a> and associated
methods used in the <a class="reference internal" href="#apsw.VTTable.BestIndexObject" title="apsw.VTTable.BestIndexObject"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.BestIndexObject()</span></code></a> method.</p>
<p>Naming is identical to the C structure rather than Pythonic. You can
access members directly while needing to use get/set methods for array
members.</p>
<p>You will get <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.12)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if you use the object outside of an
BestIndex method.</p>
<p><a class="reference internal" href="ext.html#apsw.ext.index_info_to_dict" title="apsw.ext.index_info_to_dict"><code class="xref py py-meth docutils literal notranslate"><span class="pre">apsw.ext.index_info_to_dict()</span></code></a> provides a convenient
representation of this object as a <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.12)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.colUsed">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">colUsed</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#set" title="(in Python v3.12)"><span class="pre">set</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#apsw.IndexInfo.colUsed" title="Link to this definition"></a></dt>
<dd><p>(Read-only) Columns used by the statement. Note that a set is returned, not
the underlying integer.</p>
</dd></dl>
<dl class="py attribute" id="index-0">
<dt class="sig sig-object py" id="apsw.IndexInfo.distinct">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">distinct</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></em><a class="headerlink" href="#apsw.IndexInfo.distinct" title="Link to this definition"></a></dt>
<dd><p>(Read-only) How the query planner would like output ordered
if the query is using group by or distinct.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vtab_distinct.html">sqlite3_vtab_distinct</a></p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.estimatedCost">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">estimatedCost</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.12)"><span class="pre">float</span></a></em><a class="headerlink" href="#apsw.IndexInfo.estimatedCost" title="Link to this definition"></a></dt>
<dd><p>Estimated cost of using this index</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.estimatedRows">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">estimatedRows</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></em><a class="headerlink" href="#apsw.IndexInfo.estimatedRows" title="Link to this definition"></a></dt>
<dd><p>Estimated number of rows returned</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraintUsage_argvIndex">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraintUsage_argvIndex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraintUsage_argvIndex" title="Link to this definition"></a></dt>
<dd><p>Returns <em>argvIndex</em> for <em>aConstraintUsage[which]</em></p>
</dd></dl>
<dl class="py method" id="index-1">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraintUsage_in">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraintUsage_in</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraintUsage_in" title="Link to this definition"></a></dt>
<dd><p>Returns True if the constraint is <em>in</em> - eg column in (3, 7, 9)</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vtab_in.html">sqlite3_vtab_in</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraintUsage_omit">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraintUsage_omit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraintUsage_omit" title="Link to this definition"></a></dt>
<dd><p>Returns <em>omit</em> for <em>aConstraintUsage[which]</em></p>
</dd></dl>
<dl class="py method" id="index-2">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraint_collation">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraint_collation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraint_collation" title="Link to this definition"></a></dt>
<dd><p>Returns collation name for <em>aConstraint[which]</em></p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vtab_collation.html">sqlite3_vtab_collation</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraint_iColumn">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraint_iColumn</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraint_iColumn" title="Link to this definition"></a></dt>
<dd><p>Returns <em>iColumn</em> for <em>aConstraint[which]</em></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraint_op">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraint_op</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraint_op" title="Link to this definition"></a></dt>
<dd><p>Returns <em>op</em> for <em>aConstraint[which]</em></p>
</dd></dl>
<dl class="py method" id="index-3">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraint_rhs">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraint_rhs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraint_rhs" title="Link to this definition"></a></dt>
<dd><p>Returns right hand side value if known, else None.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vtab_rhs_value.html">sqlite3_vtab_rhs_value</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aConstraint_usable">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aConstraint_usable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aConstraint_usable" title="Link to this definition"></a></dt>
<dd><p>Returns <em>usable</em> for <em>aConstraint[which]</em></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aOrderBy_desc">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aOrderBy_desc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aOrderBy_desc" title="Link to this definition"></a></dt>
<dd><p>Returns <em>desc</em> for <em>aOrderBy[which]</em></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.get_aOrderBy_iColumn">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">get_aOrderBy_iColumn</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.get_aOrderBy_iColumn" title="Link to this definition"></a></dt>
<dd><p>Returns <em>iColumn</em> for <em>aOrderBy[which]</em></p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.idxFlags">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">idxFlags</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></em><a class="headerlink" href="#apsw.IndexInfo.idxFlags" title="Link to this definition"></a></dt>
<dd><p>Mask of <a class="reference internal" href="apsw.html#apsw.mapping_virtual_table_scan_flags" title="apsw.mapping_virtual_table_scan_flags"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SQLITE_INDEX_SCAN</span> <span class="pre">flags</span></code></a></p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.idxNum">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">idxNum</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></em><a class="headerlink" href="#apsw.IndexInfo.idxNum" title="Link to this definition"></a></dt>
<dd><p>Number used to identify the index</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.idxStr">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">idxStr</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></em><a class="headerlink" href="#apsw.IndexInfo.idxStr" title="Link to this definition"></a></dt>
<dd><p>Name used to identify the index</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.nConstraint">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">nConstraint</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></em><a class="headerlink" href="#apsw.IndexInfo.nConstraint" title="Link to this definition"></a></dt>
<dd><p>(Read-only) Number of constraint entries</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.nOrderBy">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">nOrderBy</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></em><a class="headerlink" href="#apsw.IndexInfo.nOrderBy" title="Link to this definition"></a></dt>
<dd><p>(Read-only) Number of order by entries</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.IndexInfo.orderByConsumed">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">orderByConsumed</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></em><a class="headerlink" href="#apsw.IndexInfo.orderByConsumed" title="Link to this definition"></a></dt>
<dd><p>True if index output is already ordered</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.set_aConstraintUsage_argvIndex">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">set_aConstraintUsage_argvIndex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">argvIndex</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.set_aConstraintUsage_argvIndex" title="Link to this definition"></a></dt>
<dd><p>Sets <em>argvIndex</em> for <em>aConstraintUsage[which]</em></p>
</dd></dl>
<dl class="py method" id="index-4">
<dt class="sig sig-object py" id="apsw.IndexInfo.set_aConstraintUsage_in">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">set_aConstraintUsage_in</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">filter_all</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.set_aConstraintUsage_in" title="Link to this definition"></a></dt>
<dd><p>If <em>which</em> is an <em>in</em> constraint, and <em>filter_all</em> is True then your <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a>
method will have all of the values at once.</p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vtab_in.html">sqlite3_vtab_in</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.IndexInfo.set_aConstraintUsage_omit">
<span class="sig-prename descclassname"><span class="pre">IndexInfo.</span></span><span class="sig-name descname"><span class="pre">set_aConstraintUsage_omit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">omit</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.IndexInfo.set_aConstraintUsage_omit" title="Link to this definition"></a></dt>
<dd><p>Sets <em>omit</em> for <em>aConstraintUsage[which]</em></p>
</dd></dl>
</section>
<section id="vtmodule-class">
<h2>VTModule class<a class="headerlink" href="#vtmodule-class" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="apsw.VTModule">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">VTModule</span></span><a class="headerlink" href="#apsw.VTModule" title="Link to this definition"></a></dt>
<dd></dd></dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is no actual <em>VTModule</em> class - it is shown this way for
documentation convenience and is present as a <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Protocol">typing protocol</a>.</p>
</div>
<p>A module instance is used to create the virtual tables. Once you have
a module object, you register it with a connection by calling
<a class="reference internal" href="connection.html#apsw.Connection.create_module" title="apsw.Connection.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.create_module()</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># make an instance</span>
<span class="n">mymod</span><span class="o">=</span><span class="n">MyModuleClass</span><span class="p">()</span>
<span class="c1"># register the vtable on connection con</span>
<span class="n">con</span><span class="o">.</span><span class="n">create_module</span><span class="p">(</span><span class="s2">"modulename"</span><span class="p">,</span> <span class="n">mymod</span><span class="p">)</span>
<span class="c1"># tell SQLite about the table</span>
<span class="n">con</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">"create VIRTUAL table tablename USING modulename('arg1', 2)"</span><span class="p">)</span>
</pre></div>
</div>
<p>The create step is to tell SQLite about the existence of the table.
Any number of tables referring to the same module can be made this
way.</p>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTModule.Connect">
<span class="sig-prename descclassname"><span class="pre">VTModule.</span></span><span class="sig-name descname"><span class="pre">Connect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">connection</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><span class="pre">Connection</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">modulename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">databasename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">tablename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="p"><span class="pre">...</span></span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference internal" href="#apsw.VTTable" title="apsw.VTTable"><span class="pre">VTTable</span></a><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#apsw.VTModule.Connect" title="Link to this definition"></a></dt>
<dd><p>The parameters and return are identical to
<a class="reference internal" href="#apsw.VTModule.Create" title="apsw.VTModule.Create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Create()</span></code></a>. This method is called
when there are additional references to the table. <a class="reference internal" href="#apsw.VTModule.Create" title="apsw.VTModule.Create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Create()</span></code></a> will be called the first time and
<a class="reference internal" href="#apsw.VTModule.Connect" title="apsw.VTModule.Connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connect()</span></code></a> after that.</p>
<p>The advise is to create caches, generated data and other
heavyweight processing on <a class="reference internal" href="#apsw.VTModule.Create" title="apsw.VTModule.Create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Create()</span></code></a> calls and then
find and reuse that on the subsequent <a class="reference internal" href="#apsw.VTModule.Connect" title="apsw.VTModule.Connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connect()</span></code></a>
calls.</p>
<p>The corresponding call is <a class="reference internal" href="#apsw.VTTable.Disconnect" title="apsw.VTTable.Disconnect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.Disconnect()</span></code></a>. If you have a simple virtual table implementation, then just
set <a class="reference internal" href="#apsw.VTModule.Connect" title="apsw.VTModule.Connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connect()</span></code></a> to be the same as <a class="reference internal" href="#apsw.VTModule.Create" title="apsw.VTModule.Create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Create()</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyModule</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">Create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">connection</span><span class="p">,</span> <span class="n">modulename</span><span class="p">,</span> <span class="n">databasename</span><span class="p">,</span> <span class="n">tablename</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="c1"># do lots of hard work</span>
<span class="n">Connect</span><span class="o">=</span><span class="n">Create</span>
</pre></div>
</div>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xconnect_method">SQLite xConnect reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTModule.Create">
<span class="sig-prename descclassname"><span class="pre">VTModule.</span></span><span class="sig-name descname"><span class="pre">Create</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">connection</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><span class="pre">Connection</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">modulename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">databasename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">tablename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="p"><span class="pre">...</span></span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference internal" href="#apsw.VTTable" title="apsw.VTTable"><span class="pre">VTTable</span></a><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#apsw.VTModule.Create" title="Link to this definition"></a></dt>
<dd><p>Called when a table is first created on a <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">connection</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>connection</strong> – An instance of <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Connection</span></code></a></p></li>
<li><p><strong>modulename</strong> – The string name under which the module was <a class="reference internal" href="connection.html#apsw.Connection.create_module" title="apsw.Connection.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">registered</span></code></a></p></li>
<li><p><strong>databasename</strong> – The name of the database. <cite>main</cite>, <cite>temp</cite>, the name in <a class="reference external" href="https://sqlite.org/lang_attach.html">ATTACH</a></p></li>
<li><p><strong>tablename</strong> – Name of the table the user wants to create.</p></li>
<li><p><strong>args</strong> – Any arguments that were specified in the <a class="reference external" href="https://sqlite.org/lang_createvtab.html">create virtual table</a> statement.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>A list of two items. The first is a SQL <a class="reference external" href="https://sqlite.org/lang_createtable.html">create table</a> statement. The
columns are parsed so that SQLite knows what columns and declared types exist for the table. The second item
is an object that implements the <a class="reference internal" href="#apsw.VTTable" title="apsw.VTTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">table</span></code></a> methods.</p>
</dd>
</dl>
<p>The corresponding call is <a class="reference internal" href="#apsw.VTTable.Destroy" title="apsw.VTTable.Destroy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.Destroy()</span></code></a>.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xcreate_method">SQLite xCreate reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTModule.ShadowName">
<span class="sig-prename descclassname"><span class="pre">VTModule.</span></span><span class="sig-name descname"><span class="pre">ShadowName</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">table_suffix</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.VTModule.ShadowName" title="Link to this definition"></a></dt>
<dd><p>This method is called to check if
<em>table_suffix</em> is a <a class="reference external" href="https://www.sqlite.org/vtab.html#the_xshadowname_method">shadow name</a></p>
<p>The default implementation always returns <em>False</em>.</p>
<p>If a virtual table is created using this module
named <code class="code docutils literal notranslate"><span class="pre">example</span></code> and then a real table is created
named <code class="code docutils literal notranslate"><span class="pre">example_content</span></code>, this would be called with
a <em>table_suffix</em> of <code class="code docutils literal notranslate"><span class="pre">content</span></code></p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xshadowname_method">SQLite xShadowName reference</a></p>
</dd></dl>
</section>
<section id="vttable-class">
<h2>VTTable class<a class="headerlink" href="#vttable-class" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="apsw.VTTable">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">VTTable</span></span><a class="headerlink" href="#apsw.VTTable" title="Link to this definition"></a></dt>
<dd><div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is no actual <em>VTTable</em> class - it is shown this way for
documentation convenience and is present as a <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Protocol">typing protocol</a>.</p>
</div>
<p>The <a class="reference internal" href="#apsw.VTTable" title="apsw.VTTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">VTTable</span></code></a> object contains knowledge of the indices, makes
cursors and can perform transactions.</p>
<p>A virtual table is structured as a series of rows, each of which has
the same number of columns. The value in a column must be one of the <a class="reference external" href="https://sqlite.org/datatype3.html">5
supported types</a>, but the
type can be different between rows for the same column. The virtual
table routines identify the columns by number, starting at zero.</p>
<p>Each row has a <strong>unique</strong> 64 bit integer <a class="reference external" href="https://sqlite.org/autoinc.html">rowid</a> with the <a class="reference internal" href="#apsw.VTCursor" title="apsw.VTCursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cursor</span></code></a> routines operating on this number, as well as some of
the <a class="reference internal" href="#apsw.VTTable" title="apsw.VTTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Table</span></code></a> routines such as <a class="reference internal" href="#apsw.VTTable.UpdateChangeRow" title="apsw.VTTable.UpdateChangeRow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">UpdateChangeRow</span></code></a>.</p>
<p>It is possible to <a class="reference external" href="https://www.sqlite.org/vtab.html#_without_rowid_virtual_tables_">not have a rowid</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Begin">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Begin</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Begin" title="Link to this definition"></a></dt>
<dd><p>This function is used as part of transactions. You do not have to
provide the method.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xbegin_method">SQLite xBegin reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.BestIndex">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">BestIndex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">constraints</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Sequence</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">orderbys</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Sequence</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">Any</span></span></span><a class="headerlink" href="#apsw.VTTable.BestIndex" title="Link to this definition"></a></dt>
<dd><p>This is a complex method. To get going initially, just return
<em>None</em> and you will be fine. You should also consider using
<a class="reference internal" href="#apsw.VTTable.BestIndexObject" title="apsw.VTTable.BestIndexObject"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BestIndexObject()</span></code></a> instead.</p>
<p>Implementing this method reduces the number of rows scanned
in your table to satisfy queries, but only if you have an
index or index like mechanism available.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The implementation of this method differs slightly from the
<a class="reference external" href="https://sqlite.org/vtab.html">SQLite documentation</a>
for the C API. You are not passed “unusable” constraints. The
argv/constraintarg positions are not off by one. In the C api, you
have to return position 1 to get something passed to
<a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a> in position 0. With the APSW
implementation, you return position 0 to get Filter arg 0,
position 1 to get Filter arg 1 etc.</p>
</div>
<p>The purpose of this method is to ask if you have the ability to
determine if a row meets certain constraints that doesn’t involve
visiting every row. An example constraint is <code class="docutils literal notranslate"><span class="pre">price</span> <span class="pre">></span> <span class="pre">74.99</span></code>. In a
traditional SQL database, queries with constraints can be speeded up
<a class="reference external" href="https://sqlite.org/lang_createindex.html">with indices</a>. If
you return None, then SQLite will visit every row in your table and
evaluate the constraints itself. Your index choice returned from
BestIndex will also be passed to the <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Filter()</span></code></a> method on your cursor
object. Note that SQLite may call this method multiple times trying
to find the most efficient way of answering a complex query.</p>
<p><strong>constraints</strong></p>
<p>You will be passed the constraints as a sequence of tuples containing two
items. The first item is the column number and the second item is
the operation.</p>
<blockquote>
<div><p>Example query: <code class="docutils literal notranslate"><span class="pre">select</span> <span class="pre">*</span> <span class="pre">from</span> <span class="pre">foo</span> <span class="pre">where</span> <span class="pre">price</span> <span class="pre">></span> <span class="pre">74.99</span> <span class="pre">and</span>
<span class="pre">quantity<=10</span> <span class="pre">and</span> <span class="pre">customer='Acme</span> <span class="pre">Widgets'</span></code></p>
<p>If customer is column 0, price column 2 and quantity column 5
then the constraints will be:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_GT</span><span class="p">),</span>
<span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_LE</span><span class="p">),</span>
<span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_EQ</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that you do not get the value of the constraint (ie “Acme
Widgets”, 74.99 and 10 in this example).</p>
</div></blockquote>
<p>If you do have any suitable indices then you return a sequence the
same length as constraints with the members mapping to the
constraints in order. Each can be one of None, an integer or a tuple
of an integer and a boolean. Conceptually SQLite is giving you a
list of constraints and you are returning a list of the same length
describing how you could satisfy each one.</p>
<p>Each list item returned corresponding to a constraint is one of:</p>
<blockquote>
<div><dl class="simple">
<dt>None</dt><dd><p>This means you have no index for that constraint. SQLite
will have to iterate over every row for it.</p>
</dd>
<dt>integer</dt><dd><p>This is the argument number for the constraintargs being passed
into the <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Filter()</span></code></a> function of your
<a class="reference internal" href="#apsw.VTCursor" title="apsw.VTCursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">cursor</span></code></a> (the values “Acme Widgets”, 74.99
and 10 in the example).</p>
</dd>
<dt>(integer, boolean)</dt><dd><p>By default SQLite will check what you return. For example if
you said that you had an index on price and so would only
return rows greater than 74.99, then SQLite will still
check that each row you returned is greater than 74.99.
If the boolean is True then SQLite will not double
check, while False retains the default double checking.</p>
</dd>
</dl>
</div></blockquote>
<p>Example query: <code class="docutils literal notranslate"><span class="pre">select</span> <span class="pre">*</span> <span class="pre">from</span> <span class="pre">foo</span> <span class="pre">where</span> <span class="pre">price</span> <span class="pre">></span> <span class="pre">74.99</span> <span class="pre">and</span>
<span class="pre">quantity<=10</span> <span class="pre">and</span> <span class="pre">customer=='Acme</span> <span class="pre">Widgets'</span></code>. customer is column 0,
price column 2 and quantity column 5. You can index on customer
equality and price.</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Constraints (in)</p></th>
<th class="head"><p>Constraints used (out)</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_GT</span><span class="p">),</span>
<span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_LE</span><span class="p">),</span>
<span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_EQ</span><span class="p">)</span>
</pre></div>
</div>
</td>
<td><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="mi">0</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
<p>When your <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Filter</span></code></a> method in the cursor is called,
constraintarg[0] will be “Acme Widgets” (customer constraint value)
and constraintarg[1] will be 74.99 (price constraint value). You can
also return an index number (integer) and index string to use
(SQLite attaches no significance to these values - they are passed
as is to your <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a> method as a way for the
BestIndex method to let the <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Filter()</span></code></a> method know
which of your indices or similar mechanism to use.</p>
<p><strong>orderbys</strong></p>
<p>The second argument to BestIndex is a sequence of orderbys because
the query requested the results in a certain order. If your data is
already in that order then SQLite can give the results back as
is. If not, then SQLite will have to sort the results first.</p>
<blockquote>
<div><p>Example query: <code class="docutils literal notranslate"><span class="pre">select</span> <span class="pre">*</span> <span class="pre">from</span> <span class="pre">foo</span> <span class="pre">order</span> <span class="pre">by</span> <span class="pre">price</span> <span class="pre">desc,</span> <span class="pre">quantity</span> <span class="pre">asc</span></code></p>
<p>Price is column 2, quantity column 5 so orderbys will be:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span> <span class="c1"># True means descending, False is ascending</span>
<span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
</div></blockquote>
<p><strong>Return</strong></p>
<p>You should return up to 5 items. Items not present in the return have a default value.</p>
<dl class="simple">
<dt>0: constraints used (default None)</dt><dd><p>This must either be None or a sequence the same length as
constraints passed in. Each item should be as specified above
saying if that constraint is used, and if so which constraintarg
to make the value be in your <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a> function.</p>
</dd>
<dt>1: index number (default zero)</dt><dd><p>This value is passed as is to <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a></p>
</dd>
<dt>2: index string (default None)</dt><dd><p>This value is passed as is to <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Filter()</span></code></a></p>
</dd>
<dt>3: orderby consumed (default False)</dt><dd><p>Return True if your output will be in exactly the same order as the orderbys passed in</p>
</dd>
<dt>4: estimated cost (default a huge number)</dt><dd><p>Approximately how many disk operations are needed to provide the
results. SQLite uses the cost to optimise queries. For example if
the query includes <em>A or B</em> and A has 2,000 operations and B has 100
then it is best to evaluate B before A.</p>
</dd>
</dl>
<p><strong>A complete example</strong></p>
<p>Query is <code class="docutils literal notranslate"><span class="pre">select</span> <span class="pre">*</span> <span class="pre">from</span> <span class="pre">foo</span> <span class="pre">where</span> <span class="pre">price>74.99</span> <span class="pre">and</span> <span class="pre">quantity<=10</span> <span class="pre">and</span>
<span class="pre">customer=="Acme</span> <span class="pre">Widgets"</span> <span class="pre">order</span> <span class="pre">by</span> <span class="pre">price</span> <span class="pre">desc,</span> <span class="pre">quantity</span> <span class="pre">asc</span></code>.
Customer is column 0, price column 2 and quantity column 5. You can
index on customer equality and price.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">BestIndex</span><span class="p">(</span><span class="n">constraints</span><span class="p">,</span> <span class="n">orderbys</span><span class="p">)</span>
<span class="n">constraints</span><span class="o">=</span> <span class="p">(</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_GT</span><span class="p">),</span>
<span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_LE</span><span class="p">),</span>
<span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">apsw</span><span class="o">.</span><span class="n">SQLITE_INDEX_CONSTRAINT_EQ</span><span class="p">)</span> <span class="p">)</span>
<span class="n">orderbys</span><span class="o">=</span> <span class="p">(</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="p">)</span>
<span class="c1"># You return</span>
<span class="p">(</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="c1"># constraints used</span>
<span class="mi">27</span><span class="p">,</span> <span class="c1"># index number</span>
<span class="s2">"idx_pr_cust"</span><span class="p">,</span> <span class="c1"># index name</span>
<span class="kc">False</span><span class="p">,</span> <span class="c1"># results are not in orderbys order</span>
<span class="mi">1000</span> <span class="c1"># about 1000 disk operations to access index</span>
<span class="p">)</span>
<span class="c1"># Your Cursor.Filter method will be called with:</span>
<span class="mi">27</span><span class="p">,</span> <span class="c1"># index number you returned</span>
<span class="s2">"idx_pr_cust"</span><span class="p">,</span> <span class="c1"># index name you returned</span>
<span class="s2">"Acme Widgets"</span><span class="p">,</span> <span class="c1"># constraintarg[0] - customer</span>
<span class="mf">74.99</span> <span class="c1"># constraintarg[1] - price</span>
</pre></div>
</div>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xbestindex_method">SQLite xBestIndex reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.BestIndexObject">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">BestIndexObject</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">index_info</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#apsw.IndexInfo" title="apsw.IndexInfo"><span class="pre">IndexInfo</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.VTTable.BestIndexObject" title="Link to this definition"></a></dt>
<dd><p>This method is called instead of <a class="reference internal" href="#apsw.VTTable.BestIndex" title="apsw.VTTable.BestIndex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BestIndex()</span></code></a> if
<em>use_bestindex_object</em> was <em>True</em> in the call to
<a class="reference internal" href="connection.html#apsw.Connection.create_module" title="apsw.Connection.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.create_module()</span></code></a>.</p>
<p>Use the <a class="reference internal" href="#apsw.IndexInfo" title="apsw.IndexInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">IndexInfo</span></code></a> to tell SQLite about your indexes, and
extract other information.</p>
<p>Return <em>True</em> to indicate all is well. If you return <em>False</em> or there is an error,
then <a class="reference external" href="https://www.sqlite.org/vtab.html#return_value">SQLITE_CONSTRAINT</a> is returned to
SQLite.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xbestindex_method">SQLite xBestIndex reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Commit">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Commit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Commit" title="Link to this definition"></a></dt>
<dd><p>This function is used as part of transactions. You do not have to
provide the method.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xcommit_method">SQLite xCommit reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Destroy">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Destroy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Destroy" title="Link to this definition"></a></dt>
<dd><p>The opposite of <a class="reference internal" href="#apsw.VTModule.Create" title="apsw.VTModule.Create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTModule.Create()</span></code></a>. This method is called when
the table is no longer used. Note that you must always release
resources even if you intend to return an error, as it will not be
called again on error.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xdestroy_method">SQLite xDestroy reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Disconnect">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Disconnect</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Disconnect" title="Link to this definition"></a></dt>
<dd><p>The opposite of <a class="reference internal" href="#apsw.VTModule.Connect" title="apsw.VTModule.Connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTModule.Connect()</span></code></a>. This method is called when
a reference to a virtual table is no longer used, but <a class="reference internal" href="#apsw.VTTable.Destroy" title="apsw.VTTable.Destroy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.Destroy()</span></code></a> will
be called when the table is no longer used.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xdisconnect_method">SQLite xDisconnect reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.FindFunction">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">FindFunction</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">nargs</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">Callable</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">Callable</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#apsw.VTTable.FindFunction" title="Link to this definition"></a></dt>
<dd><p>Called to find if the virtual table has its own implementation of a
particular scalar function. You do not have to provide this method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> – The function name</p></li>
<li><p><strong>nargs</strong> – How many arguments the function takes</p></li>
</ul>
</dd>
</dl>
<p>Return <em>None</em> if you don’t have the function. Zero is then returned to SQLite.</p>
<p>Return a callable if you have one. One is then returned to SQLite with the function.</p>
<p>Return a sequence of int, callable. The int is returned to SQLite with the function.
This is useful for <em>SQLITE_INDEX_CONSTRAINT_FUNCTION</em> returns.</p>
<p>It isn’t possible to tell SQLite about exceptions in this function, so an
<a class="reference internal" href="exceptions.html#unraisable"><span class="std std-ref">unraisable exception</span></a> is used.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<ul class="simple">
<li><p><a class="reference internal" href="connection.html#apsw.Connection.overload_function" title="apsw.Connection.overload_function"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.overload_function()</span></code></a></p></li>
</ul>
</div>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xfindfunction_method">SQLite xFindFunction reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Integrity">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Integrity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">schema</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">is_quick</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Integrity" title="Link to this definition"></a></dt>
<dd><p>If present, check the integrity of the virtual table.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>schema</strong> – Database name <cite>main</cite>, <cite>temp</cite>, the name in <a class="reference external" href="https://sqlite.org/lang_attach.html">ATTACH</a></p></li>
<li><p><strong>name</strong> – Name of the table</p></li>
<li><p><strong>is_quick</strong> – 0 if <a class="reference external" href="https://sqlite.org/pragma.html#pragma_integrity_check">pragma integrity_check</a> was used,
1 if <a class="reference external" href="https://sqlite.org/pragma.html#pragma_quick_check">pragma quick_check</a> was used, and may contain
other values in the future.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>None if there are no problems, else a string to be used as an error message. The string is returned to the
pragma as is, so it is recommended that you include the database and table name to clarify what database and
table the message is referring to.</p>
</dd>
</dl>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xintegrity_method">SQLite xIntegrity reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Open">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Open</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#apsw.VTCursor" title="apsw.VTCursor"><span class="pre">VTCursor</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Open" title="Link to this definition"></a></dt>
<dd><p>Returns a <a class="reference internal" href="#apsw.VTCursor" title="apsw.VTCursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">cursor</span></code></a> object.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xopen_method">SQLite xOpen reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Release">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Release</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Release" title="Link to this definition"></a></dt>
<dd><p>Release nested transactions back to <em>level</em>.</p>
<p>If you do not provide this method then the call succeeds (matching
SQLite behaviour when no callback is provided).</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xsavepoint_xrelease_and_xrollbackto_methods">SQLite xRelease reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Rename">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Rename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newname</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Rename" title="Link to this definition"></a></dt>
<dd><p>Notification that the table will be given a new name. If you return
without raising an exception, then SQLite renames the table (you
don’t have to do anything). If you raise an exception then the
renaming is prevented. You do not have to provide this method.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xrename_method">SQLite xRename reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Rollback">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Rollback</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Rollback" title="Link to this definition"></a></dt>
<dd><p>This function is used as part of transactions. You do not have to
provide the method.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xsavepoint_xrelease_and_xrollbackto_methods">SQLite xRollbackTo reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Savepoint">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Savepoint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Savepoint" title="Link to this definition"></a></dt>
<dd><p>Set nested transaction to <em>level</em>.</p>
<p>If you do not provide this method then the call succeeds (matching
SQLite behaviour when no callback is provided).</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xsavepoint_xrelease_and_xrollbackto_methods">SQLite xSavepoint reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.Sync">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">Sync</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.Sync" title="Link to this definition"></a></dt>
<dd><p>This function is used as part of transactions. You do not have to
provide the method.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xsync_method">SQLite xSync reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.UpdateChangeRow">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">UpdateChangeRow</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">row</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">newrowid</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">fields</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="p"><span class="pre">...</span></span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.UpdateChangeRow" title="Link to this definition"></a></dt>
<dd><p>Change an existing row. You may also need to change the rowid - for example if the query was
<code class="docutils literal notranslate"><span class="pre">UPDATE</span> <span class="pre">table</span> <span class="pre">SET</span> <span class="pre">rowid=rowid+100</span> <span class="pre">WHERE</span> <span class="pre">...</span></code></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>row</strong> – The existing 64 bit integer rowid</p></li>
<li><p><strong>newrowid</strong> – If not the same as <em>row</em> then also change the rowid to this.</p></li>
<li><p><strong>fields</strong> – A tuple of values the same length and order as columns in your table</p></li>
</ul>
</dd>
</dl>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xupdate_method">SQLite xUpdate reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.UpdateDeleteRow">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">UpdateDeleteRow</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rowid</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.UpdateDeleteRow" title="Link to this definition"></a></dt>
<dd><p>Delete the row with the specified <em>rowid</em>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>rowid</strong> – 64 bit integer</p>
</dd>
</dl>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xupdate_method">SQLite xUpdate reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTTable.UpdateInsertRow">
<span class="sig-prename descclassname"><span class="pre">VTTable.</span></span><span class="sig-name descname"><span class="pre">UpdateInsertRow</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rowid</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">fields</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="p"><span class="pre">...</span></span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTTable.UpdateInsertRow" title="Link to this definition"></a></dt>
<dd><p>Insert a row with the specified <em>rowid</em>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>rowid</strong> – <em>None</em> if you should choose the rowid yourself, else a 64 bit integer</p></li>
<li><p><strong>fields</strong> – A tuple of values the same length and order as columns in your table</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>If <em>rowid</em> was <em>None</em> then return the id you assigned
to the row. If <em>rowid</em> was not <em>None</em> then the return value
is ignored.</p>
</dd>
</dl>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xupdate_method">SQLite xUpdate reference</a></p>
</dd></dl>
</section>
<section id="vtcursor-class">
<h2>VTCursor class<a class="headerlink" href="#vtcursor-class" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="apsw.VTCursor">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">VTCursor</span></span><a class="headerlink" href="#apsw.VTCursor" title="Link to this definition"></a></dt>
<dd></dd></dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is no actual <em>VTCursor</em> class - it is shown this way for
documentation convenience and is present as a <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Protocol">typing protocol</a>.</p>
</div>
<p>The <a class="reference internal" href="#apsw.VTCursor" title="apsw.VTCursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">VTCursor</span></code></a> object is used for iterating over a table.
There may be many cursors simultaneously so each one needs to keep
track of where in the table it is.</p>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTCursor.Close">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">Close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.Close" title="Link to this definition"></a></dt>
<dd><p>This is the destructor for the cursor. Note that you must
cleanup. The method will not be called again if you raise an
exception.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xclose_method">SQLite xClose reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTCursor.Column">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">Column</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">number</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.Column" title="Link to this definition"></a></dt>
<dd><p>Requests the value of the specified column <em>number</em> of the current
row. If <em>number</em> is -1 then return the rowid.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Must be one one of the <a class="reference internal" href="tips.html#types"><span class="std std-ref">5
supported types</span></a></p>
</dd>
</dl>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xcolumn_method">SQLite xColumn reference</a></p>
</dd></dl>
<dl class="py method" id="index-5">
<dt class="sig sig-object py" id="apsw.VTCursor.ColumnNoChange">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">ColumnNoChange</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">number</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="apsw.html#apsw.SQLiteValue" title="apsw.SQLiteValue"><span class="pre">SQLiteValue</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.ColumnNoChange" title="Link to this definition"></a></dt>
<dd><p><a class="reference internal" href="#apsw.VTTable.UpdateChangeRow" title="apsw.VTTable.UpdateChangeRow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.UpdateChangeRow()</span></code></a> is going to be called which includes
values for all columns. However this column is not going to be changed
in that update.</p>
<p>If you return <a class="reference internal" href="apsw.html#apsw.no_change" title="apsw.no_change"><code class="xref py py-attr docutils literal notranslate"><span class="pre">apsw.no_change</span></code></a> then <a class="reference internal" href="#apsw.VTTable.UpdateChangeRow" title="apsw.VTTable.UpdateChangeRow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.UpdateChangeRow()</span></code></a>
will have <a class="reference internal" href="apsw.html#apsw.no_change" title="apsw.no_change"><code class="xref py py-attr docutils literal notranslate"><span class="pre">apsw.no_change</span></code></a> for this column. If you return
anything else then it will have that value - as though <a class="reference internal" href="#apsw.VTCursor.Column" title="apsw.VTCursor.Column"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTCursor.Column()</span></code></a>
had been called.</p>
<p>This method will only be called if <em>use_no_change</em> was <em>True</em> in the
call to <a class="reference internal" href="connection.html#apsw.Connection.create_module" title="apsw.Connection.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.create_module()</span></code></a>.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xcolumn_method">SQLite xColumn reference</a></p>
<p>Calls: <a class="reference external" href="https://sqlite.org/c3ref/vtab_nochange.html">sqlite3_vtab_nochange</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTCursor.Eof">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">Eof</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.12)"><span class="pre">bool</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.Eof" title="Link to this definition"></a></dt>
<dd><p>Called to ask if we are at the end of the table. It is called after each call to Filter and Next.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>False if the cursor is at a valid row of data, else True</p>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This method can only return True or False to SQLite. If you have
an exception in the method or provide a non-boolean return then
True (no more data) will be returned to SQLite.</p>
</div>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xeof_method">SQLite xEof reference</a></p>
</dd></dl>
<dl class="py method" id="index-6">
<dt class="sig sig-object py" id="apsw.VTCursor.Filter">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">Filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">indexnum</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">indexname</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">constraintargs</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.12)"><span class="pre">tuple</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.Filter" title="Link to this definition"></a></dt>
<dd><p>This method is always called first to initialize an iteration to the
first row of the table. The arguments come from the
<a class="reference internal" href="#apsw.VTTable.BestIndex" title="apsw.VTTable.BestIndex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BestIndex()</span></code></a> or <a class="reference internal" href="#apsw.VTTable.BestIndexObject" title="apsw.VTTable.BestIndexObject"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BestIndexObject()</span></code></a>
with constraintargs being a tuple of the constraints you
requested. If you always return None in BestIndex then indexnum will
be zero, indexstring will be None and constraintargs will be empty).</p>
<p>If you had an <em>in</em> constraint and set <a class="reference internal" href="#apsw.IndexInfo.set_aConstraintUsage_in" title="apsw.IndexInfo.set_aConstraintUsage_in"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IndexInfo.set_aConstraintUsage_in()</span></code></a>
then that value will be a <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#set" title="(in Python v3.12)"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xfilter_method">SQLite xFilter reference</a></p>
<dl class="simple">
<dt>Calls:</dt><dd><ul class="simple">
<li><p><a class="reference external" href="https://sqlite.org/c3ref/vtab_in_first.html">sqlite3_vtab_in_first</a></p></li>
<li><p><a class="reference external" href="https://sqlite.org/c3ref/vtab_in_first.html">sqlite3_vtab_in_next</a></p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTCursor.Next">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">Next</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.Next" title="Link to this definition"></a></dt>
<dd><p>Move the cursor to the next row. Do not have an exception if there
is no next row. Instead return False when <a class="reference internal" href="#apsw.VTCursor.Eof" title="apsw.VTCursor.Eof"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Eof()</span></code></a> is
subsequently called.</p>
<p>If you said you had indices in your <a class="reference internal" href="#apsw.VTTable.BestIndex" title="apsw.VTTable.BestIndex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">VTTable.BestIndex()</span></code></a>
return, and they were selected for use as provided in the parameters
to <a class="reference internal" href="#apsw.VTCursor.Filter" title="apsw.VTCursor.Filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Filter()</span></code></a> then you should move to the next
appropriate indexed and constrained row.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xnext_method">SQLite xNext reference</a></p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="apsw.VTCursor.Rowid">
<span class="sig-prename descclassname"><span class="pre">VTCursor.</span></span><span class="sig-name descname"><span class="pre">Rowid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></span><a class="headerlink" href="#apsw.VTCursor.Rowid" title="Link to this definition"></a></dt>
<dd><p>Return the current rowid.</p>
<p><a class="reference external" href="https://sqlite.org/vtab.html#the_xrowid_method">SQLite xRowid reference</a></p>
</dd></dl>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="backup.html" class="btn btn-neutral float-left" title="Backup" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="vfs.html" class="btn btn-neutral float-right" title="Virtual File System (VFS)" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© <a href="copyright.html">Copyright</a> 2004-2024, Roger Binns <rogerb@rogerbinns.com>.
<span class="lastupdated">Last updated on Jun 16, 2024.
</span></p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>
|