Imported Upstream version 2.3.3 upstream/2.3.3
authorJoel Rosdahl <joel@debian.org>
Mon, 11 Jan 2010 20:37:37 +0000 (21:37 +0100)
committerJoel Rosdahl <joel@debian.org>
Mon, 11 Jan 2010 20:37:37 +0000 (21:37 +0100)
26 files changed:
PKG-INFO
doc/install-source-win32.html [deleted file]
doc/install-source.html [deleted file]
doc/usage-guide.html [deleted file]
pysqlite2/dbapi2.py
pysqlite2/test/factory.py
pysqlite2/test/regression.py
pysqlite2/test/types.py
src/cache.c
src/cache.h
src/connection.c
src/connection.h
src/cursor.c
src/cursor.h
src/microprotocols.c
src/microprotocols.h
src/module.c
src/module.h
src/prepare_protocol.c
src/prepare_protocol.h
src/row.c
src/row.h
src/statement.c
src/statement.h
src/util.c
src/util.h

index 6bb3e72..895db91 100644 (file)
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: pysqlite
-Version: 2.3.2
+Version: 2.3.3
 Summary: DB-API 2.0 interface for SQLite 3.x
 Home-page: http://pysqlite.org/
 Author: Gerhard Haering
diff --git a/doc/install-source-win32.html b/doc/install-source-win32.html
deleted file mode 100644 (file)
index d3b4c3c..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>pysqlite installation guide - installing from source on Windows</title>
-<style type="text/css">
-
-@import url(docutils.css);
-@import url(silvercity.css);
-
-div.code-block{
-margin-left: 2em ;
-margin-right: 2em ;
-background-color: #eeeeee;
-font-family: "Courier New", Courier, monospace;
-font-size: 10pt;
-}
-
-</style>
-</head>
-<body>
-<div class="document" id="pysqlite-installation-guide-installing-from-source-on-windows">
-<h1 class="title">pysqlite installation guide - installing from source on Windows</h1>
-<p>(c) 2005 Gerhard Häring</p>
-<p>Steps:</p>
-<blockquote>
-<ul class="simple">
-<li><a class="reference" href="#step-1-download-and-install-required-tools">Step 1: Download and install required tools</a></li>
-<li><a class="reference" href="#step-2-download-and-compile-sqlite">Step 2: Download and compile SQLite</a></li>
-<li><a class="reference" href="#step-3-compile-pysqlite">Step 3: Compile pysqlite</a></li>
-<li><a class="reference" href="#step-4-install-pysqlite-or-create-an-installer">Step 4: Install pysqlite or create an installer</a></li>
-<li><a class="reference" href="#step-5-test-your-pysqlite-installation">Step 5: Test your pysqlite installation</a></li>
-</ul>
-</blockquote>
-<div class="section">
-<h1><a id="step-1-download-and-install-required-tools" name="step-1-download-and-install-required-tools">Step 1: Download and install required tools</a></h1>
-<p>This guide explains how to build SQLite and pysqlite with free and commercial
-Microsoft compilers for Python 2.4 and later. Other compilers might work, too,
-and MINGW is known to work well for Python 2.3, but in order to keep this
-document to the point, only one obvious way to do it is documented.</p>
-<p>First we need to have a working compiler. These two work fine:</p>
-<blockquote>
-<ul class="simple">
-<li>Microsoft Visual Studio .NET 2003</li>
-<li>MS Toolkit Compiler (<a class="reference" href="http://www.vrplumber.com/programming/mstoolkit/">http://www.vrplumber.com/programming/mstoolkit/</a>)</li>
-</ul>
-</blockquote>
-<p>Then, we need GNU make. Download a Windows version from
-<a class="reference" href="http://mingw.sourceforge.net/download.shtml">http://mingw.sourceforge.net/download.shtml</a> and extract it.</p>
-<p>Make sure your PATH is set up correctly, so that the make.exe you just
-downloaded is in the PATH and that your compiler's environment is set up
-correctly. For MS Visual Studio .NET 2003, just execute
-Start/Programs/Microsoft Visual Studio .NET/Visual Studio .NET Tools/Visual
-Studio .NET 2003 Command Prompt. For the MS Toolkit Compiler write yourself a
-batch file that sets up the environment as neccessary.</p>
-</div>
-<div class="section">
-<h1><a id="step-2-download-and-compile-sqlite" name="step-2-download-and-compile-sqlite">Step 2: Download and compile SQLite</a></h1>
-<p>From now on, let's suppose you do all your development work in $SRCDIR.</p>
-<p>Now download the latest versions of the SQLite 3.x Windows sources from <a class="reference" href="http://sqlite.org/download.html">http://sqlite.org/download.html</a>.</p>
-<p>Pick the download that looks like this:</p>
-<p>sqlite-source-3_{major}_{minor}.zip</p>
-<p>Extract this file in $SRCDIR/sqlite</p>
-<p>Now copy this file into your $SRCDIR/sqlite directory:
-<a class="reference" href="http://initd.org/svn/pysqlite/pysqlite/trunk/misc/Makefile">http://initd.org/svn/pysqlite/pysqlite/trunk/misc/Makefile</a></p>
-<p>Then on a Windows command prompt, change into the $SRCDIR/sqlite directory and
-issue a &quot;make&quot;. This should build a statically linked SQLite library now:</p>
-<pre class="literal-block">
-Setting environment for using Microsoft Visual Studio .NET 2003 tools.
-(If you have another version of Visual Studio or Visual C++ installed and wish
-to use its tools from the command line, run vcvars32.bat for that version.)
-
-C:\Documents and Settings\Gerhard&gt;set path=c:\msys\1.0\bin;%PATH%
-
-C:\Documents and Settings\Gerhard&gt;d:
-
-D:\&gt;cd src\sqlite
-
-D:\src\sqlite&gt;make
-cl -c -O2 -Og -G7 -Foalter.o alter.c
-Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
-Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
-
-alter.c
-cl -c -O2 -Og -G7 -Foanalyze.o analyze.c
-Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
-Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
-
-[...]
-
-utf.c
-cl -c -O2 -Og -G7 -Folegacy.o legacy.c
-Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
-Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
-
-legacy.c
-link -LIB -OUT:sqlite3.lib alter.o analyze.o attach.o auth.o btree.o build.o cal
-lback.o complete.o date.o delete.o expr.o func.o hash.o insert.o main.o opcodes.
-o os_unix.o os_win.o pager.o parse.o pragma.o prepare.o printf.o random.o select
-.o table.o tokenize.o trigger.o update.o util.o vacuum.o vdbe.o vdbeapi.o vdbeau
-x.o vdbefifo.o vdbemem.o where.o utf.o legacy.o
-Microsoft (R) Library Manager Version 7.10.3077
-Copyright (C) Microsoft Corporation.  All rights reserved.
-
-done
-
-D:\src\sqlite&gt;
-</pre>
-</div>
-<div class="section">
-<h1><a id="step-3-compile-pysqlite" name="step-3-compile-pysqlite">Step 3: Compile pysqlite</a></h1>
-<p>Unpack the latest pysqlite sources in $SRCDIR/pysqlite</p>
-<p>Now change the include_dirs and library_dirs settings in <tt class="docutils literal"><span class="pre">setup.cfg</span></tt> like
-this:</p>
-<pre class="literal-block">
-[build_ext]
-define=
-include_dirs=../sqlite
-library_dirs=../sqlite
-libraries=sqlite3
-</pre>
-<p>Now open a command prompt, change to the directory where you decompressed the
-pysqlite source distribution, and type:</p>
-<pre class="literal-block">
-python setup.py build
-</pre>
-<p>If setup.py raises no errors and its output concludes with something like
-&quot;Creating library...&quot;, then you are ready to proceed to the next step.</p>
-<p>If you receive an error message from the compiler, then try to look at the
-first error it reports. Other errors will most likely be aftereffects from the
-first error (like not finding the sqlite3.h header file).</p>
-</div>
-<div class="section">
-<h1><a id="step-4-install-pysqlite-or-create-an-installer" name="step-4-install-pysqlite-or-create-an-installer">Step 4: Install pysqlite or create an installer</a></h1>
-<p>To install pysqlite now, invoke:</p>
-<pre class="literal-block">
-python setup.py install
-</pre>
-<p>from the commandline. In order to create an installer executable, invoke:</p>
-<pre class="literal-block">
-python setup.py bdist_wininst
-</pre>
-<p>from the commandline.</p>
-</div>
-<div class="section">
-<h1><a id="step-5-test-your-pysqlite-installation" name="step-5-test-your-pysqlite-installation">Step 5: Test Your pysqlite Installation</a></h1>
-<p>Switch to a directory other than the temporary directory into which you
-decompressed the source distribution (to avoid conflict between the copy of
-pysqlite in that directory and the copy placed under the standard Python
-site-packages directory), then run the pysqlite test suite by starting a Python
-interpreter for the Python version you installed pysqlite for and entering the
-following:</p>
-<pre class="literal-block">
-&gt;&gt;&gt; from pysqlite2 import test
-&gt;&gt;&gt; test.test()
-......................................................................
-......................................................................
-...........
-----------------------------------------------------------------------
-Ran 151 tests in 1.059s
-
-OK
-&gt;&gt;&gt;
-</pre>
-<p>If the test suite runs without any errors, you are finished.</p>
-<p>You should not encounter any errors at this stage since you have already
-completed the compilation and installation steps successfully. If you do,
-please report them to the <a class="reference" href="http://initd.org/tracker/pysqlite">pysqlite bug tracker</a> or the <a class="reference" href="http://lists.initd.org/mailman/listinfo/pysqlite">pysqlite mailing
-list</a>.</p>
-</div>
-</div>
-</body>
-</html>
diff --git a/doc/install-source.html b/doc/install-source.html
deleted file mode 100644 (file)
index 36a9452..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>pysqlite installation guide - source distribution</title>
-<style type="text/css">
-
-@import url(docutils.css);
-@import url(silvercity.css);
-
-div.code-block{
-margin-left: 2em ;
-margin-right: 2em ;
-background-color: #eeeeee;
-font-family: "Courier New", Courier, monospace;
-font-size: 10pt;
-}
-
-</style>
-</head>
-<body>
-<div class="document" id="pysqlite-installation-guide-source-distribution">
-<h1 class="title">pysqlite installation guide - source distribution</h1>
-<p>(c) 2005 Gerhard Häring</p>
-<dl class="docutils">
-<dt>Note: For Windows users, it is recommended that you use the win32 binary</dt>
-<dd>distribution of pysqlite!</dd>
-</dl>
-<p>Steps:</p>
-<blockquote>
-<ul class="simple">
-<li><a class="reference" href="#step-1-satisfy-the-dependencies">Step 1: Satisfy the dependencies</a></li>
-<li><a class="reference" href="#step-2-compile-pysqlite">Step 2: Compile pysqlite</a></li>
-<li><a class="reference" href="#step-3-install-pysqlite">Step 3: Install pysqlite</a></li>
-<li><a class="reference" href="#step-4-test-your-pysqlite-installation">Step 4: Test your pysqlite installation</a></li>
-</ul>
-</blockquote>
-<div class="section">
-<h1><a id="step-1-satisfy-the-dependencies" name="step-1-satisfy-the-dependencies">Step 1: Satisfy The Dependencies</a></h1>
-<p>pysqlite requires a valid combination of the dependencies in the list below.</p>
-<p>Detailed instructions on how to install each dependency are beyond the scope of
-this document; consult the dependency distributor for installation
-instructions.</p>
-<p>Dependencies:</p>
-<blockquote>
-<ol class="arabic simple">
-<li>Operating System and C Compiler - one of:<ul>
-<li>Linux/FreeBSD/NetBSD/OpenBSD and GCC</li>
-<li>Other POSIX-compliant operating system and a C compiler</li>
-</ul>
-</li>
-<li>SQLite:<ul>
-<li>SQLite version 3.0.8 or later (as of pysqlite 2.2.0). This means we need
-the SQLite library installed - either statically or dynamically linked -
-and the SQLite header files. On Linux, the chances are very high that
-your distribution offers packages for SQLite 3. Be sure to verify the
-package is recent enough (version 3.0.8 or higher) and that you're
-installing the development package as well, which will be need for
-building pysqlite. On Debian and derivatives, the package to look for is
-called libsqlite3-dev.</li>
-</ul>
-</li>
-<li>Python:<ul>
-<li>Python 2.3 or later</li>
-</ul>
-</li>
-</ol>
-</blockquote>
-</div>
-<div class="section">
-<h1><a id="step-2-compile-pysqlite" name="step-2-compile-pysqlite">Step 2: Compile pysqlite</a></h1>
-<p>Once you have successfully installed the dependencies, you may proceed with the
-installation of pysqlite itself.</p>
-<p>pysqlite has full support for the <a class="reference" href="http://www.python.org/sigs/distutils-sig/">distutils</a>, the standard facility for Python
-package distribution and installation. Full instructions for using the
-distutils are available in <a class="reference" href="http://www.python.org/doc/current/inst/inst.html">this section of the Python documentation</a>, but you
-can skip them unless you have an otherwise insoluble problem.</p>
-<p>Open a command prompt, change to the directory where you decompressed the
-pysqlite source distribution, and type:</p>
-<pre class="literal-block">
-python setup.py build
-</pre>
-<p>The installation script, setup.py, will attempt to automatically detect the
-information needed by the C compiler; then it will invoke the distutils to
-perform the actual compilation. If you installed automatic distributions of the
-dependencies that place themselves in standard locations (on UNIX-style
-operating systems), the compilation should proceed without incident.</p>
-<p>Otherwise you will have to customize the build process. That's what the file
-<em>setup.cfg</em> is meant for. It's contains a few lines that you can customize so
-your C compiler will find the library and header files and you can also do a
-few other tweaks, like build pysqlite in debug mode.</p>
-<p>After you've customized <em>setup.cfg</em> apprporiately, try invoking <tt class="docutils literal"><span class="pre">python</span>
-<span class="pre">setup.py</span> <span class="pre">build</span></tt> again.</p>
-<p>If setup.py raises no errors and its output concludes with something like
-&quot;Creating library...&quot;, then you are ready to proceed to the next step.</p>
-<p>If you receive an error message from the compiler, then try to look at the
-first error it reports. Other errors will most likely be aftereffects from the
-first error (like not finding the sqlite3.h header file).</p>
-</div>
-<div class="section">
-<h1><a id="step-3-install-pysqlite" name="step-3-install-pysqlite">Step 3: Install pysqlite</a></h1>
-<p>During this step, the setup script moves the <em>pysqlite2</em> package (including the
-newly compiled C extension) to the standard package directory of your Python
-installation so that Python will be able to import pysqlite2.dbapi2 and
-pysqlite2.test.</p>
-<p>In addition to the Python code and shared library files actually used by the
-Python interpreter, the setup script typically installs some supporting files,
-such as documentation. Depending on your system configuration, these supporting
-files may be placed in the same directory or a different directory from the
-files used by the Python interpreter.</p>
-<p>Run the following command:</p>
-<pre class="literal-block">
-python setup.py install
-</pre>
-<p>The setup script will install pysqlite, listing each file it installs.</p>
-<p>Errors during this step are rare because compilation (the finicky part of this
-process) has already taken place; installation is really just a matter of
-copying files. However, there will be file system permission errors if the
-Python installation directory is not writable by the user running the setup
-script. If you encounter such an error, try one of the following:</p>
-<ul class="simple">
-<li>Log in as a user who has the required file system permissions and repeat the
-installation step.</li>
-<li>Manually copy the directory build/lib.platform-pyver/pysqlite2 (which
-contains the Python modules and compiled library files created during the
-compilation step) to a directory in your PYTHONPATH. This approach will not
-install the supporting files, but they are for the benefit of the programmer
-rather than the Python interpreter anyway.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="step-4-test-your-pysqlite-installation" name="step-4-test-your-pysqlite-installation">Step 4: Test Your pysqlite Installation</a></h1>
-<p>Switch to a directory other than the temporary directory into which you
-decompressed the source distribution (to avoid conflict between the copy of
-pysqlite in that directory and the copy placed under the standard Python
-site-packages directory), then run the pysqlite test suite by starting a Python
-interpreter for the Python version you installed pysqlite for and entering the
-following:</p>
-<pre class="literal-block">
-&gt;&gt;&gt; from pysqlite2 import test
-&gt;&gt;&gt; test.test()
-.....................................................................................................
-----------------------------------------------------------------------
-Ran 101 tests in 0.182s
-</pre>
-<p>If the test suite runs without any errors, you are finished.</p>
-<p>You should not encounter any errors at this stage since you have already
-completed the compilation and installation steps successfully. If you do,
-please report them to the <a class="reference" href="http://initd.org/tracker/pysqlite">pysqlite bug tracker</a> or the <a class="reference" href="http://lists.initd.org/mailman/listinfo/pysqlite">pysqlite mailing
-list</a>.</p>
-</div>
-</div>
-</body>
-</html>
diff --git a/doc/usage-guide.html b/doc/usage-guide.html
deleted file mode 100644 (file)
index 78d59f6..0000000
+++ /dev/null
@@ -1,1374 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>pysqlite usage guide</title>
-<style type="text/css">
-
-@import url(docutils.css);
-@import url(silvercity.css);
-
-div.code-block{
-margin-left: 2em ;
-margin-right: 2em ;
-background-color: #eeeeee;
-font-family: "Courier New", Courier, monospace;
-font-size: 10pt;
-}
-
-</style>
-</head>
-<body>
-<div class="document" id="pysqlite-usage-guide">
-<h1 class="title">pysqlite usage guide</h1>
-<div class="line-block">
-<div class="line">(c) 2004-2005 David Rushby</div>
-<div class="line">(c) 2005-2006 Gerhard Häring</div>
-</div>
-<p>Last updated for pysqlite 2.3.0</p>
-<div class="section">
-<h1><a id="table-of-contents" name="table-of-contents">Table Of Contents</a></h1>
-<div class="line-block">
-<div class="line"><a class="reference" href="#introduction">0. Introduction</a></div>
-<div class="line"><a class="reference" href="#python-database-api-2-0-compliance">1. Python Database API 2.0 Compliance</a></div>
-<div class="line-block">
-<div class="line"><a class="reference" href="#incompatibilities">1.1 Incompatibilities</a></div>
-<div class="line"><a class="reference" href="#unsupported-optional-features">1.2 Unsupported Optional Features</a></div>
-<div class="line"><a class="reference" href="#nominally-supported-optional-features">1.3 Nominally Supported Optional Features</a></div>
-<div class="line"><a class="reference" href="#extensions-and-caveats">1.4 Extensions and Caveats</a></div>
-</div>
-<div class="line"><a class="reference" href="#brief-tutorial">2. Brief Tutorial</a></div>
-<div class="line-block">
-<div class="line"><a class="reference" href="#connecting-to-a-database">2.1 Connecting to a Database</a></div>
-<div class="line"><a class="reference" href="#executing-sql-statements">2.2 Executing SQL statements</a></div>
-</div>
-<div class="line"><a class="reference" href="#native-database-engine-features-and-extensions-beyond-the-python-db-api">3. Native Database Engine Features and Extensions Beyond the Python DB API</a></div>
-<div class="line-block">
-<div class="line"><a class="reference" href="#creating-user-defined-functions">3.1 Creating user-defined functions</a></div>
-<div class="line"><a class="reference" href="#creating-user-defined-aggregates">3.2 Creating user-defined aggregates</a></div>
-<div class="line"><a class="reference" href="#creating-and-using-collations">3.3 Creating and using collations</a></div>
-<div class="line"><a class="reference" href="#checking-for-complete-statements">3.4 Checking for complete statements</a></div>
-<div class="line"><a class="reference" href="#enabling-sqlite-s-shared-cache">3.5 Enabling SQLite's shared cache</a></div>
-<div class="line"><a class="reference" href="#setting-an-authorizer-callback">3.6 Setting an authorizer callback</a></div>
-</div>
-<div class="line"><a class="reference" href="#sqlite-and-python-types">4. SQLite and Python types</a></div>
-<div class="line-block">
-<div class="line"><a class="reference" href="#id1">4.1 Introduction</a></div>
-<div class="line"><a class="reference" href="#using-adapters-to-store-additional-python-types-in-sqlite-databases">4.2 Using adapters to store additional Python types in SQLite databases</a></div>
-<div class="line-block">
-<div class="line"><a class="reference" href="#letting-your-object-adapt-itself">4.2.1 Letting your object adapt itself</a></div>
-<div class="line"><a class="reference" href="#registering-an-adapter-callable">4.2.2 Registering an adapter callable</a></div>
-</div>
-<div class="line"><a class="reference" href="#converting-sqlite-values-to-custom-python-types">4.3 Converting SQLite values to custom Python types</a></div>
-<div class="line"><a class="reference" href="#default-pysqlite-adapters-and-converters">4.4 Default pysqlite adapters and converters</a></div>
-</div>
-<div class="line"><a class="reference" href="#controlling-transactions">5. Controlling Transactions</a></div>
-<div class="line"><a class="reference" href="#using-pysqlite-efficiently">6. Using pysqlite efficiently</a></div>
-<div class="line-block">
-<div class="line"><a class="reference" href="#using-shortcut-methods">6.1 Using shortcut methods</a></div>
-<div class="line"><a class="reference" href="#accessing-columns-by-name-instead-of-by-index">6.2 Accessing columns by name instead of by index</a></div>
-</div>
-</div>
-</div>
-<div class="section">
-<h1><a id="introduction" name="introduction">0. Introduction</a></h1>
-<p>This Usage Guide is not a tutorial on Python, SQL, or SQLite; rather, it is a
-topical presentation of pysqlite's feature set, with example code to
-demonstrate basic usage patterns. This guide is meant to be consumed in
-conjunction with the Python Database API Specification and the SQLite
-documentation.</p>
-<p>It was originally written by David Rushby for kinterbasdb. He kindly gave the
-permission to adapt it for pysqlite.</p>
-</div>
-<div class="section">
-<h1><a id="python-database-api-2-0-compliance" name="python-database-api-2-0-compliance">1. Python Database API 2.0 Compliance</a></h1>
-<div class="section">
-<h2><a id="incompatibilities" name="incompatibilities">1.1 Incompatibilities</a></h2>
-<ul>
-<li><p class="first">No type information in cursor.description</p>
-<p><em>cursor.description</em> has a tuple with the fields (<em>name</em>, <em>type_code</em>,
-<em>display_size</em>, <em>internal_size</em>, <em>precision</em>, <em>scale</em>, <em>null_ok</em>) for each
-column that a query returns. The DB-API spec requires that at least <em>name</em>
-and <em>type_code</em> are filled, but at the time cursor.description is built,
-pysqlite cannot determine any types, yet. So, the only field of
-<em>cursor.description</em> that pysqlite fills is <em>name</em>. All other fields are set to
-None.</p>
-</li>
-<li><p class="first">No type objects</p>
-<p>Consequently, there are also no type objects STRING, BINARY, NUMBER,
-DATETIME, ROWID at module-level. They would be useless.</p>
-</li>
-</ul>
-</div>
-<div class="section">
-<h2><a id="unsupported-optional-features" name="unsupported-optional-features">1.2 Unsupported Optional Features</a></h2>
-<ul>
-<li><p class="first"><strong>Cursor</strong> class</p>
-<ul>
-<li><p class="first"><strong>nextset</strong> method</p>
-<p>This method is not implemented because the database engine does not
-support opening multiple result sets simultaneously with a single
-cursor.</p>
-</li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section">
-<h2><a id="nominally-supported-optional-features" name="nominally-supported-optional-features">1.3 Nominally Supported Optional Features</a></h2>
-<ul>
-<li><p class="first"><strong>Cursor</strong> class</p>
-<ul>
-<li><p class="first"><strong>arraysize</strong> attribute</p>
-<p>As required by the spec, the value of this attribute is observed
-with respect to the fetchmany method. However, changing the value
-of this attribute does not make any difference in fetch efficiency
-because the database engine only supports fetching a single row at
-a time.</p>
-</li>
-<li><p class="first"><strong>setinputsizes</strong> method</p>
-<p>Although this method is present, it does nothing, as allowed by the
-spec.</p>
-</li>
-<li><p class="first"><strong>setoutputsize</strong> method</p>
-<p>Although this method is present, it does nothing, as allowed by the
-spec.</p>
-</li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section">
-<h2><a id="extensions-and-caveats" name="extensions-and-caveats">1.4 Extensions and Caveats</a></h2>
-<p>pysqlite offers a large feature set beyond the minimal requirements of the
-Python DB API. Most of these extensions are documented in the section of this
-document entitled Native Database Engine Features and Extensions Beyond the
-Python DB API.</p>
-<ul>
-<li><p class="first"><strong>connect</strong> function</p>
-<p>The parameter <em>database</em> refers to the database file for the SQLite
-database. It's a normal filesystem path and you can use absolute or
-relative path names.</p>
-<p>The connect function supports the following optional keyword arguments
-in addition to those required by the spec:</p>
-<ul>
-<li><p class="first"><strong>timeout</strong> - When a database is accessed by multiple connections, and</p>
-<p>one of the processes modifies the database, the SQLite database is
-locked until that transaction is committed. The timeout parameter
-specifies how long the connection should wait for the lock to go away
-until raising an exception. The default for the timeout parameter is
-5.0 (five seconds).</p>
-<dl class="docutils">
-<dt>Example:</dt>
-<dd><div class="first last"><div class="code-block">
-<span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_identifier">database</span><span class="p_operator">=</span><span class="p_string">"mydb"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">timeout</span><span class="p_operator">=</span><span class="p_number">10.0</span><span class="p_operator">)</span>
-</div>
-</div></dd>
-</dl>
-</li>
-<li><p class="first"><strong>isolation_level</strong> - pysqlite will by default open transactions with a
-&quot;BEGIN&quot; statement, when it encounters a DML statement like
-INSERT/UPDATE/DELETE/REPLACE. Some users don't want pysqlite to implicitly
-open transactions for them - they want an autocommit mode. Other users want
-pysqlite to open different kinds of transactions, like with &quot;BEGIN
-IMMEDIATE&quot;. See <a class="reference" href="#controlling-transactions">5. Controlling Transactions</a>  for a more detailed
-explanation.</p>
-<p>Note that you can also switch to a different isolation level by setting the
-<strong>isolation_level</strong> property of connections.</p>
-<dl class="docutils">
-<dt>Example:</dt>
-<dd><div class="first last"><div class="code-block">
-<span class="p_commentline">#&nbsp;Turn&nbsp;on&nbsp;autocommit&nbsp;mode</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">isolation_level</span><span class="p_operator">=</span><span class="p_word">None</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Set&nbsp;isolation_level&nbsp;to&nbsp;"IMMEDIATE"</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">isolation_level</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">"IMMEDIATE"</span>
-</div>
-</div></dd>
-</dl>
-</li>
-<li><p class="first"><strong>detect_types</strong> - SQLite natively supports only the types TEXT,
-INTEGER, FLOAT, BLOB and NULL. If you want to use other types, like you
-have to add support for them yourself.  The <em>detect_types</em> parameter and
-using custom <em>converters</em> registered with the module-level
-<em>register_converter</em> function allow you to easily do that.</p>
-<p><em>detect_types</em> defaults to 0 (i. e. off, no type detection), you can
-set it to any combination of <em>PARSE_DECLTYPES</em> and <em>PARSE_COLNAMES</em> to turn
-type detection on.</p>
-<p>Consult the section <a class="reference" href="#sqlite-and-python-types">4. SQLite and Python types</a> of this manual for
-details.</p>
-<ul>
-<li><p class="first"><strong>sqlite.PARSE_DECLTYPES</strong> - This makes pysqlite parse the declared
-type for each column it returns. It will parse out the first word of the
-declared type, i. e. for &quot;integer primary key&quot;, it will parse out
-&quot;integer&quot;. Then for that column, it will look into pysqlite's converters
-dictionary and use the converter function registered for that type there.</p>
-</li>
-<li><p class="first"><strong>sqlite.PARSE_COLNAMES</strong> - This makes pysqlite parse the column name
-for each column it returns. It will look for a string formed
-[mytype] in there, and then decide that 'mytype' is the type of
-the column. It will try to find an entry of 'mytype' in the
-converters dictionary and then use the converter function found
-there to return the value. The column name found in
-cursor.description is only the first word of the column name, i.
-e. if you use something like 'as &quot;x [datetime]&quot;' in your SQL,
-then pysqlite will parse out everything until the first blank for
-the column name: the column name would simply be &quot;x&quot;.</p>
-<p>The following example uses the column name <em>timestamp</em>, which is already
-registered by default in the converters dictionary with an appropriate
-converter!</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">datetime</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">detect_types</span><span class="p_operator">=</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">PARSE_COLNAMES</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_character">'select&nbsp;?&nbsp;as&nbsp;"x&nbsp;[timestamp]"'</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">now</span><span class="p_operator">(),))</span><span class="p_default"><br/>
-</span><span class="p_identifier">dt</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">dt</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">dt</span><span class="p_operator">)</span>
-</div>
-</li>
-</ul>
-</li>
-<li><p class="first"><strong>check_same_thread</strong> - SQLite connections/cursors can only safely be
-used in the same thread they were created in. pysqlite checks for
-this each time it would do a call to the SQLite engine. If you are
-confident that you are ensuring safety otherwise, you can disable
-that checks by setting check_same_thread to False.</p>
-</li>
-<li><p class="first"><strong>factory</strong> - By default, pysqlite uses the Connection class for the
-connect call. You can, however, subclass the Connection class and
-make .connect() use your class instead by providing your class for
-the factory parameter.</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">CountCursorsConnection</span><span class="p_operator">(</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">Connection</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">*</span><span class="p_identifier">args</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">**</span><span class="p_identifier">kwargs</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">Connection</span><span class="p_operator">.</span><span class="p_identifier">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">*</span><span class="p_identifier">args</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">**</span><span class="p_identifier">kwargs</span><span class="p_operator">)</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">numcursors</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_number">0</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">cursor</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">*</span><span class="p_identifier">args</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">**</span><span class="p_identifier">kwargs</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">numcursors</span><span class="p_default">&nbsp;</span><span class="p_operator">+=</span><span class="p_default">&nbsp;</span><span class="p_number">1</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">Connection</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">*</span><span class="p_identifier">args</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">**</span><span class="p_identifier">kwargs</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">factory</span><span class="p_operator">=</span><span class="p_identifier">CountCursorsConnection</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur1</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur2</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">numcursors</span>
-</div>
-</li>
-<li><p class="first"><strong>cached_statements</strong> - pysqlite internally uses a statement cache to avoid
-SQL parsing overhead. If you want to explicitly set the number of
-statements that are cached for the connection, you can set this parameter.
-The currently implemented default is to cache 100 statements.</p>
-</li>
-</ul>
-<div class="line-block">
-<div class="line"><br /></div>
-<div class="line"><br /></div>
-</div>
-</li>
-<li><p class="first"><strong>register_converter</strong> function - <tt class="docutils literal"><span class="pre">register_converter(typename,</span> <span class="pre">callable)</span></tt>
-registers a callable to convert a bytestring from the database into a custom
-Python type. The converter will be invoked for all database values that are
-of the type <tt class="docutils literal"><span class="pre">typename</span></tt>. Confer the parameter <strong>detect_types</strong> of the
-<strong>connect</strong> method for how the type detection works.</p>
-</li>
-<li><p class="first"><strong>register_adapter</strong> function - <tt class="docutils literal"><span class="pre">register_adapter(type,</span> <span class="pre">callable)</span></tt>
-registers a callable to convert the custom Python <strong>type</strong> into one of
-SQLite's supported types. The callable accepts as single parameter the Python
-value, and must return a value of the following types: int, long, float, str
-(UTF-8 encoded), unicode or buffer.</p>
-</li>
-<li><p class="first"><strong>enable_callback_tracebacks</strong> function - <tt class="docutils literal"><span class="pre">enable_callback_tracebacks(flag)</span></tt>
-Can be used to enable displaying tracebacks of exceptions in user-defined functions, aggregates and other callbacks being printed to stderr.
-methods should never raise any exception. This feature is off by default.</p>
-</li>
-<li><p class="first"><strong>Connection</strong> class</p>
-<ul>
-<li><p class="first"><strong>isolation_level</strong> attribute (read-write)</p>
-<p>Get or set the current <em>isolation level</em>: None for autocommit mode or one
-of &quot;DEFERRED&quot;, &quot;IMMEDIATE&quot; or &quot;EXLUSIVE&quot;. See <a class="reference" href="#controlling-transactions">5. Controlling
-Transactions</a> for a more detailed explanation.</p>
-</li>
-<li><p class="first"><strong>cursor method</strong> - The cursor method accepts a single optional parameter:
-a custom cursor class extending pysqlite's <em>Cursor</em> class that you can
-adapt to your needs. Note that it is required that your custom cursor class
-extends pysqlite's <em>Cursor</em> class.</p>
-</li>
-<li><p class="first"><strong>execute method</strong> - Nonstandard - this works as a shortcut for not having
-to create a cursor object and is implemented like this:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">Connection</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">execute</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">*</span><span class="p_identifier">args</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(*</span><span class="p_identifier">args</span><span class="p_operator">)</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span>
-</div>
-</blockquote>
-</li>
-<li><p class="first"><strong>executemany method</strong> - Nonstandard - The same shortcut as the nonstandard
-<tt class="docutils literal"><span class="pre">execute</span></tt> method.</p>
-</li>
-<li><p class="first"><strong>executesript method</strong> - Nonstandard - The same shortcut as the nonstandard
-<tt class="docutils literal"><span class="pre">execute</span></tt> method.</p>
-</li>
-<li><p class="first"><strong>row_factory</strong> attribute (read-write)</p>
-<p>You can change this attribute to a callable that accepts the cursor and
-the original row as tuple and will return the real result row.  This
-way, you can implement more advanced ways of returning results, like
-ones that can also access columns by name.</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">dict_factory</span><span class="p_operator">(</span><span class="p_identifier">cursor</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">d</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_operator">{}</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">idx</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">col</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">enumerate</span><span class="p_operator">(</span><span class="p_identifier">cursor</span><span class="p_operator">.</span><span class="p_identifier">description</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">d</span><span class="p_operator">[</span><span class="p_identifier">col</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]]</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_identifier">idx</span><span class="p_operator">]</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">d</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">row_factory</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">dict_factory</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;1&nbsp;as&nbsp;a"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_string">"a"</span><span class="p_operator">]</span>
-</div>
-<p>If the standard tuple types don't suffice for you, and you want name-based
-access to columns, you should consider setting <tt class="docutils literal"><span class="pre">row_factory</span></tt> to the
-highly-optimized <tt class="docutils literal"><span class="pre">pysqlite2.dbapi2.Row</span></tt> type. It provides both
-index-based and case-insensitive name-based access to columns with almost
-no memory overhead. Much better than your own custom dictionary-based
-approach or even a <tt class="docutils literal"><span class="pre">db_row</span></tt> based solution.</p>
-</li>
-<li><p class="first"><strong>text_factory</strong> attribute (read-write)</p>
-<p>Using this attribute you can control what objects pysqlite returns for the
-TEXT data type. By default, this attribute is set to <tt class="docutils literal"><span class="pre">unicode</span></tt> and
-pysqlite will return Unicode objects for TEXT. If you want to return
-bytestrings instead, you can set it to <tt class="docutils literal"><span class="pre">str</span></tt>.</p>
-<p>For efficiency reasons, there's also a way to return Unicode objects only
-for non-ASCII data, and bytestrings otherwise. To activate it, set this
-attribute to <tt class="docutils literal"><span class="pre">pysqlite2.dbapi2.OptimizedUnicode</span></tt>.</p>
-<p>You can also set it to any other callable that accepts a single bytestring
-parameter and returns the result object.</p>
-<p>See the following example code for illustration:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Create&nbsp;the&nbsp;table</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;person(lastname,&nbsp;firstname)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">AUSTRIA</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">u"\xd6sterreich"</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;by&nbsp;default,&nbsp;rows&nbsp;are&nbsp;returned&nbsp;as&nbsp;Unicode</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">AUSTRIA</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">AUSTRIA</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;but&nbsp;we&nbsp;can&nbsp;make&nbsp;pysqlite&nbsp;always&nbsp;return&nbsp;bytestrings&nbsp;...</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">text_factory</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">str</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">AUSTRIA</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">])</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">str</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;the&nbsp;bytestrings&nbsp;will&nbsp;be&nbsp;encoded&nbsp;in&nbsp;UTF-8,&nbsp;unless&nbsp;you&nbsp;stored&nbsp;garbage&nbsp;in&nbsp;the</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;database&nbsp;...</span><span class="p_default"><br/>
-</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">AUSTRIA</span><span class="p_operator">.</span><span class="p_identifier">encode</span><span class="p_operator">(</span><span class="p_string">"utf-8"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;we&nbsp;can&nbsp;also&nbsp;implement&nbsp;a&nbsp;custom&nbsp;text_factory&nbsp;...</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;here&nbsp;we&nbsp;implement&nbsp;one&nbsp;that&nbsp;will&nbsp;ignore&nbsp;Unicode&nbsp;characters&nbsp;that&nbsp;cannot&nbsp;be</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;decoded&nbsp;from&nbsp;UTF-8</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">text_factory</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_word">lambda</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">:</span><span class="p_default">&nbsp;</span><span class="p_identifier">unicode</span><span class="p_operator">(</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"utf-8"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"ignore"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_string">"this&nbsp;is&nbsp;latin1&nbsp;and&nbsp;would&nbsp;normally&nbsp;create&nbsp;errors"</span><span class="p_default">&nbsp;</span><span class="p_operator">+</span><span class="p_default">&nbsp;</span><span class="p_string">u"\xe4\xf6\xfc"</span><span class="p_operator">.</span><span class="p_identifier">encode</span><span class="p_operator">(</span><span class="p_string">"latin1"</span><span class="p_operator">),))</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">])</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">unicode</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;pysqlite&nbsp;offers&nbsp;a&nbsp;builtin&nbsp;optimized&nbsp;text_factory&nbsp;that&nbsp;will&nbsp;return&nbsp;bytestring</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;objects,&nbsp;if&nbsp;the&nbsp;data&nbsp;is&nbsp;in&nbsp;ASCII&nbsp;only,&nbsp;and&nbsp;otherwise&nbsp;return&nbsp;unicode&nbsp;objects</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">text_factory</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">OptimizedUnicode</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">AUSTRIA</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">])</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">unicode</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_string">"Germany"</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">])</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">str</span><span class="p_default"><br/>
-</span>
-</div>
-</blockquote>
-</li>
-<li><p class="first"><strong>total_changes</strong> attribute (read-only)</p>
-<p>Returns the total number of database rows that have be modified, inserted,
-or deleted since the database connection was opened.</p>
-</li>
-</ul>
-<div class="line-block">
-<div class="line"><br /></div>
-</div>
-</li>
-<li><p class="first"><strong>Cursor</strong> class</p>
-<ul>
-<li><p class="first"><strong>execute</strong> method</p>
-<p>pysqlite uses <em>paramstyle = &quot;qmark&quot;</em>. That means if you use parametrized
-statements, you use the question mark as placeholder.</p>
-<p>This is a basic example showing the use of question marks as placeholders
-and a parameter tuple:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">who</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">"Yeltsin"</span><span class="p_default"><br/>
-</span><span class="p_identifier">age</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_number">72</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;name_last,&nbsp;age&nbsp;from&nbsp;people&nbsp;where&nbsp;name_last=?&nbsp;and&nbsp;age=?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">who</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">age</span><span class="p_operator">))</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span>
-</div>
-<p>pysqlite also supports <em>paramstyle = &quot;named&quot;</em>. That means you can use named
-placeholders in the format &quot;:name&quot;, i. e. a colon followed by the parameter
-name. As parameters, you then supply a mapping instead of a sequence. In
-the simplest case, a dictionary instead of a tuple.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">who</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">"Yeltsin"</span><span class="p_default"><br/>
-</span><span class="p_identifier">age</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_number">72</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;name_last,&nbsp;age&nbsp;from&nbsp;people&nbsp;where&nbsp;name_last=:who&nbsp;and&nbsp;age=:age"</span><span class="p_operator">,</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">{</span><span class="p_string">"who"</span><span class="p_operator">:</span><span class="p_default">&nbsp;</span><span class="p_identifier">who</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"age"</span><span class="p_operator">:</span><span class="p_default">&nbsp;</span><span class="p_identifier">age</span><span class="p_operator">})</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span>
-</div>
-<p>The following example shows a shortcut that you can often use when using
-named parameters. It exploits the fact that locals() is a dictionary, too.
-So you can also use it as parameter for <em>execute</em>:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">who</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">"Yeltsin"</span><span class="p_default"><br/>
-</span><span class="p_identifier">age</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_number">72</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;name_last,&nbsp;age&nbsp;from&nbsp;people&nbsp;where&nbsp;name_last=:who&nbsp;and&nbsp;age=:age"</span><span class="p_operator">,</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">locals</span><span class="p_operator">())</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span>
-</div>
-<p><em>execute</em> will only execute a single SQL statement. If you try to execute
-more than one statement with it, it will raise a Warning. Use
-<em>executescript</em> if want to execute multiple SQL statements with one call.</p>
-</li>
-<li><p class="first"><strong>executemany</strong> method</p>
-<p>The DB-API specifies the executemany method like this:</p>
-<div class="code-block">
-<span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_identifier">operation</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">seq_of_parameters</span><span class="p_operator">)</span>
-</div>
-<p>pysqlite, however, extends <em>executemany</em> so it can be used more efficiently
-for inserting bulk data. The second parameter to <em>executemany</em> can be a
-<em>sequence of parameters</em>, but it can also be an <em>iterator</em> returning
-parameters.</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">IterChars</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">ord</span><span class="p_operator">(</span><span class="p_character">'a'</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__iter__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">next</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default">&nbsp;</span><span class="p_operator">&gt;</span><span class="p_default">&nbsp;</span><span class="p_identifier">ord</span><span class="p_operator">(</span><span class="p_character">'z'</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">raise</span><span class="p_default">&nbsp;</span><span class="p_identifier">StopIteration</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default">&nbsp;</span><span class="p_operator">+=</span><span class="p_default">&nbsp;</span><span class="p_number">1</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">chr</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default">&nbsp;</span><span class="p_operator">-</span><span class="p_default">&nbsp;</span><span class="p_number">1</span><span class="p_operator">),)</span><span class="p_default">&nbsp;</span><span class="p_commentline">#&nbsp;this&nbsp;is&nbsp;a&nbsp;1-tuple</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;characters(c)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">theIter</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">IterChars</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;characters(c)&nbsp;values&nbsp;(?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">theIter</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;c&nbsp;from&nbsp;characters"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchall</span><span class="p_operator">()</span>
-</div>
-<p>As generators are iterators, too, here's a much simpler, equivalent example
-using a generator:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">char_generator</span><span class="p_operator">():</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">string</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">c</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">string</span><span class="p_operator">.</span><span class="p_identifier">letters</span><span class="p_operator">[:</span><span class="p_number">26</span><span class="p_operator">]:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">yield</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">c</span><span class="p_operator">,)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;characters(c)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;characters(c)&nbsp;values&nbsp;(?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">char_generator</span><span class="p_operator">())</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;c&nbsp;from&nbsp;characters"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchall</span><span class="p_operator">()</span>
-</div>
-<p><em>executemany</em> will only execute a single SQL statement. If you try to
-execute more than one statement with it, it will raise a Warning. Use
-<em>executescript</em> if want to execute multiple SQL statements with one call.</p>
-</li>
-<li><p class="first"><strong>executescript</strong> method</p>
-<div class="code-block">
-<span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_identifier">sqlscript</span><span class="p_operator">)</span>
-</div>
-<p>This is a nonstandard convenience method for executing multiple SQL
-statements at once. It issues a COMMIT statement before, then executes the
-SQL script it gets as a parameter.</p>
-<p>The SQL script <tt class="docutils literal"><span class="pre">sqlscript</span></tt> can be a bytestring or a Unicode string.</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">executescript</span><span class="p_operator">(</span><span class="p_tripledouble">"""<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;create&nbsp;table&nbsp;person(<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstname,<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lastname,<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;age<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;);<br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;create&nbsp;table&nbsp;book(<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title,<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;author,<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;published<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;);<br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;insert&nbsp;into&nbsp;book(title,&nbsp;author,&nbsp;published)<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;values&nbsp;(<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Dirk&nbsp;Gently''s&nbsp;Holistic&nbsp;Detective&nbsp;Agency<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Douglas&nbsp;Adams',<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1987<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;);<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;"""</span><span class="p_operator">)</span>
-</div>
-</li>
-<li><p class="first"><strong>interrupt</strong> method</p>
-<p>This method has no arguments. You can call it from a different thread to
-abort any queries that are currently executing on the connection. This can
-be used to let the user abort runaway queries, for example.</p>
-</li>
-<li><p class="first"><strong>rowcount</strong> attribute</p>
-<p>Although pysqlite's Cursors implement this attribute, the database
-engine's own support for the determination of &quot;rows affected&quot;/&quot;rows
-selected&quot; is quirky.</p>
-<p>For <tt class="docutils literal"><span class="pre">SELECT</span></tt> statements, <em>rowcount</em> is always -1 because pysqlite
-cannot determine the number of rows a query produced until all rows
-were fetched.</p>
-<p>For <tt class="docutils literal"><span class="pre">DELETE</span></tt> statements, SQLite reports <em>rowcount</em> as 0 if you make a
-<tt class="docutils literal"><span class="pre">DELETE</span> <span class="pre">FROM</span> <span class="pre">table</span></tt> without any condition.</p>
-<p>For <em>executemany</em> statements, pysqlite sums up the number of
-modifications into <em>rowcount</em>.</p>
-<p>As required by the Python DB API Spec, the <em>rowcount</em> attribute &quot;is -1
-in case no executeXX() has been performed on the cursor or the rowcount
-of the last operation is not determinable by the interface&quot;.</p>
-</li>
-</ul>
-</li>
-</ul>
-<div class="line-block">
-<div class="line"><br /></div>
-</div>
-<hr class="docutils" />
-<div class="line-block">
-<div class="line"><br /></div>
-</div>
-</div>
-</div>
-<div class="section">
-<h1><a id="brief-tutorial" name="brief-tutorial">2. Brief Tutorial</a></h1>
-<p>This brief tutorial aims to get the reader started by demonstrating elementary
-usage of pysqlite. It is not a comprehensive Python Database API tutorial, nor
-is it comprehensive in its coverage of anything else.</p>
-<div class="section">
-<h2><a id="connecting-to-a-database" name="connecting-to-a-database">2.1 Connecting to a Database</a></h2>
-<blockquote>
-<p><strong>Example 1</strong></p>
-<p>Connecting to a database file <em>mydb</em>:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span>
-</div>
-<p><strong>Example 2</strong></p>
-<p>Creating an in-memory database:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span>
-</div>
-</blockquote>
-</div>
-<div class="section">
-<h2><a id="executing-sql-statements" name="executing-sql-statements">2.2 Executing SQL statements</a></h2>
-<p>For this section, we have a database <em>mydb</em> defined and populated by the
-following SQL code:</p>
-<blockquote>
-<div class="code-block">
-<span class="c_identifier">create</span><span class="c_default">&nbsp;</span><span class="c_identifier">table</span><span class="c_default">&nbsp;</span><span class="c_identifier">people</span><span class="c_default"><br/>
-</span><span class="c_operator">(</span><span class="c_default"><br/>
-&nbsp;&nbsp;</span><span class="c_identifier">name_last</span><span class="c_default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c_identifier">varchar</span><span class="c_operator">(</span><span class="c_number">20</span><span class="c_operator">),</span><span class="c_default"><br/>
-&nbsp;&nbsp;</span><span class="c_identifier">age</span><span class="c_default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c_identifier">integer</span><span class="c_default"><br/>
-</span><span class="c_operator">);</span><span class="c_default"><br/>
-<br/>
-</span><span class="c_identifier">insert</span><span class="c_default">&nbsp;</span><span class="c_identifier">into</span><span class="c_default">&nbsp;</span><span class="c_identifier">people</span><span class="c_default">&nbsp;</span><span class="c_operator">(</span><span class="c_identifier">name_last</span><span class="c_operator">,</span><span class="c_default">&nbsp;</span><span class="c_identifier">age</span><span class="c_operator">)</span><span class="c_default">&nbsp;</span><span class="c_identifier">values</span><span class="c_default">&nbsp;</span><span class="c_operator">(</span><span class="c_character">'Yeltsin'</span><span class="c_operator">,</span><span class="c_default">&nbsp;&nbsp;&nbsp;</span><span class="c_number">72</span><span class="c_operator">);</span><span class="c_default"><br/>
-</span><span class="c_identifier">insert</span><span class="c_default">&nbsp;</span><span class="c_identifier">into</span><span class="c_default">&nbsp;</span><span class="c_identifier">people</span><span class="c_default">&nbsp;</span><span class="c_operator">(</span><span class="c_identifier">name_last</span><span class="c_operator">,</span><span class="c_default">&nbsp;</span><span class="c_identifier">age</span><span class="c_operator">)</span><span class="c_default">&nbsp;</span><span class="c_identifier">values</span><span class="c_default">&nbsp;</span><span class="c_operator">(</span><span class="c_character">'Putin'</span><span class="c_operator">,</span><span class="c_default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c_number">51</span><span class="c_operator">);</span>
-</div>
-</blockquote>
-<p><em>Example 1</em></p>
-<p>This example shows the simplest way to print the entire contents of the <tt class="docutils literal"><span class="pre">people</span></tt> table:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Create&nbsp;a&nbsp;connection&nbsp;to&nbsp;the&nbsp;database&nbsp;file&nbsp;"mydb":</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Get&nbsp;a&nbsp;Cursor&nbsp;object&nbsp;that&nbsp;operates&nbsp;in&nbsp;the&nbsp;context&nbsp;of&nbsp;Connection&nbsp;con:</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Execute&nbsp;the&nbsp;SELECT&nbsp;statement:</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;*&nbsp;from&nbsp;people&nbsp;order&nbsp;by&nbsp;age"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Retrieve&nbsp;all&nbsp;rows&nbsp;as&nbsp;a&nbsp;sequence&nbsp;and&nbsp;print&nbsp;that&nbsp;sequence:</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchall</span><span class="p_operator">()</span>
-</div>
-<p>Sample output:</p>
-<pre class="literal-block">
-[(u'Putin', 51), (u'Yeltsin', 72)]
-</pre>
-<p><em>Example 2</em></p>
-<p>Here's another trivial example that demonstrates various ways of fetching a
-single row at a time from a SELECT-cursor:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">SELECT</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">"select&nbsp;name_last,&nbsp;age&nbsp;from&nbsp;people&nbsp;order&nbsp;by&nbsp;age,&nbsp;name_last"</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;1.&nbsp;Iterate&nbsp;over&nbsp;the&nbsp;rows&nbsp;available&nbsp;from&nbsp;the&nbsp;cursor,&nbsp;unpacking&nbsp;the</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;resulting&nbsp;sequences&nbsp;to&nbsp;yield&nbsp;their&nbsp;elements&nbsp;(name_last,&nbsp;age):</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_identifier">SELECT</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">name_last</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">age</span><span class="p_operator">)</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_character">'%s&nbsp;is&nbsp;%d&nbsp;years&nbsp;old.'</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">name_last</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">age</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;2.&nbsp;Equivalently:</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_identifier">SELECT</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_character">'%s&nbsp;is&nbsp;%d&nbsp;years&nbsp;old.'</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">],</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">])</span>
-</div>
-<p>Sample output:</p>
-<pre class="literal-block">
-Putin is 51 years old.
-Yeltsin is 72 years old.
-Putin is 51 years old.
-Yeltsin is 72 years old.
-</pre>
-<p><em>Example 3</em></p>
-<p>The following program is a simplistic table printer (applied in this example to
-people)</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">FIELD_MAX_WIDTH</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_number">20</span><span class="p_default"><br/>
-</span><span class="p_identifier">TABLE_NAME</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_character">'people'</span><span class="p_default"><br/>
-</span><span class="p_identifier">SELECT</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_character">'select&nbsp;*&nbsp;from&nbsp;%s&nbsp;order&nbsp;by&nbsp;age,&nbsp;name_last'</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_identifier">TABLE_NAME</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_identifier">SELECT</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Print&nbsp;a&nbsp;header.</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">fieldDesc</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">description</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">fieldDesc</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">].</span><span class="p_identifier">ljust</span><span class="p_operator">(</span><span class="p_identifier">FIELD_MAX_WIDTH</span><span class="p_operator">)</span><span class="p_default">&nbsp;</span><span class="p_operator">,</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_commentline">#&nbsp;Finish&nbsp;the&nbsp;header&nbsp;with&nbsp;a&nbsp;newline.</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_character">'-'</span><span class="p_default">&nbsp;</span><span class="p_operator">*</span><span class="p_default">&nbsp;</span><span class="p_number">78</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;For&nbsp;each&nbsp;row,&nbsp;print&nbsp;the&nbsp;value&nbsp;of&nbsp;each&nbsp;field&nbsp;left-justified&nbsp;within</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;the&nbsp;maximum&nbsp;possible&nbsp;width&nbsp;of&nbsp;that&nbsp;field.</span><span class="p_default"><br/>
-</span><span class="p_identifier">fieldIndices</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">range</span><span class="p_operator">(</span><span class="p_identifier">len</span><span class="p_operator">(</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">description</span><span class="p_operator">))</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">fieldIndex</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">fieldIndices</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">fieldValue</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">str</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_identifier">fieldIndex</span><span class="p_operator">])</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">fieldValue</span><span class="p_operator">.</span><span class="p_identifier">ljust</span><span class="p_operator">(</span><span class="p_identifier">FIELD_MAX_WIDTH</span><span class="p_operator">)</span><span class="p_default">&nbsp;</span><span class="p_operator">,</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_commentline">#&nbsp;Finish&nbsp;the&nbsp;row&nbsp;with&nbsp;a&nbsp;newline.</span>
-</div>
-<p>Sample output:</p>
-<pre class="literal-block">
-name_last            age
-------------------------------------------------------------------------------
-Putin                51
-Yeltsin              72
-</pre>
-<p><em>Example 4</em></p>
-<p>Let's insert more people into the people table:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">newPeople</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">(</span><span class="p_character">'Lebed'</span><span class="p_default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_number">53</span><span class="p_operator">),</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">(</span><span class="p_character">'Zhirinovsky'</span><span class="p_default">&nbsp;</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_number">57</span><span class="p_operator">),</span><span class="p_default"><br/>
-&nbsp;&nbsp;</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">person</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">newPeople</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;people&nbsp;(name_last,&nbsp;age)&nbsp;values&nbsp;(?,&nbsp;?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">person</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;The&nbsp;changes&nbsp;will&nbsp;not&nbsp;be&nbsp;saved&nbsp;unless&nbsp;the&nbsp;transaction&nbsp;is&nbsp;committed&nbsp;explicitly:</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">commit</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span>
-</div>
-<p>Note the use of a parameterized SQL statement above. When dealing with
-repetitive statements, this is much faster and less error-prone than assembling
-each SQL statement manually.</p>
-<p>It's also worth noting that in the example above, the code:</p>
-<p>It's also worth noting that in the example above, the code:</p>
-<div class="code-block">
-<span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">person</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">newPeople</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;people&nbsp;(name_last,&nbsp;age)&nbsp;values&nbsp;(?,&nbsp;?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">person</span><span class="p_operator">)</span>
-</div>
-<p>could be rewritten as:</p>
-<div class="code-block">
-<span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;people&nbsp;(name_last,&nbsp;age)&nbsp;values&nbsp;(?,&nbsp;?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">newPeople</span><span class="p_operator">)</span>
-</div>
-<p>After running Example 4, the table printer from Example 3 would print:</p>
-<pre class="literal-block">
-name_last            age
-------------------------------------------------------------------------------
-Putin                51
-Lebed                53
-Zhirinovsky          57
-Yeltsin              72
-</pre>
-<div class="line-block">
-<div class="line"><br /></div>
-</div>
-<hr class="docutils" />
-<div class="line-block">
-<div class="line"><br /></div>
-</div>
-</div>
-</div>
-<div class="section">
-<h1><a id="native-database-engine-features-and-extensions-beyond-the-python-db-api" name="native-database-engine-features-and-extensions-beyond-the-python-db-api">3. Native Database Engine Features and Extensions Beyond the Python DB API</a></h1>
-<div class="section">
-<h2><a id="creating-user-defined-functions" name="creating-user-defined-functions">3.1 Creating user-defined functions</a></h2>
-<p>SQLite supports user-defined functions.  Using pysqlite, you can create new
-functions with the connection's <strong>create_function</strong> method:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">create_function</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">name</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">numparams</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">func</span><span class="p_operator">)</span>
-</div>
-<dl class="docutils">
-<dt><em>name</em></dt>
-<dd>the name of your function in SQL</dd>
-<dt><em>numparams</em></dt>
-<dd>the number of parameters your function accepts, -1 if it accepts any
-number of parameters</dd>
-<dt><em>func</em></dt>
-<dd>the Python function</dd>
-</dl>
-<p>The function can return any of pysqlite's supported SQLite types: unicode,
-str, int, long, float, buffer and None.  Any exception in the user-defined
-function leads to the SQL statement executed being aborted.</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">md5</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">md5sum</span><span class="p_operator">(</span><span class="p_identifier">t</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">md5</span><span class="p_operator">.</span><span class="p_identifier">md5</span><span class="p_operator">(</span><span class="p_identifier">t</span><span class="p_operator">).</span><span class="p_identifier">hexdigest</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">create_function</span><span class="p_operator">(</span><span class="p_string">"md5"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_number">1</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">md5sum</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;md5(?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_string">"foo"</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span>
-</div>
-</blockquote>
-</div>
-<div class="section">
-<h2><a id="creating-user-defined-aggregates" name="creating-user-defined-aggregates">3.2 Creating user-defined aggregates</a></h2>
-<p>SQLite supports user-defined aggregate functions. Using pysqlite, you can
-create new aggregate functions with the connection's <em>create_aggregate</em> method.</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">create_aggregate</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">name</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">numparams</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">aggregate_class</span><span class="p_operator">)</span>
-</div>
-<p>The aggregate class must implement a <em>step</em> method, which accepts the
-number of parameters defined in <em>create_aggregate</em>, and a <em>finalize</em>
-method which will return the final result of the aggregate.</p>
-<p>The <em>finalize</em> method can return any of pysqlite's supported SQLite types:
-unicode, str, int, long, float, buffer and None. Any exception in the
-aggregate's <em>__init__</em>, <em>step</em> or <em>finalize</em> methods lead to the SQL
-statement executed being aborted.</p>
-<p>Example:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">MySum</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_number">0</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">step</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">value</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default">&nbsp;</span><span class="p_operator">+=</span><span class="p_default">&nbsp;</span><span class="p_identifier">value</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">finalize</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">count</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">create_aggregate</span><span class="p_operator">(</span><span class="p_string">"mysum"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_number">1</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">MySum</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;test(i)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;test(i)&nbsp;values&nbsp;(1)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;test(i)&nbsp;values&nbsp;(2)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;mysum(i)&nbsp;from&nbsp;test"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span>
-</div>
-</blockquote>
-</div>
-<div class="section">
-<h2><a id="creating-and-using-collations" name="creating-and-using-collations">3.3 Creating and using collations</a></h2>
-<blockquote>
-<div class="code-block">
-<span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">create_collation</span><span class="p_operator">(</span><span class="p_identifier">name</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">callable</span><span class="p_operator">)</span>
-</div>
-</blockquote>
-<p>Creates a collation with the specified name and callable. The callable will be
-passed two string arguments. It should return -1 if the first is less than the
-second, 0 if they are equal and 1 and if the first is greater than the second.
-Note that this controls sorting (ORDER BY in SQL) so your comparisons don't
-affect other SQL operations. Read more about SQLite's handling of collations.
-(This calls sqlite3_create_collation.) If there is an error in your Python code
-then 0 (ie items are equal) is returned.</p>
-<p>Note that the callable will get its parameters as Python bytestrings, which
-will normally be encoded in UTF-8.</p>
-<p>The following example shows a custom collation that sorts &quot;the wrong way&quot;:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">collate_reverse</span><span class="p_operator">(</span><span class="p_identifier">string1</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">string2</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_operator">-</span><span class="p_identifier">cmp</span><span class="p_operator">(</span><span class="p_identifier">string1</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">string2</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">create_collation</span><span class="p_operator">(</span><span class="p_string">"reverse"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">collate_reverse</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;test(x)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;test(x)&nbsp;values&nbsp;(?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">[(</span><span class="p_string">"a"</span><span class="p_operator">,),</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_string">"b"</span><span class="p_operator">,)])</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;x&nbsp;from&nbsp;test&nbsp;order&nbsp;by&nbsp;x&nbsp;collate&nbsp;reverse"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">close</span><span class="p_operator">()</span>
-</div>
-</blockquote>
-<p>To remove a collation, call <cite>create_collation</cite> with None as callable:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">create_collation</span><span class="p_operator">(</span><span class="p_string">"reverse"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_word">None</span><span class="p_operator">)</span>
-</div>
-</blockquote>
-</div>
-<div class="section">
-<h2><a id="checking-for-complete-statements" name="checking-for-complete-statements">3.4 Checking for complete statements</a></h2>
-<p>The module-level function <em>complete_statement(sql)</em> can be used to check if a
-string contains a complete SQL statement or is still incomplete. The given
-string could still contain invalid SQL, but be parsable as a &quot;complete&quot;
-statement!</p>
-<p>This can be used to build a shell for SQLite, like in the following example:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_commentline">#&nbsp;A&nbsp;minimal&nbsp;SQLite&nbsp;shell&nbsp;for&nbsp;experiments</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">isolation_level</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_word">None</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">buffer</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">""</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"Enter&nbsp;your&nbsp;SQL&nbsp;commands&nbsp;to&nbsp;execute&nbsp;in&nbsp;SQLite."</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"Enter&nbsp;a&nbsp;blank&nbsp;line&nbsp;to&nbsp;exit."</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">while</span><span class="p_default">&nbsp;</span><span class="p_identifier">True</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">line</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">raw_input</span><span class="p_operator">()</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">line</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_string">""</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">break</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">buffer</span><span class="p_default">&nbsp;</span><span class="p_operator">+=</span><span class="p_default">&nbsp;</span><span class="p_identifier">line</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">complete_statement</span><span class="p_operator">(</span><span class="p_identifier">buffer</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">try</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">buffer</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">buffer</span><span class="p_operator">.</span><span class="p_identifier">strip</span><span class="p_operator">()</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_identifier">buffer</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">buffer</span><span class="p_operator">.</span><span class="p_identifier">lstrip</span><span class="p_operator">().</span><span class="p_identifier">upper</span><span class="p_operator">().</span><span class="p_identifier">startswith</span><span class="p_operator">(</span><span class="p_string">"SELECT"</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchall</span><span class="p_operator">()</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">except</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">Error</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">e</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"An&nbsp;error&nbsp;occured:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">e</span><span class="p_operator">.</span><span class="p_identifier">args</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">buffer</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_string">""</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">close</span><span class="p_operator">()</span>
-</div>
-</blockquote>
-</div>
-<div class="section">
-<h2><a id="enabling-sqlite-s-shared-cache" name="enabling-sqlite-s-shared-cache">3.5 Enabling SQLite's shared cache</a></h2>
-<p>To enable SQLite's shared cache for the calling thread, call the function
-<em>enable_shared_cache</em>.</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;The&nbsp;shared&nbsp;cache&nbsp;is&nbsp;only&nbsp;available&nbsp;in&nbsp;SQLite&nbsp;versions&nbsp;3.3.3&nbsp;or&nbsp;later</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;See&nbsp;the&nbsp;SQLite&nbsp;documentaton&nbsp;for&nbsp;details.</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">enable_shared_cache</span><span class="p_operator">(</span><span class="p_identifier">True</span><span class="p_operator">)</span>
-</div>
-</blockquote>
-</div>
-<div class="section">
-<h2><a id="setting-an-authorizer-callback" name="setting-an-authorizer-callback">3.6 Setting an authorizer callback</a></h2>
-<p>You can set an authorizer callback if you want to restrict what your users can
-do with the database. This is mostly useful if you accept arbitrary SQL from
-users and want to execute it safely. See the relevant section in the SQL
-documentation for details:
-<a class="reference" href="http://sqlite.org/capi3ref.html#sqlite3_set_authorizer">http://sqlite.org/capi3ref.html#sqlite3_set_authorizer</a></p>
-<p>All necessary constants like SQLITE_OK, SQLITE_DENY, SQLITE_IGNORE,
-SQLITE_SELECT, SQLITE_CREATE_INDEX and all other authorizer-related constants
-are available through the dbapi2 module.</p>
-<p>Here's an example that demonstrates the usage of this function:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">authorizer_callback</span><span class="p_operator">(</span><span class="p_identifier">action</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">arg1</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">arg2</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbname</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">source</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">action</span><span class="p_default">&nbsp;</span><span class="p_operator">!=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">SQLITE_SELECT</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">SQLITE_DENY</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">arg1</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_string">"private_table"</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">SQLITE_DENY</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">SQLITE_OK</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">executescript</span><span class="p_operator">(</span><span class="p_tripledouble">"""<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;create&nbsp;table&nbsp;public_table(c1,&nbsp;c2);<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;create&nbsp;table&nbsp;private_table(c1,&nbsp;c2);<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;"""</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">set_authorizer</span><span class="p_operator">(</span><span class="p_identifier">authorizer_callback</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">try</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;*&nbsp;from&nbsp;private_table"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">except</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">DatabaseError</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">e</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"SELECT&nbsp;FROM&nbsp;private_table&nbsp;=&gt;"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">e</span><span class="p_operator">.</span><span class="p_identifier">args</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_commentline">#&nbsp;access&nbsp;...&nbsp;prohibited</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">try</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;public_table(c1,&nbsp;c2)&nbsp;values&nbsp;(1,&nbsp;2)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">except</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">DatabaseError</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">e</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"DML&nbsp;command&nbsp;=&gt;"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">e</span><span class="p_operator">.</span><span class="p_identifier">args</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_commentline">#&nbsp;access&nbsp;...&nbsp;prohibited</span><span class="p_default"><br/>
-</span>
-</div>
-</blockquote>
-</div>
-</div>
-<div class="section">
-<h1><a id="sqlite-and-python-types" name="sqlite-and-python-types">4. SQLite and Python types</a></h1>
-<div class="section">
-<h2><a id="id1" name="id1">4.1 Introduction</a></h2>
-<p><a class="reference" href="http://sqlite.org/datatype3.html">http://sqlite.org/datatype3.html</a></p>
-<p>SQLite natively supports the following types: NULL, INTEGER, REAL, TEXT, BLOB.</p>
-<p>The following Python types can thus be sent to SQLite without any problem:</p>
-<table border="1" class="docutils">
-<colgroup>
-<col width="67%" />
-<col width="33%" />
-</colgroup>
-<thead valign="bottom">
-<tr><th class="head">Python type</th>
-<th class="head">SQLite type</th>
-</tr>
-</thead>
-<tbody valign="top">
-<tr><td>NoneType</td>
-<td>NULL</td>
-</tr>
-<tr><td>int</td>
-<td>INTEGER</td>
-</tr>
-<tr><td>long</td>
-<td>INTEGER</td>
-</tr>
-<tr><td>float</td>
-<td>REAL</td>
-</tr>
-<tr><td>str (utf-8 encoded)</td>
-<td>TEXT</td>
-</tr>
-<tr><td>unicode</td>
-<td>TEXT</td>
-</tr>
-<tr><td>buffer</td>
-<td>BLOB</td>
-</tr>
-</tbody>
-</table>
-<p>This is how SQLite types are converted to Python types by default:</p>
-<table border="1" class="docutils">
-<colgroup>
-<col width="27%" />
-<col width="73%" />
-</colgroup>
-<thead valign="bottom">
-<tr><th class="head">SQLite type</th>
-<th class="head">Python type</th>
-</tr>
-</thead>
-<tbody valign="top">
-<tr><td>NULL</td>
-<td>NoneType</td>
-</tr>
-<tr><td>INTEGER</td>
-<td>int or long, depending on size</td>
-</tr>
-<tr><td>REAL</td>
-<td>float</td>
-</tr>
-<tr><td>TEXT</td>
-<td>unicode</td>
-</tr>
-<tr><td>BLOB</td>
-<td>buffer</td>
-</tr>
-</tbody>
-</table>
-<p>pysqlite's type system is extensible in both ways: you can store additional
-Python types in a SQLite database via object adaptation, and you can let
-pysqlite convert SQLite types to different Python types via pysqlite's
-converters.</p>
-</div>
-<div class="section">
-<h2><a id="using-adapters-to-store-additional-python-types-in-sqlite-databases" name="using-adapters-to-store-additional-python-types-in-sqlite-databases">4.2 Using adapters to store additional Python types in SQLite databases</a></h2>
-<p>Like described before, SQLite supports only a limited set of types natively. To
-use other Python types with SQLite, you must <em>adapt</em> them to one of pysqlite's
-supported types for SQLite. So, one of NoneType, int, long, float, str,
-unicode, buffer.</p>
-<p>pysqlite uses the Python object adaptation, like described in PEP 246 for this.
-The protocol to use is <tt class="docutils literal"><span class="pre">PrepareProtocol</span></tt>.</p>
-<p>There are two ways to enable pysqlite to adapt a custom Python type to one of
-the supported ones.</p>
-</div>
-<div class="section">
-<h2><a id="letting-your-object-adapt-itself" name="letting-your-object-adapt-itself">4.2.1 Letting your object adapt itself</a></h2>
-<p>This is a good approach if you write the class yourself. Let's suppose you have
-a class like this:</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">Point</span><span class="p_operator">(</span><span class="p_identifier">object</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span>
-</div>
-</blockquote>
-<p>Now you want to store the point in a single SQLite column. You'll have to
-choose one of the supported types first that you use to represent the point in.
-Let's just use str and separate the coordinates using a semicolon. Then you
-need to give your class a method <tt class="docutils literal"><span class="pre">__conform__(self,</span> <span class="pre">protocol)</span></tt> which must
-return the converted value. The parameter <tt class="docutils literal"><span class="pre">protocol</span></tt> will be
-<tt class="docutils literal"><span class="pre">PrepareProtocol</span></tt>.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">Point</span><span class="p_operator">(</span><span class="p_identifier">object</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__conform__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">protocol</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">if</span><span class="p_default">&nbsp;</span><span class="p_identifier">protocol</span><span class="p_default">&nbsp;</span><span class="p_word">is</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">PrepareProtocol</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_string">"%f;%f"</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">p</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">Point</span><span class="p_operator">(</span><span class="p_number">4.0</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">-</span><span class="p_number">3.2</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">p</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default"><br/>
-</span>
-</div>
-</div>
-<div class="section">
-<h2><a id="registering-an-adapter-callable" name="registering-an-adapter-callable">4.2.2 Registering an adapter callable</a></h2>
-<p>The other possibility is to create a function that converts the type to the
-string representation and register the function with <tt class="docutils literal"><span class="pre">register_adapter</span></tt>.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">Point</span><span class="p_operator">(</span><span class="p_identifier">object</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">adapt_point</span><span class="p_operator">(</span><span class="p_identifier">point</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_string">"%f;%f"</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">point</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">point</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">register_adapter</span><span class="p_operator">(</span><span class="p_identifier">Point</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">adapt_point</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">p</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">Point</span><span class="p_operator">(</span><span class="p_number">4.0</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">-</span><span class="p_number">3.2</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">p</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default"><br/>
-</span>
-</div>
-<p>The type/class to adapt must be a new-style class, i. e. it must have
-<tt class="docutils literal"><span class="pre">object</span></tt> as one of its bases!!!</p>
-<p>pysqlite has two default adapters for Python's builtin <em>date</em> and <em>datetime</em>
-types. Now let's suppose we want to store <em>datetime</em> objects not in ISO
-representation, but as Unix timestamp.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">datetime</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">time</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">adapt_datetime</span><span class="p_operator">(</span><span class="p_identifier">ts</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">time</span><span class="p_operator">.</span><span class="p_identifier">mktime</span><span class="p_operator">(</span><span class="p_identifier">ts</span><span class="p_operator">.</span><span class="p_identifier">timetuple</span><span class="p_operator">())</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">register_adapter</span><span class="p_operator">(</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">datetime</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">adapt_datetime</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">now</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">now</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;?"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">now</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span>
-</div>
-</div>
-<div class="section">
-<h2><a id="converting-sqlite-values-to-custom-python-types" name="converting-sqlite-values-to-custom-python-types">4.3 Converting SQLite values to custom Python types</a></h2>
-<p>Now that's all nice and dandy that you can send custom Python types to SQLite.
-But to make it really useful we need to make the Python to SQLite to Python
-roundtrip work.</p>
-<p>Enter pysqlite converters.</p>
-<p>Let's go back to the Point class. We stored the x and y coordinates separated
-via semicolons as strings in SQLite.</p>
-<p>Let's first define a converter function that accepts the string as a parameter and constructs a Point object from it.</p>
-<p>!!! Note that converter functions <em>always</em> get called with a string, no matter
-under which data type you sent the value to SQLite !!!</p>
-<blockquote>
-<div class="code-block">
-<span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">convert_point</span><span class="p_operator">(</span><span class="p_identifier">s</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">map</span><span class="p_operator">(</span><span class="p_identifier">float</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">s</span><span class="p_operator">.</span><span class="p_identifier">split</span><span class="p_operator">(</span><span class="p_string">";"</span><span class="p_operator">))</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">Point</span><span class="p_operator">(</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_operator">)</span>
-</div>
-</blockquote>
-<p>Now you need to make pysqlite know that what you select from the database is
-actually a point. There are two ways of doing this:</p>
-<blockquote>
-<ul class="simple">
-<li>Implicitly via the declared type</li>
-<li>Explicitly via the column name</li>
-</ul>
-</blockquote>
-<p>Both ways are described in section <a class="reference" href="#extensions-and-caveats">1.4 Extensions and Caveats</a> in the
-paragraphs describing the connect function, and specifically the meaning of the
-<em>detect_types</em> parameter.</p>
-<p>The following example illustrates both ways.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">class</span><span class="p_default">&nbsp;</span><span class="p_classname">Point</span><span class="p_operator">(</span><span class="p_identifier">object</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__init__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_default"><br/>
-<br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">__repr__</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_string">"(%f;%f)"</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">adapt_point</span><span class="p_operator">(</span><span class="p_identifier">point</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_string">"%f;%f"</span><span class="p_default">&nbsp;</span><span class="p_operator">%</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">point</span><span class="p_operator">.</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">point</span><span class="p_operator">.</span><span class="p_identifier">y</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_word">def</span><span class="p_default">&nbsp;</span><span class="p_defname">convert_point</span><span class="p_operator">(</span><span class="p_identifier">s</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">map</span><span class="p_operator">(</span><span class="p_identifier">float</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">s</span><span class="p_operator">.</span><span class="p_identifier">split</span><span class="p_operator">(</span><span class="p_string">";"</span><span class="p_operator">))</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">return</span><span class="p_default">&nbsp;</span><span class="p_identifier">Point</span><span class="p_operator">(</span><span class="p_identifier">x</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">y</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Register&nbsp;the&nbsp;adapter</span><span class="p_default"><br/>
-</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">register_adapter</span><span class="p_operator">(</span><span class="p_identifier">Point</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">adapt_point</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Register&nbsp;the&nbsp;converter</span><span class="p_default"><br/>
-</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">register_converter</span><span class="p_operator">(</span><span class="p_string">"point"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">convert_point</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">p</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">Point</span><span class="p_operator">(</span><span class="p_number">4.0</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">-</span><span class="p_number">3.2</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentblock">#########################</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;1)&nbsp;Using&nbsp;declared&nbsp;types</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">detect_types</span><span class="p_operator">=</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">PARSE_DECLTYPES</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;test(p&nbsp;point)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;test(p)&nbsp;values&nbsp;(?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">p</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;p&nbsp;from&nbsp;test"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"with&nbsp;declared&nbsp;types:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">close</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">close</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentblock">#######################</span><span class="p_default"><br/>
-</span><span class="p_commentline">#&nbsp;1)&nbsp;Using&nbsp;column&nbsp;names</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">detect_types</span><span class="p_operator">=</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">PARSE_COLNAMES</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;test(p)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;test(p)&nbsp;values&nbsp;(?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">p</span><span class="p_operator">,))</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_character">'select&nbsp;p&nbsp;as&nbsp;"p&nbsp;[point]"&nbsp;from&nbsp;test'</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"with&nbsp;column&nbsp;names:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">close</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">close</span><span class="p_operator">()</span>
-</div>
-</div>
-<div class="section">
-<h2><a id="default-pysqlite-adapters-and-converters" name="default-pysqlite-adapters-and-converters">4.4 Default pysqlite adapters and converters</a></h2>
-<p>pysqlite has default adapters for the date and datetime types in the datetime
-module. They will be sent as ISO dates/ISO timestamps to SQLite.</p>
-<p>pysqlite has default converters registered under the name &quot;date&quot; for
-datetime.date and under the name &quot;timestamp&quot; for datetime.datetime.</p>
-<p>This way, you can use date/timestamps from pysqlite without any additional
-fiddling in most cases. The format of the adapters is also compatible with the
-experimental SQLite date/time functions.</p>
-<p>The following example demonstrates this.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">datetime</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">detect_types</span><span class="p_operator">=</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">PARSE_DECLTYPES</span><span class="p_operator">|</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">PARSE_COLNAMES</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;test(d&nbsp;date,&nbsp;ts&nbsp;timestamp)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">today</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">date</span><span class="p_operator">.</span><span class="p_identifier">today</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">now</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">datetime</span><span class="p_operator">.</span><span class="p_identifier">now</span><span class="p_operator">()</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;test(d,&nbsp;ts)&nbsp;values&nbsp;(?,&nbsp;?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_operator">(</span><span class="p_identifier">today</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">now</span><span class="p_operator">))</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;d,&nbsp;ts&nbsp;from&nbsp;test"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">today</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"=&gt;"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">],</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">])</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">now</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"=&gt;"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">],</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">])</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_character">'select&nbsp;current_date&nbsp;as&nbsp;"d&nbsp;[date]",&nbsp;current_timestamp&nbsp;as&nbsp;"ts&nbsp;[timestamp]"'</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">fetchone</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"current_date"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">],</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">])</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"current_timestamp"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">],</span><span class="p_default">&nbsp;</span><span class="p_identifier">type</span><span class="p_operator">(</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">])</span>
-</div>
-</div>
-<div class="section">
-<h2><a id="controlling-transactions" name="controlling-transactions">5. Controlling Transactions</a></h2>
-<p>By default, pysqlite opens transactions implicitly before a DML statement
-(<em>INSERT/UPDATE/DELETE/REPLACE</em>), and commits transactions implicitly before a
-non-DML, non-DQL statement (i. e. anything other than
-<em>SELECT/INSERT/UPDATE/DELETE/REPLACE</em>).</p>
-<p>So if you are within a transaction, and issue a command like <tt class="docutils literal"><span class="pre">CREATE</span> <span class="pre">TABLE</span>
-<span class="pre">...</span></tt>, <tt class="docutils literal"><span class="pre">VACUUM</span></tt>, <tt class="docutils literal"><span class="pre">PRAGMA</span></tt>, pysqlite will commit implicitly before executing
-that command. There are two reasons for doing that. The first is that most of
-these commands don't work within transactions. The other reason is that
-pysqlite needs to keep track of the transaction state (if a transaction is
-active or not).</p>
-<p>You can control which kind of &quot;BEGIN&quot; statements pysqlite implicitly executes
-(or none at all) via the <strong>isolation_level</strong> parameter to the <em>connect</em> call,
-or via the <strong>isolation_level</strong> property of connections.</p>
-<p>If you want <em>autocommit mode</em>, then set <strong>isolation_level</strong> to None.</p>
-<p>Otherwise leave it at it's default, which will result in a plain &quot;BEGIN&quot;
-statement, or set it to one of SQLite's supported isolation levels: DEFERRED,
-IMMEDIATE or EXCLUSIVE.</p>
-<p>As pysqlite needs to keep track of the transaction state, you should not use
-<tt class="docutils literal"><span class="pre">OR</span> <span class="pre">ROLLBACK</span></tt> or <tt class="docutils literal"><span class="pre">ON</span> <span class="pre">CONFLICT</span> <span class="pre">ROLLBACK</span></tt>. Instead, catch the
-<tt class="docutils literal"><span class="pre">IntegrityError</span></tt> and call the <tt class="docutils literal"><span class="pre">rollback</span></tt> method of the connection yourself.</p>
-</div>
-<div class="section">
-<h2><a id="using-pysqlite-efficiently" name="using-pysqlite-efficiently">6. Using pysqlite efficiently</a></h2>
-</div>
-<div class="section">
-<h2><a id="using-shortcut-methods" name="using-shortcut-methods">6.1 Using shortcut methods</a></h2>
-<p>Using the nonstandard <tt class="docutils literal"><span class="pre">execute()</span></tt>, <tt class="docutils literal"><span class="pre">executemany()</span></tt> and <tt class="docutils literal"><span class="pre">executescript()</span></tt>
-methods of the Connection object, your code can be written more concisely,
-because you don't have to create the - often superfluous Cursor objects
-explicitly. Instead, the Cursor objects are created implicitly and
-these shortcut methods return the cursor objects. This way, you can for
-example execute a SELECT statement and iterate over it directly using
-only a single call on the Connection object.</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">persons</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_operator">[</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">(</span><span class="p_string">"Hugo"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"Boss"</span><span class="p_operator">),</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">(</span><span class="p_string">"Calvin"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"Klein"</span><span class="p_operator">)</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_operator">]</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">":memory:"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Create&nbsp;the&nbsp;table</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"create&nbsp;table&nbsp;person(firstname,&nbsp;lastname)"</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Fill&nbsp;the&nbsp;table</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">executemany</span><span class="p_operator">(</span><span class="p_string">"insert&nbsp;into&nbsp;person(firstname,&nbsp;lastname)&nbsp;values&nbsp;(?,&nbsp;?)"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">persons</span><span class="p_operator">)</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Print&nbsp;the&nbsp;table&nbsp;contents</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;firstname,&nbsp;lastname&nbsp;from&nbsp;person"</span><span class="p_operator">):</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_commentline">#&nbsp;Using&nbsp;a&nbsp;dummy&nbsp;WHERE&nbsp;clause&nbsp;to&nbsp;not&nbsp;let&nbsp;SQLite&nbsp;take&nbsp;the&nbsp;shortcut&nbsp;table&nbsp;deletes.</span><span class="p_default"><br/>
-</span><span class="p_word">print</span><span class="p_default">&nbsp;</span><span class="p_string">"I&nbsp;just&nbsp;deleted"</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"delete&nbsp;from&nbsp;person&nbsp;where&nbsp;1=1"</span><span class="p_operator">).</span><span class="p_identifier">rowcount</span><span class="p_operator">,</span><span class="p_default">&nbsp;</span><span class="p_string">"rows"</span><span class="p_default"><br/>
-</span>
-</div>
-</div>
-<div class="section">
-<h2><a id="accessing-columns-by-name-instead-of-by-index" name="accessing-columns-by-name-instead-of-by-index">6.2 Accessing columns by name instead of by index</a></h2>
-<p>A cool new feature of pysqlite 2.1.0 is the new builtin sqlite.Row class
-designed to be used as a row factory.</p>
-<p>Rows wrapped with this class can be accessed both by index (like tuples) and
-case-insensitively by name:</p>
-<div class="code-block">
-<span class="p_word">from</span><span class="p_default">&nbsp;</span><span class="p_identifier">pysqlite2</span><span class="p_default">&nbsp;</span><span class="p_word">import</span><span class="p_default">&nbsp;</span><span class="p_identifier">dbapi2</span><span class="p_default">&nbsp;</span><span class="p_word">as</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">con</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">connect</span><span class="p_operator">(</span><span class="p_string">"mydb"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">row_factory</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">sqlite</span><span class="p_operator">.</span><span class="p_identifier">Row</span><span class="p_default"><br/>
-<br/>
-</span><span class="p_identifier">cur</span><span class="p_default">&nbsp;</span><span class="p_operator">=</span><span class="p_default">&nbsp;</span><span class="p_identifier">con</span><span class="p_operator">.</span><span class="p_identifier">cursor</span><span class="p_operator">()</span><span class="p_default"><br/>
-</span><span class="p_identifier">cur</span><span class="p_operator">.</span><span class="p_identifier">execute</span><span class="p_operator">(</span><span class="p_string">"select&nbsp;name_last,&nbsp;age&nbsp;from&nbsp;people"</span><span class="p_operator">)</span><span class="p_default"><br/>
-</span><span class="p_word">for</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_default">&nbsp;</span><span class="p_word">in</span><span class="p_default">&nbsp;</span><span class="p_identifier">cur</span><span class="p_operator">:</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">0</span><span class="p_operator">]</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_string">"name_last"</span><span class="p_operator">]</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_string">"name_last"</span><span class="p_operator">]</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_string">"nAmE_lAsT"</span><span class="p_operator">]</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">]</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_string">"age"</span><span class="p_operator">]</span><span class="p_default"><br/>
-&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="p_word">assert</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_number">1</span><span class="p_operator">]</span><span class="p_default">&nbsp;</span><span class="p_operator">==</span><span class="p_default">&nbsp;</span><span class="p_identifier">row</span><span class="p_operator">[</span><span class="p_string">"AgE"</span><span class="p_operator">]</span>
-</div>
-</div>
-</div>
-</div>
-</body>
-</html>
index 4170e86..d89e4c4 100644 (file)
@@ -68,7 +68,7 @@ def register_adapters_and_converters():
         timepart_full = timepart.split(".")
         hours, minutes, seconds = map(int, timepart_full[0].split(":"))
         if len(timepart_full) == 2:
-            microseconds = int(float("0." + timepart_full[1]) * 1000000)
+            microseconds = int(timepart_full[1])
         else:
             microseconds = 0
 
index 60bd528..4fabd07 100644 (file)
@@ -91,7 +91,7 @@ class RowFactoryTests(unittest.TestCase):
                                    list),
                         "row is not instance of list")
 
-    def CheckSqliteRow(self):
+    def CheckSqliteRowIndex(self):
         self.con.row_factory = sqlite.Row
         row = self.con.execute("select 1 as a, 2 as b").fetchone()
         self.failUnless(isinstance(row,
@@ -110,6 +110,27 @@ class RowFactoryTests(unittest.TestCase):
         self.failUnless(col1 == 1, "by index: wrong result for column 0")
         self.failUnless(col2 == 2, "by index: wrong result for column 1")
 
+    def CheckSqliteRowIter(self):
+        """Checks if the row object is iterable"""
+        self.con.row_factory = sqlite.Row
+        row = self.con.execute("select 1 as a, 2 as b").fetchone()
+        for col in row:
+            pass
+
+    def CheckSqliteRowAsTuple(self):
+        """Checks if the row object can be converted to a tuple"""
+        self.con.row_factory = sqlite.Row
+        row = self.con.execute("select 1 as a, 2 as b").fetchone()
+        t = tuple(row)
+
+    def CheckSqliteRowAsDict(self):
+        """Checks if the row object can be correctly converted to a dictionary"""
+        self.con.row_factory = sqlite.Row
+        row = self.con.execute("select 1 as a, 2 as b").fetchone()
+        d = dict(row)
+        self.failUnlessEqual(d["a"], row["a"])
+        self.failUnlessEqual(d["b"], row["b"])
+
     def tearDown(self):
         self.con.close()
 
index 04e16ef..068f5b8 100644 (file)
@@ -69,6 +69,16 @@ class RegressionTests(unittest.TestCase):
         cur.execute('select 1 as "foo baz"')
         self.failUnlessEqual(cur.description[0][0], "foo baz")
 
+    def CheckStatementAvailable(self):
+        # pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
+        # before trying to fetch data from it. close() destroys the active statement ...
+        con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
+        cur = con.cursor()
+        cur.execute("select 4 union select 5")
+        cur.close()
+        cur.fetchone()
+        cur.fetchone()
+
 def suite():
     regression_suite = unittest.makeSuite(RegressionTests, "Check")
     return unittest.TestSuite((regression_suite,))
index 34ebbea..973fb84 100644 (file)
@@ -106,6 +106,7 @@ class DeclTypesTests(unittest.TestCase):
         # and implement two custom ones
         sqlite.converters["BOOL"] = lambda x: bool(int(x))
         sqlite.converters["FOO"] = DeclTypesTests.Foo
+        sqlite.converters["WRONG"] = lambda x: "WRONG"
 
     def tearDown(self):
         del sqlite.converters["FLOAT"]
@@ -117,7 +118,7 @@ class DeclTypesTests(unittest.TestCase):
     def CheckString(self):
         # default
         self.cur.execute("insert into test(s) values (?)", ("foo",))
-        self.cur.execute("select s from test")
+        self.cur.execute('select s as "s [WRONG]" from test')
         row = self.cur.fetchone()
         self.failUnlessEqual(row[0], "foo")
 
@@ -204,26 +205,32 @@ class DeclTypesTests(unittest.TestCase):
 
 class ColNamesTests(unittest.TestCase):
     def setUp(self):
-        self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES|sqlite.PARSE_DECLTYPES)
+        self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
         self.cur = self.con.cursor()
         self.cur.execute("create table test(x foo)")
 
         sqlite.converters["FOO"] = lambda x: "[%s]" % x
         sqlite.converters["BAR"] = lambda x: "<%s>" % x
         sqlite.converters["EXC"] = lambda x: 5/0
+        sqlite.converters["B1B1"] = lambda x: "MARKER"
 
     def tearDown(self):
         del sqlite.converters["FOO"]
         del sqlite.converters["BAR"]
         del sqlite.converters["EXC"]
+        del sqlite.converters["B1B1"]
         self.cur.close()
         self.con.close()
 
-    def CheckDeclType(self):
+    def CheckDeclTypeNotUsed(self):
+        """
+        Assures that the declared type is not used when PARSE_DECLTYPES
+        is not set.
+        """
         self.cur.execute("insert into test(x) values (?)", ("xxx",))
         self.cur.execute("select x from test")
         val = self.cur.fetchone()[0]
-        self.failUnlessEqual(val, "[xxx]")
+        self.failUnlessEqual(val, "xxx")
 
     def CheckNone(self):
         self.cur.execute("insert into test(x) values (?)", (None,))
@@ -241,6 +248,11 @@ class ColNamesTests(unittest.TestCase):
         # whitespace should be stripped.
         self.failUnlessEqual(self.cur.description[0][0], "x")
 
+    def CheckCaseInConverterName(self):
+        self.cur.execute("""select 'other' as "x [b1b1]\"""")
+        val = self.cur.fetchone()[0]
+        self.failUnlessEqual(val, "MARKER")
+
     def CheckCursorDescriptionNoRow(self):
         """
         cursor.description should at least provide the column name(s), even if
@@ -334,6 +346,13 @@ class DateTimeTests(unittest.TestCase):
         ts2 = self.cur.fetchone()[0]
         self.failUnlessEqual(ts, ts2)
 
+    def CheckDateTimeSubSecondsFloatingPoint(self):
+        ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241)
+        self.cur.execute("insert into test(ts) values (?)", (ts,))
+        self.cur.execute("select ts from test")
+        ts2 = self.cur.fetchone()[0]
+        self.failUnlessEqual(ts, ts2)
+
 def suite():
     sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check")
     decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check")
index 6962695..18a4066 100644 (file)
 #include <limits.h>
 
 /* only used internally */
-Node* new_node(PyObject* key, PyObject* data)
+pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data)
 {
-    Node* node;
+    pysqlite_Node* node;
 
-    node = (Node*) (NodeType.tp_alloc(&NodeType, 0));
+    node = (pysqlite_Node*) (pysqlite_NodeType.tp_alloc(&pysqlite_NodeType, 0));
     if (!node) {
         return NULL;
     }
@@ -46,7 +46,7 @@ Node* new_node(PyObject* key, PyObject* data)
     return node;
 }
 
-void node_dealloc(Node* self)
+void pysqlite_node_dealloc(pysqlite_Node* self)
 {
     Py_DECREF(self->key);
     Py_DECREF(self->data);
@@ -54,7 +54,7 @@ void node_dealloc(Node* self)
     self->ob_type->tp_free((PyObject*)self);
 }
 
-int cache_init(Cache* self, PyObject* args, PyObject* kwargs)
+int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* factory;
     int size = 10;
@@ -86,10 +86,10 @@ int cache_init(Cache* self, PyObject* args, PyObject* kwargs)
     return 0;
 }
 
-void cache_dealloc(Cache* self)
+void pysqlite_cache_dealloc(pysqlite_Cache* self)
 {
-    Node* node;
-    Node* delete_node;
+    pysqlite_Node* node;
+    pysqlite_Node* delete_node;
 
     if (!self->factory) {
         /* constructor failed, just get out of here */
@@ -112,14 +112,14 @@ void cache_dealloc(Cache* self)
     self->ob_type->tp_free((PyObject*)self);
 }
 
-PyObject* cache_get(Cache* self, PyObject* args)
+PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
 {
     PyObject* key = args;
-    Node* node;
-    Node* ptr;
+    pysqlite_Node* node;
+    pysqlite_Node* ptr;
     PyObject* data;
 
-    node = (Node*)PyDict_GetItem(self->mapping, key);
+    node = (pysqlite_Node*)PyDict_GetItem(self->mapping, key);
     if (node) {
         /* an entry for this key already exists in the cache */
 
@@ -186,7 +186,7 @@ PyObject* cache_get(Cache* self, PyObject* args)
             return NULL;
         }
 
-        node = new_node(key, data);
+        node = pysqlite_new_node(key, data);
         if (!node) {
             return NULL;
         }
@@ -211,9 +211,9 @@ PyObject* cache_get(Cache* self, PyObject* args)
     return node->data;
 }
 
-PyObject* cache_display(Cache* self, PyObject* args)
+PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
 {
-    Node* ptr;
+    pysqlite_Node* ptr;
     PyObject* prevkey;
     PyObject* nextkey;
     PyObject* fmt_args;
@@ -265,20 +265,20 @@ PyObject* cache_display(Cache* self, PyObject* args)
 }
 
 static PyMethodDef cache_methods[] = {
-    {"get", (PyCFunction)cache_get, METH_O,
+    {"get", (PyCFunction)pysqlite_cache_get, METH_O,
         PyDoc_STR("Gets an entry from the cache or calls the factory function to produce one.")},
-    {"display", (PyCFunction)cache_display, METH_NOARGS,
+    {"display", (PyCFunction)pysqlite_cache_display, METH_NOARGS,
         PyDoc_STR("For debugging only.")},
     {NULL, NULL}
 };
 
-PyTypeObject NodeType = {
+PyTypeObject pysqlite_NodeType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME "Node",                             /* tp_name */
-        sizeof(Node),                                   /* tp_basicsize */
+        sizeof(pysqlite_Node),                          /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)node_dealloc,                       /* tp_dealloc */
+        (destructor)pysqlite_node_dealloc,              /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -315,13 +315,13 @@ PyTypeObject NodeType = {
         0                                               /* tp_free */
 };
 
-PyTypeObject CacheType = {
+PyTypeObject pysqlite_CacheType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".Cache",                           /* tp_name */
-        sizeof(Cache),                                  /* tp_basicsize */
+        sizeof(pysqlite_Cache),                         /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)cache_dealloc,                      /* tp_dealloc */
+        (destructor)pysqlite_cache_dealloc,             /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -352,24 +352,24 @@ PyTypeObject CacheType = {
         0,                                              /* tp_descr_get */
         0,                                              /* tp_descr_set */
         0,                                              /* tp_dictoffset */
-        (initproc)cache_init,                           /* tp_init */
+        (initproc)pysqlite_cache_init,                  /* tp_init */
         0,                                              /* tp_alloc */
         0,                                              /* tp_new */
         0                                               /* tp_free */
 };
 
-extern int cache_setup_types(void)
+extern int pysqlite_cache_setup_types(void)
 {
     int rc;
 
-    NodeType.tp_new = PyType_GenericNew;
-    CacheType.tp_new = PyType_GenericNew;
+    pysqlite_NodeType.tp_new = PyType_GenericNew;
+    pysqlite_CacheType.tp_new = PyType_GenericNew;
 
-    rc = PyType_Ready(&NodeType);
+    rc = PyType_Ready(&pysqlite_NodeType);
     if (rc < 0) {
         return rc;
     }
 
-    rc = PyType_Ready(&CacheType);
+    rc = PyType_Ready(&pysqlite_CacheType);
     return rc;
 }
index 1f13907..158bf5a 100644 (file)
  * dictionary. The list items are of type 'Node' and the dictionary has the
  * nodes as values. */
 
-typedef struct _Node
+typedef struct _pysqlite_Node
 {
     PyObject_HEAD
     PyObject* key;
     PyObject* data;
     long count;
-    struct _Node* prev;
-    struct _Node* next;
-} Node;
+    struct _pysqlite_Node* prev;
+    struct _pysqlite_Node* next;
+} pysqlite_Node;
 
 typedef struct
 {
@@ -50,24 +50,24 @@ typedef struct
     /* the factory callable */
     PyObject* factory;
 
-    Node* first;
-    Node* last;
+    pysqlite_Node* first;
+    pysqlite_Node* last;
 
     /* if set, decrement the factory function when the Cache is deallocated.
      * this is almost always desirable, but not in the pysqlite context */
     int decref_factory;
-} Cache;
+} pysqlite_Cache;
 
-extern PyTypeObject NodeType;
-extern PyTypeObject CacheType;
+extern PyTypeObject pysqlite_NodeType;
+extern PyTypeObject pysqlite_CacheType;
 
-int node_init(Node* self, PyObject* args, PyObject* kwargs);
-void node_dealloc(Node* self);
+int pysqlite_node_init(pysqlite_Node* self, PyObject* args, PyObject* kwargs);
+void pysqlite_node_dealloc(pysqlite_Node* self);
 
-int cache_init(Cache* self, PyObject* args, PyObject* kwargs);
-void cache_dealloc(Cache* self);
-PyObject* cache_get(Cache* self, PyObject* args);
+int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs);
+void pysqlite_cache_dealloc(pysqlite_Cache* self);
+PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args);
 
-int cache_setup_types(void);
+int pysqlite_cache_setup_types(void);
 
 #endif
index 703af15..924d582 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "pythread.h"
 
-static int connection_set_isolation_level(Connection* self, PyObject* isolation_level);
+static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level);
 
 
 void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len)
@@ -43,11 +43,11 @@ void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len)
 #if SQLITE_VERSION_NUMBER >= 3003003
     sqlite3_result_error(ctx, errmsg, len);
 #else
-    PyErr_SetString(OperationalError, errmsg);
+    PyErr_SetString(pysqlite_OperationalError, errmsg);
 #endif
 }
 
-int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
+int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL};
 
@@ -82,7 +82,7 @@ int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
     Py_END_ALLOW_THREADS
 
     if (rc != SQLITE_OK) {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
         return -1;
     }
 
@@ -95,10 +95,10 @@ int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
         Py_INCREF(isolation_level);
     }
     self->isolation_level = NULL;
-    connection_set_isolation_level(self, isolation_level);
+    pysqlite_connection_set_isolation_level(self, isolation_level);
     Py_DECREF(isolation_level);
 
-    self->statement_cache = (Cache*)PyObject_CallFunction((PyObject*)&CacheType, "Oi", self, cached_statements);
+    self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "Oi", self, cached_statements);
     if (PyErr_Occurred()) {
         return -1;
     }
@@ -135,41 +135,41 @@ int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
         return -1;
     }
 
-    self->Warning Warning;
-    self->Error Error;
-    self->InterfaceError InterfaceError;
-    self->DatabaseError DatabaseError;
-    self->DataError DataError;
-    self->OperationalError OperationalError;
-    self->IntegrityError IntegrityError;
-    self->InternalError InternalError;
-    self->ProgrammingError ProgrammingError;
-    self->NotSupportedError NotSupportedError;
+    self->Warning               = pysqlite_Warning;
+    self->Error                 = pysqlite_Error;
+    self->InterfaceError        = pysqlite_InterfaceError;
+    self->DatabaseError         = pysqlite_DatabaseError;
+    self->DataError             = pysqlite_DataError;
+    self->OperationalError      = pysqlite_OperationalError;
+    self->IntegrityError        = pysqlite_IntegrityError;
+    self->InternalError         = pysqlite_InternalError;
+    self->ProgrammingError      = pysqlite_ProgrammingError;
+    self->NotSupportedError     = pysqlite_NotSupportedError;
 
     return 0;
 }
 
 /* Empty the entire statement cache of this connection */
-void flush_statement_cache(Connection* self)
+void pysqlite_flush_statement_cache(pysqlite_Connection* self)
 {
-    Node* node;
-    Statement* statement;
+    pysqlite_Node* node;
+    pysqlite_Statement* statement;
 
     node = self->statement_cache->first;
 
     while (node) {
-        statement = (Statement*)(node->data);
-        (void)statement_finalize(statement);
+        statement = (pysqlite_Statement*)(node->data);
+        (void)pysqlite_statement_finalize(statement);
         node = node->next;
     }
 
     Py_DECREF(self->statement_cache);
-    self->statement_cache = (Cache*)PyObject_CallFunction((PyObject*)&CacheType, "O", self);
+    self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "O", self);
     Py_DECREF(self);
     self->statement_cache->decref_factory = 0;
 }
 
-void reset_all_statements(Connection* self)
+void pysqlite_reset_all_statements(pysqlite_Connection* self)
 {
     int i;
     PyObject* weakref;
@@ -179,12 +179,12 @@ void reset_all_statements(Connection* self)
         weakref = PyList_GetItem(self->statements, i);
         statement = PyWeakref_GetObject(weakref);
         if (statement != Py_None) {
-            (void)statement_reset((Statement*)statement);
+            (void)pysqlite_statement_reset((pysqlite_Statement*)statement);
         }
     }
 }
 
-void connection_dealloc(Connection* self)
+void pysqlite_connection_dealloc(pysqlite_Connection* self)
 {
     Py_XDECREF(self->statement_cache);
 
@@ -208,7 +208,7 @@ void connection_dealloc(Connection* self)
     self->ob_type->tp_free((PyObject*)self);
 }
 
-PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"factory", NULL, NULL};
     PyObject* factory = NULL;
@@ -220,34 +220,34 @@ PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs)
         return NULL;
     }
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         return NULL;
     }
 
     if (factory == NULL) {
-        factory = (PyObject*)&CursorType;
+        factory = (PyObject*)&pysqlite_CursorType;
     }
 
     cursor = PyObject_CallFunction(factory, "O", self);
 
     if (cursor && self->row_factory != Py_None) {
-        Py_XDECREF(((Cursor*)cursor)->row_factory);
+        Py_XDECREF(((pysqlite_Cursor*)cursor)->row_factory);
         Py_INCREF(self->row_factory);
-        ((Cursor*)cursor)->row_factory = self->row_factory;
+        ((pysqlite_Cursor*)cursor)->row_factory = self->row_factory;
     }
 
     return cursor;
 }
 
-PyObject* connection_close(Connection* self, PyObject* args)
+PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
 {
     int rc;
 
-    if (!check_thread(self)) {
+    if (!pysqlite_check_thread(self)) {
         return NULL;
     }
 
-    flush_statement_cache(self);
+    pysqlite_flush_statement_cache(self);
 
     if (self->db) {
         Py_BEGIN_ALLOW_THREADS
@@ -255,7 +255,7 @@ PyObject* connection_close(Connection* self, PyObject* args)
         Py_END_ALLOW_THREADS
 
         if (rc != SQLITE_OK) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
             return NULL;
         } else {
             self->db = NULL;
@@ -271,17 +271,17 @@ PyObject* connection_close(Connection* self, PyObject* args)
  *
  * 0 => error; 1 => ok
  */
-int check_connection(Connection* con)
+int pysqlite_check_connection(pysqlite_Connection* con)
 {
     if (!con->db) {
-        PyErr_SetString(ProgrammingError, "Cannot operate on a closed database.");
+        PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed database.");
         return 0;
     } else {
         return 1;
     }
 }
 
-PyObject* _connection_begin(Connection* self)
+PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
 {
     int rc;
     const char* tail;
@@ -292,7 +292,7 @@ PyObject* _connection_begin(Connection* self)
     Py_END_ALLOW_THREADS
 
     if (rc != SQLITE_OK) {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
         goto error;
     }
 
@@ -300,7 +300,7 @@ PyObject* _connection_begin(Connection* self)
     if (rc == SQLITE_DONE) {
         self->inTransaction = 1;
     } else {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
     }
 
     Py_BEGIN_ALLOW_THREADS
@@ -308,7 +308,7 @@ PyObject* _connection_begin(Connection* self)
     Py_END_ALLOW_THREADS
 
     if (rc != SQLITE_OK && !PyErr_Occurred()) {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
     }
 
 error:
@@ -320,13 +320,13 @@ error:
     }
 }
 
-PyObject* connection_commit(Connection* self, PyObject* args)
+PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)
 {
     int rc;
     const char* tail;
     sqlite3_stmt* statement;
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         return NULL;
     }
 
@@ -335,7 +335,7 @@ PyObject* connection_commit(Connection* self, PyObject* args)
         rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
             goto error;
         }
 
@@ -343,14 +343,14 @@ PyObject* connection_commit(Connection* self, PyObject* args)
         if (rc == SQLITE_DONE) {
             self->inTransaction = 0;
         } else {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_finalize(statement);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK && !PyErr_Occurred()) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
     }
@@ -364,24 +364,24 @@ error:
     }
 }
 
-PyObject* connection_rollback(Connection* self, PyObject* args)
+PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args)
 {
     int rc;
     const char* tail;
     sqlite3_stmt* statement;
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         return NULL;
     }
 
     if (self->inTransaction) {
-        reset_all_statements(self);
+        pysqlite_reset_all_statements(self);
 
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
             goto error;
         }
 
@@ -389,14 +389,14 @@ PyObject* connection_rollback(Connection* self, PyObject* args)
         if (rc == SQLITE_DONE) {
             self->inTransaction = 0;
         } else {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_finalize(statement);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK && !PyErr_Occurred()) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
     }
@@ -410,7 +410,7 @@ error:
     }
 }
 
-void _set_result(sqlite3_context* context, PyObject* py_val)
+void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
 {
     long longval;
     const char* buffer;
@@ -445,7 +445,7 @@ void _set_result(sqlite3_context* context, PyObject* py_val)
     }
 }
 
-PyObject* _build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv)
+PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv)
 {
     PyObject* args;
     int i;
@@ -512,7 +512,7 @@ PyObject* _build_py_params(sqlite3_context *context, int argc, sqlite3_value** a
     return args;
 }
 
-void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
+void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
 {
     PyObject* args;
     PyObject* py_func;
@@ -524,14 +524,14 @@ void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
 
     py_func = (PyObject*)sqlite3_user_data(context);
 
-    args = _build_py_params(context, argc, argv);
+    args = _pysqlite_build_py_params(context, argc, argv);
     if (args) {
         py_retval = PyObject_CallObject(py_func, args);
         Py_DECREF(args);
     }
 
     if (py_retval) {
-        _set_result(context, py_retval);
+        _pysqlite_set_result(context, py_retval);
         Py_DECREF(py_retval);
     } else {
         if (_enable_callback_tracebacks) {
@@ -545,7 +545,7 @@ void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
     PyGILState_Release(threadstate);
 }
 
-static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
+static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
 {
     PyObject* args;
     PyObject* function_result = NULL;
@@ -581,7 +581,7 @@ static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** p
         goto error;
     }
 
-    args = _build_py_params(context, argc, params);
+    args = _pysqlite_build_py_params(context, argc, params);
     if (!args) {
         goto error;
     }
@@ -605,7 +605,7 @@ error:
     PyGILState_Release(threadstate);
 }
 
-void _final_callback(sqlite3_context* context)
+void _pysqlite_final_callback(sqlite3_context* context)
 {
     PyObject* function_result = NULL;
     PyObject** aggregate_instance;
@@ -634,7 +634,7 @@ void _final_callback(sqlite3_context* context)
         }
         _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
     } else {
-        _set_result(context, function_result);
+        _pysqlite_set_result(context, function_result);
     }
 
 error:
@@ -644,7 +644,7 @@ error:
     PyGILState_Release(threadstate);
 }
 
-void _drop_unused_statement_references(Connection* self)
+void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self)
 {
     PyObject* new_list;
     PyObject* weakref;
@@ -676,7 +676,7 @@ void _drop_unused_statement_references(Connection* self)
     self->statements = new_list;
 }
 
-PyObject* connection_create_function(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"name", "narg", "func", NULL, NULL};
 
@@ -691,11 +691,11 @@ PyObject* connection_create_function(Connection* self, PyObject* args, PyObject*
         return NULL;
     }
 
-    rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _func_callback, NULL, NULL);
+    rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _pysqlite_func_callback, NULL, NULL);
 
     if (rc != SQLITE_OK) {
         /* Workaround for SQLite bug: no error code or string is available here */
-        PyErr_SetString(OperationalError, "Error creating function");
+        PyErr_SetString(pysqlite_OperationalError, "Error creating function");
         return NULL;
     } else {
         PyDict_SetItem(self->function_pinboard, func, Py_None);
@@ -705,7 +705,7 @@ PyObject* connection_create_function(Connection* self, PyObject* args, PyObject*
     }
 }
 
-PyObject* connection_create_aggregate(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* aggregate_class;
 
@@ -719,10 +719,10 @@ PyObject* connection_create_aggregate(Connection* self, PyObject* args, PyObject
         return NULL;
     }
 
-    rc = sqlite3_create_function(self->db, name, n_arg, SQLITE_UTF8, (void*)aggregate_class, 0, &_step_callback, &_final_callback);
+    rc = sqlite3_create_function(self->db, name, n_arg, SQLITE_UTF8, (void*)aggregate_class, 0, &_pysqlite_step_callback, &_pysqlite_final_callback);
     if (rc != SQLITE_OK) {
         /* Workaround for SQLite bug: no error code or string is available here */
-        PyErr_SetString(OperationalError, "Error creating aggregate");
+        PyErr_SetString(pysqlite_OperationalError, "Error creating aggregate");
         return NULL;
     } else {
         PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None);
@@ -732,7 +732,7 @@ PyObject* connection_create_aggregate(Connection* self, PyObject* args, PyObject
     }
 }
 
-int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
+static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
 {
     PyObject *ret;
     int rc;
@@ -762,7 +762,7 @@ int _authorizer_callback(void* user_arg, int action, const char* arg1, const cha
     return rc;
 }
 
-PyObject* connection_set_authorizer(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* authorizer_cb;
 
@@ -777,7 +777,7 @@ PyObject* connection_set_authorizer(Connection* self, PyObject* args, PyObject*
     rc = sqlite3_set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb);
 
     if (rc != SQLITE_OK) {
-        PyErr_SetString(OperationalError, "Error setting authorizer callback");
+        PyErr_SetString(pysqlite_OperationalError, "Error setting authorizer callback");
         return NULL;
     } else {
         PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None);
@@ -787,11 +787,11 @@ PyObject* connection_set_authorizer(Connection* self, PyObject* args, PyObject*
     }
 }
 
-int check_thread(Connection* self)
+int pysqlite_check_thread(pysqlite_Connection* self)
 {
     if (self->check_same_thread) {
         if (PyThread_get_thread_ident() != self->thread_ident) {
-            PyErr_Format(ProgrammingError,
+            PyErr_Format(pysqlite_ProgrammingError,
                         "SQLite objects created in a thread can only be used in that same thread."
                         "The object was created in thread id %ld and this is thread id %ld",
                         self->thread_ident, PyThread_get_thread_ident());
@@ -803,22 +803,22 @@ int check_thread(Connection* self)
     return 1;
 }
 
-static PyObject* connection_get_isolation_level(Connection* self, void* unused)
+static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused)
 {
     Py_INCREF(self->isolation_level);
     return self->isolation_level;
 }
 
-static PyObject* connection_get_total_changes(Connection* self, void* unused)
+static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused)
 {
-    if (!check_connection(self)) {
+    if (!pysqlite_check_connection(self)) {
         return NULL;
     } else {
         return Py_BuildValue("i", sqlite3_total_changes(self->db));
     }
 }
 
-static int connection_set_isolation_level(Connection* self, PyObject* isolation_level)
+static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level)
 {
     PyObject* res;
     PyObject* begin_statement;
@@ -834,7 +834,7 @@ static int connection_set_isolation_level(Connection* self, PyObject* isolation_
         Py_INCREF(Py_None);
         self->isolation_level = Py_None;
 
-        res = connection_commit(self, NULL);
+        res = pysqlite_connection_commit(self, NULL);
         if (!res) {
             return -1;
         }
@@ -866,10 +866,10 @@ static int connection_set_isolation_level(Connection* self, PyObject* isolation_
     return 0;
 }
 
-PyObject* connection_call(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* sql;
-    Statement* statement;
+    pysqlite_Statement* statement;
     PyObject* weakref;
     int rc;
 
@@ -877,22 +877,22 @@ PyObject* connection_call(Connection* self, PyObject* args, PyObject* kwargs)
         return NULL;
     }
 
-    _drop_unused_statement_references(self);
+    _pysqlite_drop_unused_statement_references(self);
 
-    statement = PyObject_New(Statement, &StatementType);
+    statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
     if (!statement) {
         return NULL;
     }
 
-    rc = statement_create(statement, self, sql);
+    rc = pysqlite_statement_create(statement, self, sql);
 
     if (rc != SQLITE_OK) {
         if (rc == PYSQLITE_TOO_MUCH_SQL) {
-            PyErr_SetString(Warning, "You can only execute one statement at a time.");
+            PyErr_SetString(pysqlite_Warning, "You can only execute one statement at a time.");
         } else if (rc == PYSQLITE_SQL_WRONG_TYPE) {
-            PyErr_SetString(Warning, "SQL is of wrong type. Must be string or unicode.");
+            PyErr_SetString(pysqlite_Warning, "SQL is of wrong type. Must be string or unicode.");
         } else {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
         Py_DECREF(statement);
@@ -918,7 +918,7 @@ error:
     return (PyObject*)statement;
 }
 
-PyObject* connection_execute(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* cursor = 0;
     PyObject* result = 0;
@@ -949,7 +949,7 @@ error:
     return cursor;
 }
 
-PyObject* connection_executemany(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* cursor = 0;
     PyObject* result = 0;
@@ -980,7 +980,7 @@ error:
     return cursor;
 }
 
-PyObject* connection_executescript(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* cursor = 0;
     PyObject* result = 0;
@@ -1014,7 +1014,7 @@ error:
 /* ------------------------- COLLATION CODE ------------------------ */
 
 static int
-collation_callback(
+pysqlite_collation_callback(
         void* context,
         int text1_length, const void* text1_data,
         int text2_length, const void* text2_data)
@@ -1063,11 +1063,11 @@ finally:
 }
 
 static PyObject *
-connection_interrupt(Connection* self, PyObject* args)
+pysqlite_connection_interrupt(pysqlite_Connection* self, PyObject* args)
 {
     PyObject* retval = NULL;
 
-    if (!check_connection(self)) {
+    if (!pysqlite_check_connection(self)) {
         goto finally;
     }
 
@@ -1081,7 +1081,7 @@ finally:
 }
 
 static PyObject *
-connection_create_collation(Connection* self, PyObject* args)
+pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
 {
     PyObject* callable;
     PyObject* uppercase_name = 0;
@@ -1090,7 +1090,7 @@ connection_create_collation(Connection* self, PyObject* args)
     char* chk;
     int rc;
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         goto finally;
     }
 
@@ -1111,7 +1111,7 @@ connection_create_collation(Connection* self, PyObject* args)
         {
             chk++;
         } else {
-            PyErr_SetString(ProgrammingError, "invalid character in collation name");
+            PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name");
             goto finally;
         }
     }
@@ -1131,10 +1131,10 @@ connection_create_collation(Connection* self, PyObject* args)
                                   PyString_AsString(uppercase_name),
                                   SQLITE_UTF8,
                                   (callable != Py_None) ? callable : NULL,
-                                  (callable != Py_None) ? collation_callback : NULL);
+                                  (callable != Py_None) ? pysqlite_collation_callback : NULL);
     if (rc != SQLITE_OK) {
         PyDict_DelItem(self->collations, uppercase_name);
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
         goto finally;
     }
 
@@ -1155,63 +1155,63 @@ static char connection_doc[] =
 PyDoc_STR("SQLite database connection object.");
 
 static PyGetSetDef connection_getset[] = {
-    {"isolation_level",  (getter)connection_get_isolation_level, (setter)connection_set_isolation_level},
-    {"total_changes",  (getter)connection_get_total_changes, (setter)0},
+    {"isolation_level",  (getter)pysqlite_connection_get_isolation_level, (setter)pysqlite_connection_set_isolation_level},
+    {"total_changes",  (getter)pysqlite_connection_get_total_changes, (setter)0},
     {NULL}
 };
 
 static PyMethodDef connection_methods[] = {
-    {"cursor", (PyCFunction)connection_cursor, METH_VARARGS|METH_KEYWORDS,
+    {"cursor", (PyCFunction)pysqlite_connection_cursor, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Return a cursor for the connection.")},
-    {"close", (PyCFunction)connection_close, METH_NOARGS,
+    {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS,
         PyDoc_STR("Closes the connection.")},
-    {"commit", (PyCFunction)connection_commit, METH_NOARGS,
+    {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS,
         PyDoc_STR("Commit the current transaction.")},
-    {"rollback", (PyCFunction)connection_rollback, METH_NOARGS,
+    {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS,
         PyDoc_STR("Roll back the current transaction.")},
-    {"create_function", (PyCFunction)connection_create_function, METH_VARARGS|METH_KEYWORDS,
+    {"create_function", (PyCFunction)pysqlite_connection_create_function, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Creates a new function. Non-standard.")},
-    {"create_aggregate", (PyCFunction)connection_create_aggregate, METH_VARARGS|METH_KEYWORDS,
+    {"create_aggregate", (PyCFunction)pysqlite_connection_create_aggregate, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Creates a new aggregate. Non-standard.")},
-    {"set_authorizer", (PyCFunction)connection_set_authorizer, METH_VARARGS|METH_KEYWORDS,
+    {"set_authorizer", (PyCFunction)pysqlite_connection_set_authorizer, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Sets authorizer callback. Non-standard.")},
-    {"execute", (PyCFunction)connection_execute, METH_VARARGS,
+    {"execute", (PyCFunction)pysqlite_connection_execute, METH_VARARGS,
         PyDoc_STR("Executes a SQL statement. Non-standard.")},
-    {"executemany", (PyCFunction)connection_executemany, METH_VARARGS,
+    {"executemany", (PyCFunction)pysqlite_connection_executemany, METH_VARARGS,
         PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")},
-    {"executescript", (PyCFunction)connection_executescript, METH_VARARGS,
+    {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_VARARGS,
         PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
-    {"create_collation", (PyCFunction)connection_create_collation, METH_VARARGS,
+    {"create_collation", (PyCFunction)pysqlite_connection_create_collation, METH_VARARGS,
         PyDoc_STR("Creates a collation function. Non-standard.")},
-    {"interrupt", (PyCFunction)connection_interrupt, METH_NOARGS,
+    {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS,
         PyDoc_STR("Abort any pending database operation. Non-standard.")},
     {NULL, NULL}
 };
 
 static struct PyMemberDef connection_members[] =
 {
-    {"Warning", T_OBJECT, offsetof(Connection, Warning), RO},
-    {"Error", T_OBJECT, offsetof(Connection, Error), RO},
-    {"InterfaceError", T_OBJECT, offsetof(Connection, InterfaceError), RO},
-    {"DatabaseError", T_OBJECT, offsetof(Connection, DatabaseError), RO},
-    {"DataError", T_OBJECT, offsetof(Connection, DataError), RO},
-    {"OperationalError", T_OBJECT, offsetof(Connection, OperationalError), RO},
-    {"IntegrityError", T_OBJECT, offsetof(Connection, IntegrityError), RO},
-    {"InternalError", T_OBJECT, offsetof(Connection, InternalError), RO},
-    {"ProgrammingError", T_OBJECT, offsetof(Connection, ProgrammingError), RO},
-    {"NotSupportedError", T_OBJECT, offsetof(Connection, NotSupportedError), RO},
-    {"row_factory", T_OBJECT, offsetof(Connection, row_factory)},
-    {"text_factory", T_OBJECT, offsetof(Connection, text_factory)},
+    {"Warning", T_OBJECT, offsetof(pysqlite_Connection, Warning), RO},
+    {"Error", T_OBJECT, offsetof(pysqlite_Connection, Error), RO},
+    {"InterfaceError", T_OBJECT, offsetof(pysqlite_Connection, InterfaceError), RO},
+    {"DatabaseError", T_OBJECT, offsetof(pysqlite_Connection, DatabaseError), RO},
+    {"DataError", T_OBJECT, offsetof(pysqlite_Connection, DataError), RO},
+    {"OperationalError", T_OBJECT, offsetof(pysqlite_Connection, OperationalError), RO},
+    {"IntegrityError", T_OBJECT, offsetof(pysqlite_Connection, IntegrityError), RO},
+    {"InternalError", T_OBJECT, offsetof(pysqlite_Connection, InternalError), RO},
+    {"ProgrammingError", T_OBJECT, offsetof(pysqlite_Connection, ProgrammingError), RO},
+    {"NotSupportedError", T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), RO},
+    {"row_factory", T_OBJECT, offsetof(pysqlite_Connection, row_factory)},
+    {"text_factory", T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
     {NULL}
 };
 
-PyTypeObject ConnectionType = {
+PyTypeObject pysqlite_ConnectionType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".Connection",                      /* tp_name */
-        sizeof(Connection),                             /* tp_basicsize */
+        sizeof(pysqlite_Connection),                    /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)connection_dealloc,                 /* tp_dealloc */
+        (destructor)pysqlite_connection_dealloc,        /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -1221,7 +1221,7 @@ PyTypeObject ConnectionType = {
         0,                                              /* tp_as_sequence */
         0,                                              /* tp_as_mapping */
         0,                                              /* tp_hash */
-        (ternaryfunc)connection_call,                   /* tp_call */
+        (ternaryfunc)pysqlite_connection_call,          /* tp_call */
         0,                                              /* tp_str */
         0,                                              /* tp_getattro */
         0,                                              /* tp_setattro */
@@ -1242,14 +1242,14 @@ PyTypeObject ConnectionType = {
         0,                                              /* tp_descr_get */
         0,                                              /* tp_descr_set */
         0,                                              /* tp_dictoffset */
-        (initproc)connection_init,                      /* tp_init */
+        (initproc)pysqlite_connection_init,             /* tp_init */
         0,                                              /* tp_alloc */
         0,                                              /* tp_new */
         0                                               /* tp_free */
 };
 
-extern int connection_setup_types(void)
+extern int pysqlite_connection_setup_types(void)
 {
-    ConnectionType.tp_new = PyType_GenericNew;
-    return PyType_Ready(&ConnectionType);
+    pysqlite_ConnectionType.tp_new = PyType_GenericNew;
+    return PyType_Ready(&pysqlite_ConnectionType);
 }
index 8f4d36e..21fcd2a 100644 (file)
@@ -66,7 +66,7 @@ typedef struct
     /* thread identification of the thread the connection was created in */
     long thread_ident;
 
-    Cache* statement_cache;
+    pysqlite_Cache* statement_cache;
 
     /* A list of weak references to statements used within this connection */
     PyObject* statements;
@@ -106,24 +106,23 @@ typedef struct
     PyObject* InternalError;
     PyObject* ProgrammingError;
     PyObject* NotSupportedError;
-} Connection;
+} pysqlite_Connection;
 
-extern PyTypeObject ConnectionType;
+extern PyTypeObject pysqlite_ConnectionType;
 
-PyObject* connection_alloc(PyTypeObject* type, int aware);
-void connection_dealloc(Connection* self);
-PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs);
-PyObject* connection_close(Connection* self, PyObject* args);
-PyObject* _connection_begin(Connection* self);
-PyObject* connection_begin(Connection* self, PyObject* args);
-PyObject* connection_commit(Connection* self, PyObject* args);
-PyObject* connection_rollback(Connection* self, PyObject* args);
-PyObject* connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
-int connection_init(Connection* self, PyObject* args, PyObject* kwargs);
+PyObject* pysqlite_connection_alloc(PyTypeObject* type, int aware);
+void pysqlite_connection_dealloc(pysqlite_Connection* self);
+PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
+PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args);
+PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
+PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args);
+PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args);
+PyObject* pysqlite_connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
+int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
 
-int check_thread(Connection* self);
-int check_connection(Connection* con);
+int pysqlite_check_thread(pysqlite_Connection* self);
+int pysqlite_check_connection(pysqlite_Connection* con);
 
-int connection_setup_types(void);
+int pysqlite_connection_setup_types(void);
 
 #endif
index 94aea9b..ec203be 100644 (file)
@@ -34,9 +34,9 @@
 #define INT32_MAX 2147483647
 #endif
 
-PyObject* cursor_iternext(Cursor *self);
+PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self);
 
-static StatementKind detect_statement_type(char* statement)
+static pysqlite_StatementKind detect_statement_type(char* statement)
 {
     char buf[20];
     char* src;
@@ -74,11 +74,11 @@ static StatementKind detect_statement_type(char* statement)
     }
 }
 
-int cursor_init(Cursor* self, PyObject* args, PyObject* kwargs)
+int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject* kwargs)
 {
-    Connection* connection;
+    pysqlite_Connection* connection;
 
-    if (!PyArg_ParseTuple(args, "O!", &ConnectionType, &connection))
+    if (!PyArg_ParseTuple(args, "O!", &pysqlite_ConnectionType, &connection))
     {
         return -1; 
     }
@@ -109,20 +109,20 @@ int cursor_init(Cursor* self, PyObject* args, PyObject* kwargs)
     Py_INCREF(Py_None);
     self->row_factory = Py_None;
 
-    if (!check_thread(self->connection)) {
+    if (!pysqlite_check_thread(self->connection)) {
         return -1;
     }
 
     return 0;
 }
 
-void cursor_dealloc(Cursor* self)
+void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
 {
     int rc;
 
     /* Reset the statement if the user has not closed the cursor */
     if (self->statement) {
-        rc = statement_reset(self->statement);
+        rc = pysqlite_statement_reset(self->statement);
         Py_DECREF(self->statement);
     }
 
@@ -137,7 +137,7 @@ void cursor_dealloc(Cursor* self)
     self->ob_type->tp_free((PyObject*)self);
 }
 
-PyObject* _get_converter(PyObject* key)
+PyObject* _pysqlite_get_converter(PyObject* key)
 {
     PyObject* upcase_key;
     PyObject* retval;
@@ -153,7 +153,7 @@ PyObject* _get_converter(PyObject* key)
     return retval;
 }
 
-int build_row_cast_map(Cursor* self)
+int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
 {
     int i;
     const char* type_start = (const char*)-1;
@@ -175,7 +175,7 @@ int build_row_cast_map(Cursor* self)
     for (i = 0; i < sqlite3_column_count(self->statement->st); i++) {
         converter = NULL;
 
-        if (self->connection->detect_types | PARSE_COLNAMES) {
+        if (self->connection->detect_types & PARSE_COLNAMES) {
             colname = sqlite3_column_name(self->statement->st, i);
             if (colname) {
                 for (pos = colname; *pos != 0; pos++) {
@@ -190,7 +190,7 @@ int build_row_cast_map(Cursor* self)
                             break;
                         }
 
-                        converter = _get_converter(key);
+                        converter = _pysqlite_get_converter(key);
                         Py_DECREF(key);
                         break;
                     }
@@ -198,7 +198,7 @@ int build_row_cast_map(Cursor* self)
             }
         }
 
-        if (!converter && self->connection->detect_types | PARSE_DECLTYPES) {
+        if (!converter && self->connection->detect_types & PARSE_DECLTYPES) {
             decltype = sqlite3_column_decltype(self->statement->st, i);
             if (decltype) {
                 for (pos = decltype;;pos++) {
@@ -211,7 +211,7 @@ int build_row_cast_map(Cursor* self)
                     }
                 }
 
-                converter = _get_converter(py_decltype);
+                converter = _pysqlite_get_converter(py_decltype);
                 Py_DECREF(py_decltype);
             }
         }
@@ -234,7 +234,7 @@ int build_row_cast_map(Cursor* self)
     return 0;
 }
 
-PyObject* _build_column_name(const char* colname)
+PyObject* _pysqlite_build_column_name(const char* colname)
 {
     const char* pos;
 
@@ -253,7 +253,7 @@ PyObject* _build_column_name(const char* colname)
     }
 }
 
-PyObject* unicode_from_string(const char* val_str, int optimize)
+PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize)
 {
     const char* check;
     int is_ascii = 0;
@@ -285,7 +285,7 @@ PyObject* unicode_from_string(const char* val_str, int optimize)
  * Precondidition:
  * - sqlite3_step() has been called before and it returned SQLITE_ROW.
  */
-PyObject* _fetch_one_row(Cursor* self)
+PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
 {
     int i, numcols;
     PyObject* row;
@@ -356,10 +356,10 @@ PyObject* _fetch_one_row(Cursor* self)
             } else if (coltype == SQLITE_TEXT) {
                 val_str = (const char*)sqlite3_column_text(self->statement->st, i);
                 if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type)
-                    || (self->connection->text_factory == OptimizedUnicode)) {
+                    || (self->connection->text_factory == pysqlite_OptimizedUnicode)) {
 
-                    converted = unicode_from_string(val_str,
-                        self->connection->text_factory == OptimizedUnicode ? 1 : 0);
+                    converted = pysqlite_unicode_from_string(val_str,
+                        self->connection->text_factory == pysqlite_OptimizedUnicode ? 1 : 0);
 
                     if (!converted) {
                         colname = sqlite3_column_name(self->statement->st, i);
@@ -368,7 +368,7 @@ PyObject* _fetch_one_row(Cursor* self)
                         }
                         PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
                                      colname , val_str);
-                        PyErr_SetString(OperationalError, buf);
+                        PyErr_SetString(pysqlite_OperationalError, buf);
                     }
                 } else if (self->connection->text_factory == (PyObject*)&PyString_Type) {
                     converted = PyString_FromString(val_str);
@@ -406,7 +406,7 @@ PyObject* _fetch_one_row(Cursor* self)
     return row;
 }
 
-PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
+PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
 {
     PyObject* operation;
     PyObject* operation_bytestr = NULL;
@@ -425,7 +425,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
     PyObject* second_argument = NULL;
     long rowcount = 0;
 
-    if (!check_thread(self->connection) || !check_connection(self->connection)) {
+    if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
         return NULL;
     }
 
@@ -492,7 +492,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
 
     if (self->statement != NULL) {
         /* There is an active statement */
-        rc = statement_reset(self->statement);
+        rc = pysqlite_statement_reset(self->statement);
     }
 
     if (PyString_Check(operation)) {
@@ -525,7 +525,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
             case STATEMENT_INSERT:
             case STATEMENT_REPLACE:
                 if (!self->connection->inTransaction) {
-                    result = _connection_begin(self->connection);
+                    result = _pysqlite_connection_begin(self->connection);
                     if (!result) {
                         goto error;
                     }
@@ -536,7 +536,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
                 /* it's a DDL statement or something similar
                    - we better COMMIT first so it works for all cases */
                 if (self->connection->inTransaction) {
-                    result = connection_commit(self->connection, NULL);
+                    result = pysqlite_connection_commit(self->connection, NULL);
                     if (!result) {
                         goto error;
                     }
@@ -545,7 +545,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
                 break;
             case STATEMENT_SELECT:
                 if (multiple) {
-                    PyErr_SetString(ProgrammingError,
+                    PyErr_SetString(pysqlite_ProgrammingError,
                                 "You cannot execute SELECT statements in executemany().");
                     goto error;
                 }
@@ -563,11 +563,11 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
     }
 
     if (self->statement) {
-        (void)statement_reset(self->statement);
+        (void)pysqlite_statement_reset(self->statement);
         Py_DECREF(self->statement);
     }
 
-    self->statement = (Statement*)cache_get(self->connection->statement_cache, func_args);
+    self->statement = (pysqlite_Statement*)pysqlite_cache_get(self->connection->statement_cache, func_args);
     Py_DECREF(func_args);
 
     if (!self->statement) {
@@ -576,19 +576,19 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
 
     if (self->statement->in_use) {
         Py_DECREF(self->statement);
-        self->statement = PyObject_New(Statement, &StatementType);
+        self->statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
         if (!self->statement) {
             goto error;
         }
-        rc = statement_create(self->statement, self->connection, operation);
+        rc = pysqlite_statement_create(self->statement, self->connection, operation);
         if (rc != SQLITE_OK) {
             self->statement = 0;
             goto error;
         }
     }
 
-    statement_reset(self->statement);
-    statement_mark_dirty(self->statement);
+    pysqlite_statement_reset(self->statement);
+    pysqlite_statement_mark_dirty(self->statement);
 
     while (1) {
         parameters = PyIter_Next(parameters_iter);
@@ -596,27 +596,37 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
             break;
         }
 
-        statement_mark_dirty(self->statement);
+        pysqlite_statement_mark_dirty(self->statement);
 
-        statement_bind_parameters(self->statement, parameters);
+        pysqlite_statement_bind_parameters(self->statement, parameters);
         if (PyErr_Occurred()) {
             goto error;
         }
 
-        if (build_row_cast_map(self) != 0) {
-            PyErr_SetString(OperationalError, "Error while building row_cast_map");
+        if (pysqlite_build_row_cast_map(self) != 0) {
+            PyErr_SetString(pysqlite_OperationalError, "Error while building row_cast_map");
             goto error;
         }
 
-        rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection);
-        if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
-            rc = statement_reset(self->statement);
+        /* Keep trying the SQL statement until the schema stops changing. */
+        while (1) {
+            /* Actually execute the SQL statement. */
+            rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection);
+            if (rc == SQLITE_DONE ||  rc == SQLITE_ROW) {
+                /* If it worked, let's get out of the loop */
+                break;
+            }
+            /* Something went wrong.  Re-set the statement and try again. */
+            rc = pysqlite_statement_reset(self->statement);
             if (rc == SQLITE_SCHEMA) {
-                rc = statement_recompile(self->statement, parameters);
+                /* If this was a result of the schema changing, let's try
+                   again. */
+                rc = pysqlite_statement_recompile(self->statement, parameters);
                 if (rc == SQLITE_OK) {
-                    rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection);
+                    continue;
                 } else {
-                    _seterror(self->connection->db);
+                    /* If the database gave us an error, promote it to Python. */
+                    _pysqlite_seterror(self->connection->db);
                     goto error;
                 }
             } else {
@@ -628,7 +638,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
                         PyErr_Clear();
                     }
                 }
-                _seterror(self->connection->db);
+                _pysqlite_seterror(self->connection->db);
                 goto error;
             }
         }
@@ -649,7 +659,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
                     if (!descriptor) {
                         goto error;
                     }
-                    PyTuple_SetItem(descriptor, 0, _build_column_name(sqlite3_column_name(self->statement->st, i)));
+                    PyTuple_SetItem(descriptor, 0, _pysqlite_build_column_name(sqlite3_column_name(self->statement->st, i)));
                     Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None);
                     Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None);
                     Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None);
@@ -663,13 +673,13 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
 
         if (rc == SQLITE_ROW) {
             if (multiple) {
-                PyErr_SetString(ProgrammingError, "executemany() can only execute DML statements.");
+                PyErr_SetString(pysqlite_ProgrammingError, "executemany() can only execute DML statements.");
                 goto error;
             }
 
-            self->next_row = _fetch_one_row(self);
+            self->next_row = _pysqlite_fetch_one_row(self);
         } else if (rc == SQLITE_DONE && !multiple) {
-            statement_reset(self->statement);
+            pysqlite_statement_reset(self->statement);
             Py_DECREF(self->statement);
             self->statement = 0;
         }
@@ -698,7 +708,7 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
         }
 
         if (multiple) {
-            rc = statement_reset(self->statement);
+            rc = pysqlite_statement_reset(self->statement);
         }
         Py_XDECREF(parameters);
     }
@@ -717,17 +727,17 @@ error:
     }
 }
 
-PyObject* cursor_execute(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_execute(pysqlite_Cursor* self, PyObject* args)
 {
-    return _query_execute(self, 0, args);
+    return _pysqlite_query_execute(self, 0, args);
 }
 
-PyObject* cursor_executemany(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_executemany(pysqlite_Cursor* self, PyObject* args)
 {
-    return _query_execute(self, 1, args);
+    return _pysqlite_query_execute(self, 1, args);
 }
 
-PyObject* cursor_executescript(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
 {
     PyObject* script_obj;
     PyObject* script_str = NULL;
@@ -741,7 +751,7 @@ PyObject* cursor_executescript(Cursor* self, PyObject* args)
         return NULL; 
     }
 
-    if (!check_thread(self->connection) || !check_connection(self->connection)) {
+    if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
         return NULL;
     }
 
@@ -760,7 +770,7 @@ PyObject* cursor_executescript(Cursor* self, PyObject* args)
     }
 
     /* commit first */
-    result = connection_commit(self->connection, NULL);
+    result = pysqlite_connection_commit(self->connection, NULL);
     if (!result) {
         goto error;
     }
@@ -778,7 +788,7 @@ PyObject* cursor_executescript(Cursor* self, PyObject* args)
                              &statement,
                              &script_cstr);
         if (rc != SQLITE_OK) {
-            _seterror(self->connection->db);
+            _pysqlite_seterror(self->connection->db);
             goto error;
         }
 
@@ -790,13 +800,13 @@ PyObject* cursor_executescript(Cursor* self, PyObject* args)
 
         if (rc != SQLITE_DONE) {
             (void)sqlite3_finalize(statement);
-            _seterror(self->connection->db);
+            _pysqlite_seterror(self->connection->db);
             goto error;
         }
 
         rc = sqlite3_finalize(statement);
         if (rc != SQLITE_OK) {
-            _seterror(self->connection->db);
+            _pysqlite_seterror(self->connection->db);
             goto error;
         }
     }
@@ -805,7 +815,7 @@ error:
     Py_XDECREF(script_str);
 
     if (!statement_completed) {
-        PyErr_SetString(ProgrammingError, "you did not provide a complete SQL statement");
+        PyErr_SetString(pysqlite_ProgrammingError, "you did not provide a complete SQL statement");
     }
 
     if (PyErr_Occurred()) {
@@ -816,25 +826,25 @@ error:
     }
 }
 
-PyObject* cursor_getiter(Cursor *self)
+PyObject* pysqlite_cursor_getiter(pysqlite_Cursor *self)
 {
     Py_INCREF(self);
     return (PyObject*)self;
 }
 
-PyObject* cursor_iternext(Cursor *self)
+PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
 {
     PyObject* next_row_tuple;
     PyObject* next_row;
     int rc;
 
-    if (!check_thread(self->connection) || !check_connection(self->connection)) {
+    if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
         return NULL;
     }
 
     if (!self->next_row) {
          if (self->statement) {
-            (void)statement_reset(self->statement);
+            (void)pysqlite_statement_reset(self->statement);
             Py_DECREF(self->statement);
             self->statement = NULL;
         }
@@ -851,25 +861,27 @@ PyObject* cursor_iternext(Cursor *self)
         next_row = next_row_tuple;
     }
 
-    rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection);
-    if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
-        Py_DECREF(next_row);
-        _seterror(self->connection->db);
-        return NULL;
-    }
+    if (self->statement) {
+        rc = _sqlite_step_with_busyhandler(self->statement->st, self->connection);
+        if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
+            Py_DECREF(next_row);
+            _pysqlite_seterror(self->connection->db);
+            return NULL;
+        }
 
-    if (rc == SQLITE_ROW) {
-        self->next_row = _fetch_one_row(self);
+        if (rc == SQLITE_ROW) {
+            self->next_row = _pysqlite_fetch_one_row(self);
+        }
     }
 
     return next_row;
 }
 
-PyObject* cursor_fetchone(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_fetchone(pysqlite_Cursor* self, PyObject* args)
 {
     PyObject* row;
 
-    row = cursor_iternext(self);
+    row = pysqlite_cursor_iternext(self);
     if (!row && !PyErr_Occurred()) {
         Py_INCREF(Py_None);
         return Py_None;
@@ -878,7 +890,7 @@ PyObject* cursor_fetchone(Cursor* self, PyObject* args)
     return row;
 }
 
-PyObject* cursor_fetchmany(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args)
 {
     PyObject* row;
     PyObject* list;
@@ -898,7 +910,7 @@ PyObject* cursor_fetchmany(Cursor* self, PyObject* args)
     row = Py_None;
 
     while (row) {
-        row = cursor_iternext(self);
+        row = pysqlite_cursor_iternext(self);
         if (row) {
             PyList_Append(list, row);
             Py_DECREF(row);
@@ -919,7 +931,7 @@ PyObject* cursor_fetchmany(Cursor* self, PyObject* args)
     }
 }
 
-PyObject* cursor_fetchall(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_fetchall(pysqlite_Cursor* self, PyObject* args)
 {
     PyObject* row;
     PyObject* list;
@@ -933,7 +945,7 @@ PyObject* cursor_fetchall(Cursor* self, PyObject* args)
     row = (PyObject*)Py_None;
 
     while (row) {
-        row = cursor_iternext(self);
+        row = pysqlite_cursor_iternext(self);
         if (row) {
             PyList_Append(list, row);
             Py_DECREF(row);
@@ -948,21 +960,21 @@ PyObject* cursor_fetchall(Cursor* self, PyObject* args)
     }
 }
 
-PyObject* pysqlite_noop(Connection* self, PyObject* args)
+PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args)
 {
     /* don't care, return None */
     Py_INCREF(Py_None);
     return Py_None;
 }
 
-PyObject* cursor_close(Cursor* self, PyObject* args)
+PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
 {
-    if (!check_thread(self->connection) || !check_connection(self->connection)) {
+    if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
         return NULL;
     }
 
     if (self->statement) {
-        (void)statement_reset(self->statement);
+        (void)pysqlite_statement_reset(self->statement);
         Py_DECREF(self->statement);
         self->statement = 0;
     }
@@ -972,19 +984,19 @@ PyObject* cursor_close(Cursor* self, PyObject* args)
 }
 
 static PyMethodDef cursor_methods[] = {
-    {"execute", (PyCFunction)cursor_execute, METH_VARARGS,
+    {"execute", (PyCFunction)pysqlite_cursor_execute, METH_VARARGS,
         PyDoc_STR("Executes a SQL statement.")},
-    {"executemany", (PyCFunction)cursor_executemany, METH_VARARGS,
+    {"executemany", (PyCFunction)pysqlite_cursor_executemany, METH_VARARGS,
         PyDoc_STR("Repeatedly executes a SQL statement.")},
-    {"executescript", (PyCFunction)cursor_executescript, METH_VARARGS,
+    {"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_VARARGS,
         PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
-    {"fetchone", (PyCFunction)cursor_fetchone, METH_NOARGS,
+    {"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS,
         PyDoc_STR("Fetches several rows from the resultset.")},
-    {"fetchmany", (PyCFunction)cursor_fetchmany, METH_VARARGS,
+    {"fetchmany", (PyCFunction)pysqlite_cursor_fetchmany, METH_VARARGS,
         PyDoc_STR("Fetches all rows from the resultset.")},
-    {"fetchall", (PyCFunction)cursor_fetchall, METH_NOARGS,
+    {"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS,
         PyDoc_STR("Fetches one row from the resultset.")},
-    {"close", (PyCFunction)cursor_close, METH_NOARGS,
+    {"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS,
         PyDoc_STR("Closes the cursor.")},
     {"setinputsizes", (PyCFunction)pysqlite_noop, METH_VARARGS,
         PyDoc_STR("Required by DB-API. Does nothing in pysqlite.")},
@@ -995,25 +1007,25 @@ static PyMethodDef cursor_methods[] = {
 
 static struct PyMemberDef cursor_members[] =
 {
-    {"connection", T_OBJECT, offsetof(Cursor, connection), RO},
-    {"description", T_OBJECT, offsetof(Cursor, description), RO},
-    {"arraysize", T_INT, offsetof(Cursor, arraysize), 0},
-    {"lastrowid", T_OBJECT, offsetof(Cursor, lastrowid), RO},
-    {"rowcount", T_OBJECT, offsetof(Cursor, rowcount), RO},
-    {"row_factory", T_OBJECT, offsetof(Cursor, row_factory), 0},
+    {"connection", T_OBJECT, offsetof(pysqlite_Cursor, connection), RO},
+    {"description", T_OBJECT, offsetof(pysqlite_Cursor, description), RO},
+    {"arraysize", T_INT, offsetof(pysqlite_Cursor, arraysize), 0},
+    {"lastrowid", T_OBJECT, offsetof(pysqlite_Cursor, lastrowid), RO},
+    {"rowcount", T_OBJECT, offsetof(pysqlite_Cursor, rowcount), RO},
+    {"row_factory", T_OBJECT, offsetof(pysqlite_Cursor, row_factory), 0},
     {NULL}
 };
 
 static char cursor_doc[] =
 PyDoc_STR("SQLite database cursor class.");
 
-PyTypeObject CursorType = {
+PyTypeObject pysqlite_CursorType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".Cursor",                          /* tp_name */
-        sizeof(Cursor),                                 /* tp_basicsize */
+        sizeof(pysqlite_Cursor),                        /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)cursor_dealloc,                     /* tp_dealloc */
+        (destructor)pysqlite_cursor_dealloc,            /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -1034,8 +1046,8 @@ PyTypeObject CursorType = {
         0,                                              /* tp_clear */
         0,                                              /* tp_richcompare */
         0,                                              /* tp_weaklistoffset */
-        (getiterfunc)cursor_getiter,                    /* tp_iter */
-        (iternextfunc)cursor_iternext,                  /* tp_iternext */
+        (getiterfunc)pysqlite_cursor_getiter,           /* tp_iter */
+        (iternextfunc)pysqlite_cursor_iternext,         /* tp_iternext */
         cursor_methods,                                 /* tp_methods */
         cursor_members,                                 /* tp_members */
         0,                                              /* tp_getset */
@@ -1044,14 +1056,14 @@ PyTypeObject CursorType = {
         0,                                              /* tp_descr_get */
         0,                                              /* tp_descr_set */
         0,                                              /* tp_dictoffset */
-        (initproc)cursor_init,                          /* tp_init */
+        (initproc)pysqlite_cursor_init,                 /* tp_init */
         0,                                              /* tp_alloc */
         0,                                              /* tp_new */
         0                                               /* tp_free */
 };
 
-extern int cursor_setup_types(void)
+extern int pysqlite_cursor_setup_types(void)
 {
-    CursorType.tp_new = PyType_GenericNew;
-    return PyType_Ready(&CursorType);
+    pysqlite_CursorType.tp_new = PyType_GenericNew;
+    return PyType_Ready(&pysqlite_CursorType);
 }
index 831ff81..5fce64a 100644 (file)
 typedef struct
 {
     PyObject_HEAD
-    Connection* connection;
+    pysqlite_Connection* connection;
     PyObject* description;
     PyObject* row_cast_map;
     int arraysize;
     PyObject* lastrowid;
     PyObject* rowcount;
     PyObject* row_factory;
-    Statement* statement;
+    pysqlite_Statement* statement;
 
     /* the next row to be returned, NULL if no next row available */
     PyObject* next_row;
-} Cursor;
+} pysqlite_Cursor;
 
 typedef enum {
     STATEMENT_INVALID, STATEMENT_INSERT, STATEMENT_DELETE,
     STATEMENT_UPDATE, STATEMENT_REPLACE, STATEMENT_SELECT,
     STATEMENT_OTHER
-} StatementKind;
+} pysqlite_StatementKind;
 
-extern PyTypeObject CursorType;
+extern PyTypeObject pysqlite_CursorType;
 
-int cursor_init(Cursor* self, PyObject* args, PyObject* kwargs);
-void cursor_dealloc(Cursor* self);
-PyObject* cursor_execute(Cursor* self, PyObject* args);
-PyObject* cursor_executemany(Cursor* self, PyObject* args);
-PyObject* cursor_getiter(Cursor *self);
-PyObject* cursor_iternext(Cursor *self);
-PyObject* cursor_fetchone(Cursor* self, PyObject* args);
-PyObject* cursor_fetchmany(Cursor* self, PyObject* args);
-PyObject* cursor_fetchall(Cursor* self, PyObject* args);
-PyObject* pysqlite_noop(Connection* self, PyObject* args);
-PyObject* cursor_close(Cursor* self, PyObject* args);
+int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject* kwargs);
+void pysqlite_cursor_dealloc(pysqlite_Cursor* self);
+PyObject* pysqlite_cursor_execute(pysqlite_Cursor* self, PyObject* args);
+PyObject* pysqlite_cursor_executemany(pysqlite_Cursor* self, PyObject* args);
+PyObject* pysqlite_cursor_getiter(pysqlite_Cursor *self);
+PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self);
+PyObject* pysqlite_cursor_fetchone(pysqlite_Cursor* self, PyObject* args);
+PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args);
+PyObject* pysqlite_cursor_fetchall(pysqlite_Cursor* self, PyObject* args);
+PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args);
+PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args);
 
-int cursor_setup_types(void);
+int pysqlite_cursor_setup_types(void);
 
 #define UNKNOWN (-1)
 #endif
index 4956ac0..5a78917 100644 (file)
@@ -57,7 +57,7 @@ microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast)
     PyObject* key;
     int rc;
 
-    if (proto == NULL) proto = (PyObject*)&SQLitePrepareProtocolType;
+    if (proto == NULL) proto = (PyObject*)&pysqlite_PrepareProtocolType;
 
     key = Py_BuildValue("(OO)", (PyObject*)type, proto);
     if (!key) {
@@ -78,7 +78,7 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
     PyObject *adapter, *key;
 
     /* we don't check for exact type conformance as specified in PEP 246
-       because the SQLitePrepareProtocolType type is abstract and there is no
+       because the pysqlite_PrepareProtocolType type is abstract and there is no
        way to get a quotable object to be its instance */
 
     /* look for an adapter in the registry */
@@ -125,17 +125,17 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
     }
 
     /* else set the right exception and return NULL */
-    PyErr_SetString(ProgrammingError, "can't adapt");
+    PyErr_SetString(pysqlite_ProgrammingError, "can't adapt");
     return NULL;
 }
 
 /** module-level functions **/
 
 PyObject *
-psyco_microprotocols_adapt(Cursor *self, PyObject *args)
+psyco_microprotocols_adapt(pysqlite_Cursor *self, PyObject *args)
 {
     PyObject *obj, *alt = NULL;
-    PyObject *proto = (PyObject*)&SQLitePrepareProtocolType;
+    PyObject *proto = (PyObject*)&pysqlite_PrepareProtocolType;
 
     if (!PyArg_ParseTuple(args, "O|OO", &obj, &proto, &alt)) return NULL;
     return microprotocols_adapt(obj, proto, alt);
index f601bb3..d84ec93 100644 (file)
@@ -52,7 +52,7 @@ extern PyObject *microprotocols_adapt(
     PyObject *obj, PyObject *proto, PyObject *alt);
 
 extern PyObject *
-    psyco_microprotocols_adapt(Cursor* self, PyObject *args);   
+    psyco_microprotocols_adapt(pysqlite_Cursor* self, PyObject *args);   
 #define psyco_microprotocols_adapt_doc \
     "adapt(obj, protocol, alternate) -> adapt obj to given protocol. Non-standard."
 
index 38b5917..d066d9b 100644 (file)
@@ -35,9 +35,9 @@
 
 /* static objects at module-level */
 
-PyObject* Error, *Warning, *InterfaceError, *DatabaseError, *InternalError,
-    *OperationalError, *ProgrammingError, *IntegrityError, *DataError,
-    *NotSupportedError, *OptimizedUnicode;
+PyObject* pysqlite_Error, *pysqlite_Warning, *pysqlite_InterfaceError, *pysqlite_DatabaseError,
+    *pysqlite_InternalError, *pysqlite_OperationalError, *pysqlite_ProgrammingError,
+    *pysqlite_IntegrityError, *pysqlite_DataError, *pysqlite_NotSupportedError, *pysqlite_OptimizedUnicode;
 
 PyObject* converters;
 int _enable_callback_tracebacks;
@@ -67,7 +67,7 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
     }
 
     if (factory == NULL) {
-        factory = (PyObject*)&ConnectionType;
+        factory = (PyObject*)&pysqlite_ConnectionType;
     }
 
     result = PyObject_Call(factory, args, kwargs);
@@ -115,7 +115,7 @@ static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyOb
     rc = sqlite3_enable_shared_cache(do_enable);
 
     if (rc != SQLITE_OK) {
-        PyErr_SetString(OperationalError, "Changing the shared_cache flag failed");
+        PyErr_SetString(pysqlite_OperationalError, "Changing the shared_cache flag failed");
         return NULL;
     } else {
         Py_INCREF(Py_None);
@@ -133,7 +133,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
         return NULL;
     }
 
-    microprotocols_add(type, (PyObject*)&SQLitePrepareProtocolType, caster);
+    microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -141,36 +141,29 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
 
 static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObject* kwargs)
 {
-    char* orig_name;
-    char* name = NULL;
-    char* c;
+    PyObject* orig_name;
+    PyObject* name = NULL;
     PyObject* callable;
     PyObject* retval = NULL;
 
-    if (!PyArg_ParseTuple(args, "sO", &orig_name, &callable)) {
+    if (!PyArg_ParseTuple(args, "SO", &orig_name, &callable)) {
         return NULL;
     }
 
-    /* convert the name to lowercase */
-    name = PyMem_Malloc(strlen(orig_name) + 2);
+    /* convert the name to upper case */
+    name = PyObject_CallMethod(orig_name, "upper", "");
     if (!name) {
         goto error;
     }
-    strcpy(name, orig_name);
-    for (c = name; *c != (char)0; c++) {
-        *c = (*c) & 0xDF;
-    }
 
-    if (PyDict_SetItemString(converters, name, callable) != 0) {
+    if (PyDict_SetItem(converters, name, callable) != 0) {
         goto error;
     }
 
     Py_INCREF(Py_None);
     retval = Py_None;
 error:
-    if (name) {
-        PyMem_Free(name);
-    }
+    Py_XDECREF(name);
     return retval;
 }
 
@@ -184,7 +177,7 @@ static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args, PyOb
     return Py_None;
 }
 
-void converters_init(PyObject* dict)
+static void converters_init(PyObject* dict)
 {
     converters = PyDict_New();
     if (!converters) {
@@ -265,28 +258,28 @@ PyMODINIT_FUNC init_sqlite(void)
     module = Py_InitModule("pysqlite2._sqlite", module_methods);
 
     if (!module ||
-        (row_setup_types() < 0) ||
-        (cursor_setup_types() < 0) ||
-        (connection_setup_types() < 0) ||
-        (cache_setup_types() < 0) ||
-        (statement_setup_types() < 0) ||
-        (prepare_protocol_setup_types() < 0)
+        (pysqlite_row_setup_types() < 0) ||
+        (pysqlite_cursor_setup_types() < 0) ||
+        (pysqlite_connection_setup_types() < 0) ||
+        (pysqlite_cache_setup_types() < 0) ||
+        (pysqlite_statement_setup_types() < 0) ||
+        (pysqlite_prepare_protocol_setup_types() < 0)
        ) {
         return;
     }
 
-    Py_INCREF(&ConnectionType);
-    PyModule_AddObject(module, "Connection", (PyObject*) &ConnectionType);
-    Py_INCREF(&CursorType);
-    PyModule_AddObject(module, "Cursor", (PyObject*) &CursorType);
-    Py_INCREF(&CacheType);
-    PyModule_AddObject(module, "Statement", (PyObject*)&StatementType);
-    Py_INCREF(&StatementType);
-    PyModule_AddObject(module, "Cache", (PyObject*) &CacheType);
-    Py_INCREF(&SQLitePrepareProtocolType);
-    PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &SQLitePrepareProtocolType);
-    Py_INCREF(&RowType);
-    PyModule_AddObject(module, "Row", (PyObject*) &RowType);
+    Py_INCREF(&pysqlite_ConnectionType);
+    PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType);
+    Py_INCREF(&pysqlite_CursorType);
+    PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType);
+    Py_INCREF(&pysqlite_CacheType);
+    PyModule_AddObject(module, "Statement", (PyObject*)&pysqlite_StatementType);
+    Py_INCREF(&pysqlite_StatementType);
+    PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheType);
+    Py_INCREF(&pysqlite_PrepareProtocolType);
+    PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType);
+    Py_INCREF(&pysqlite_RowType);
+    PyModule_AddObject(module, "Row", (PyObject*) &pysqlite_RowType);
 
     if (!(dict = PyModule_GetDict(module))) {
         goto error;
@@ -294,67 +287,67 @@ PyMODINIT_FUNC init_sqlite(void)
 
     /*** Create DB-API Exception hierarchy */
 
-    if (!(Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_StandardError, NULL))) {
+    if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_StandardError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "Error", Error);
+    PyDict_SetItemString(dict, "Error", pysqlite_Error);
 
-    if (!(Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_StandardError, NULL))) {
+    if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_StandardError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "Warning", Warning);
+    PyDict_SetItemString(dict, "Warning", pysqlite_Warning);
 
     /* Error subclasses */
 
-    if (!(InterfaceError = PyErr_NewException(MODULE_NAME ".InterfaceError", Error, NULL))) {
+    if (!(pysqlite_InterfaceError = PyErr_NewException(MODULE_NAME ".InterfaceError", pysqlite_Error, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "InterfaceError", InterfaceError);
+    PyDict_SetItemString(dict, "InterfaceError", pysqlite_InterfaceError);
 
-    if (!(DatabaseError = PyErr_NewException(MODULE_NAME ".DatabaseError", Error, NULL))) {
+    if (!(pysqlite_DatabaseError = PyErr_NewException(MODULE_NAME ".DatabaseError", pysqlite_Error, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "DatabaseError", DatabaseError);
+    PyDict_SetItemString(dict, "DatabaseError", pysqlite_DatabaseError);
 
-    /* DatabaseError subclasses */
+    /* pysqlite_DatabaseError subclasses */
 
-    if (!(InternalError = PyErr_NewException(MODULE_NAME ".InternalError", DatabaseError, NULL))) {
+    if (!(pysqlite_InternalError = PyErr_NewException(MODULE_NAME ".InternalError", pysqlite_DatabaseError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "InternalError", InternalError);
+    PyDict_SetItemString(dict, "InternalError", pysqlite_InternalError);
 
-    if (!(OperationalError = PyErr_NewException(MODULE_NAME ".OperationalError", DatabaseError, NULL))) {
+    if (!(pysqlite_OperationalError = PyErr_NewException(MODULE_NAME ".OperationalError", pysqlite_DatabaseError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "OperationalError", OperationalError);
+    PyDict_SetItemString(dict, "OperationalError", pysqlite_OperationalError);
 
-    if (!(ProgrammingError = PyErr_NewException(MODULE_NAME ".ProgrammingError", DatabaseError, NULL))) {
+    if (!(pysqlite_ProgrammingError = PyErr_NewException(MODULE_NAME ".ProgrammingError", pysqlite_DatabaseError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "ProgrammingError", ProgrammingError);
+    PyDict_SetItemString(dict, "ProgrammingError", pysqlite_ProgrammingError);
 
-    if (!(IntegrityError = PyErr_NewException(MODULE_NAME ".IntegrityError", DatabaseError,NULL))) {
+    if (!(pysqlite_IntegrityError = PyErr_NewException(MODULE_NAME ".IntegrityError", pysqlite_DatabaseError,NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "IntegrityError", IntegrityError);
+    PyDict_SetItemString(dict, "IntegrityError", pysqlite_IntegrityError);
 
-    if (!(DataError = PyErr_NewException(MODULE_NAME ".DataError", DatabaseError, NULL))) {
+    if (!(pysqlite_DataError = PyErr_NewException(MODULE_NAME ".DataError", pysqlite_DatabaseError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "DataError", DataError);
+    PyDict_SetItemString(dict, "DataError", pysqlite_DataError);
 
-    if (!(NotSupportedError = PyErr_NewException(MODULE_NAME ".NotSupportedError", DatabaseError, NULL))) {
+    if (!(pysqlite_NotSupportedError = PyErr_NewException(MODULE_NAME ".NotSupportedError", pysqlite_DatabaseError, NULL))) {
         goto error;
     }
-    PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
+    PyDict_SetItemString(dict, "NotSupportedError", pysqlite_NotSupportedError);
 
-    /* We just need "something" unique for OptimizedUnicode. It does not really
+    /* We just need "something" unique for pysqlite_OptimizedUnicode. It does not really
      * need to be a string subclass. Just anything that can act as a special
      * marker for us. So I pulled PyCell_Type out of my magic hat.
      */
     Py_INCREF((PyObject*)&PyCell_Type);
-    OptimizedUnicode = (PyObject*)&PyCell_Type;
-    PyDict_SetItemString(dict, "OptimizedUnicode", OptimizedUnicode);
+    pysqlite_OptimizedUnicode = (PyObject*)&PyCell_Type;
+    PyDict_SetItemString(dict, "OptimizedUnicode", pysqlite_OptimizedUnicode);
 
     /* Set integer constants */
     for (i = 0; _int_constants[i].constant_name != 0; i++) {
index e514bd1..ada6b4c 100644 (file)
 #define PYSQLITE_MODULE_H
 #include "Python.h"
 
-#define PYSQLITE_VERSION "2.3.2"
-
-extern PyObject* Error;
-extern PyObject* Warning;
-extern PyObject* InterfaceError;
-extern PyObject* DatabaseError;
-extern PyObject* InternalError;
-extern PyObject* OperationalError;
-extern PyObject* ProgrammingError;
-extern PyObject* IntegrityError;
-extern PyObject* DataError;
-extern PyObject* NotSupportedError;
-
-extern PyObject* OptimizedUnicode;
+#define PYSQLITE_VERSION "2.3.3"
+
+extern PyObject* pysqlite_Error;
+extern PyObject* pysqlite_Warning;
+extern PyObject* pysqlite_InterfaceError;
+extern PyObject* pysqlite_DatabaseError;
+extern PyObject* pysqlite_InternalError;
+extern PyObject* pysqlite_OperationalError;
+extern PyObject* pysqlite_ProgrammingError;
+extern PyObject* pysqlite_IntegrityError;
+extern PyObject* pysqlite_DataError;
+extern PyObject* pysqlite_NotSupportedError;
+
+extern PyObject* pysqlite_OptimizedUnicode;
 
 /* the functions time.time() and time.sleep() */
 extern PyObject* time_time;
index 26b663b..a8ca518 100644 (file)
 
 #include "prepare_protocol.h"
 
-int prepare_protocol_init(SQLitePrepareProtocol* self, PyObject* args, PyObject* kwargs)
+int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs)
 {
     return 0;
 }
 
-void prepare_protocol_dealloc(SQLitePrepareProtocol* self)
+void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self)
 {
     self->ob_type->tp_free((PyObject*)self);
 }
 
-PyTypeObject SQLitePrepareProtocolType= {
+PyTypeObject pysqlite_PrepareProtocolType= {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".PrepareProtocol",                 /* tp_name */
-        sizeof(SQLitePrepareProtocol),                  /* tp_basicsize */
+        sizeof(pysqlite_PrepareProtocol),               /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)prepare_protocol_dealloc,           /* tp_dealloc */
+        (destructor)pysqlite_prepare_protocol_dealloc,  /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -70,15 +70,15 @@ PyTypeObject SQLitePrepareProtocolType= {
         0,                                              /* tp_descr_get */
         0,                                              /* tp_descr_set */
         0,                                              /* tp_dictoffset */
-        (initproc)prepare_protocol_init,                /* tp_init */
+        (initproc)pysqlite_prepare_protocol_init,       /* tp_init */
         0,                                              /* tp_alloc */
         0,                                              /* tp_new */
         0                                               /* tp_free */
 };
 
-extern int prepare_protocol_setup_types(void)
+extern int pysqlite_prepare_protocol_setup_types(void)
 {
-    SQLitePrepareProtocolType.tp_new = PyType_GenericNew;
-    SQLitePrepareProtocolType.ob_type= &PyType_Type;
-    return PyType_Ready(&SQLitePrepareProtocolType);
+    pysqlite_PrepareProtocolType.tp_new = PyType_GenericNew;
+    pysqlite_PrepareProtocolType.ob_type= &PyType_Type;
+    return PyType_Ready(&pysqlite_PrepareProtocolType);
 }
index 2fc4f61..4c1e4f3 100644 (file)
 typedef struct
 {
     PyObject_HEAD
-} SQLitePrepareProtocol;
+} pysqlite_PrepareProtocol;
 
-extern PyTypeObject SQLitePrepareProtocolType;
+extern PyTypeObject pysqlite_PrepareProtocolType;
 
-int prepare_protocol_init(SQLitePrepareProtocol* self, PyObject* args, PyObject* kwargs);
-void prepare_protocol_dealloc(SQLitePrepareProtocol* self);
+int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs);
+void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self);
 
-int prepare_protocol_setup_types(void);
+int pysqlite_prepare_protocol_setup_types(void);
 
 #define UNKNOWN (-1)
 #endif
index 80b6135..7cfcfc3 100644 (file)
--- a/src/row.c
+++ b/src/row.c
@@ -25,7 +25,7 @@
 #include "cursor.h"
 #include "sqlitecompat.h"
 
-void row_dealloc(Row* self)
+void pysqlite_row_dealloc(pysqlite_Row* self)
 {
     Py_XDECREF(self->data);
     Py_XDECREF(self->description);
@@ -33,10 +33,10 @@ void row_dealloc(Row* self)
     self->ob_type->tp_free((PyObject*)self);
 }
 
-int row_init(Row* self, PyObject* args, PyObject* kwargs)
+int pysqlite_row_init(pysqlite_Row* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* data;
-    Cursor* cursor;
+    pysqlite_Cursor* cursor;
 
     self->data = 0;
     self->description = 0;
@@ -45,7 +45,7 @@ int row_init(Row* self, PyObject* args, PyObject* kwargs)
         return -1;
     }
 
-    if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&CursorType)) {
+    if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&pysqlite_CursorType)) {
         PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument");
         return -1;
     }
@@ -64,7 +64,7 @@ int row_init(Row* self, PyObject* args, PyObject* kwargs)
     return 0;
 }
 
-PyObject* row_subscript(Row* self, PyObject* idx)
+PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
 {
     long _idx;
     char* key;
@@ -133,32 +133,63 @@ PyObject* row_subscript(Row* self, PyObject* idx)
     }
 }
 
-Py_ssize_t row_length(Row* self, PyObject* args, PyObject* kwargs)
+Py_ssize_t pysqlite_row_length(pysqlite_Row* self, PyObject* args, PyObject* kwargs)
 {
     return PyTuple_GET_SIZE(self->data);
 }
 
-static int row_print(Row* self, FILE *fp, int flags)
+PyObject* pysqlite_row_keys(pysqlite_Row* self, PyObject* args, PyObject* kwargs)
+{
+    PyObject* list;
+    int nitems, i;
+
+    list = PyList_New(0);
+    if (!list) {
+        return NULL;
+    }
+    nitems = PyTuple_Size(self->description);
+
+    for (i = 0; i < nitems; i++) {
+        if (PyList_Append(list, PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)) != 0) {
+            Py_DECREF(list);
+            return NULL;
+        }
+    }
+
+    return list;
+}
+
+static int pysqlite_row_print(pysqlite_Row* self, FILE *fp, int flags)
 {
     return (&PyTuple_Type)->tp_print(self->data, fp, flags);
 }
 
+static PyObject* pysqlite_iter(pysqlite_Row* self)
+{
+    return PyObject_GetIter(self->data);
+}
 
-PyMappingMethods row_as_mapping = {
-    /* mp_length        */ (lenfunc)row_length,
-    /* mp_subscript     */ (binaryfunc)row_subscript,
+PyMappingMethods pysqlite_row_as_mapping = {
+    /* mp_length        */ (lenfunc)pysqlite_row_length,
+    /* mp_subscript     */ (binaryfunc)pysqlite_row_subscript,
     /* mp_ass_subscript */ (objobjargproc)0,
 };
 
+static PyMethodDef pysqlite_row_methods[] = {
+    {"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
+        PyDoc_STR("Returns the keys of the row.")},
+    {NULL, NULL}
+};
+
 
-PyTypeObject RowType = {
+PyTypeObject pysqlite_RowType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".Row",                             /* tp_name */
-        sizeof(Row),                                    /* tp_basicsize */
+        sizeof(pysqlite_Row),                           /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)row_dealloc,                        /* tp_dealloc */
-        (printfunc)row_print,                           /* tp_print */
+        (destructor)pysqlite_row_dealloc,               /* tp_dealloc */
+        (printfunc)pysqlite_row_print,                  /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
         0,                                              /* tp_compare */
@@ -174,13 +205,13 @@ PyTypeObject RowType = {
         0,                                              /* tp_as_buffer */
         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,         /* tp_flags */
         0,                                              /* tp_doc */
-        0,                                              /* tp_traverse */
+        (traverseproc)0,                                /* tp_traverse */
         0,                                              /* tp_clear */
         0,                                              /* tp_richcompare */
         0,                                              /* tp_weaklistoffset */
-        0,                                              /* tp_iter */
+        (getiterfunc)pysqlite_iter,                     /* tp_iter */
         0,                                              /* tp_iternext */
-        0,                                              /* tp_methods */
+        pysqlite_row_methods,                           /* tp_methods */
         0,                                              /* tp_members */
         0,                                              /* tp_getset */
         0,                                              /* tp_base */
@@ -188,15 +219,15 @@ PyTypeObject RowType = {
         0,                                              /* tp_descr_get */
         0,                                              /* tp_descr_set */
         0,                                              /* tp_dictoffset */
-        (initproc)row_init,                             /* tp_init */
+        (initproc)pysqlite_row_init,                    /* tp_init */
         0,                                              /* tp_alloc */
         0,                                              /* tp_new */
         0                                               /* tp_free */
 };
 
-extern int row_setup_types(void)
+extern int pysqlite_row_setup_types(void)
 {
-    RowType.tp_new = PyType_GenericNew;
-    RowType.tp_as_mapping = &row_as_mapping;
-    return PyType_Ready(&RowType);
+    pysqlite_RowType.tp_new = PyType_GenericNew;
+    pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping;
+    return PyType_Ready(&pysqlite_RowType);
 }
index c6e083c..b92225b 100644 (file)
--- a/src/row.h
+++ b/src/row.h
@@ -30,10 +30,10 @@ typedef struct _Row
     PyObject_HEAD
     PyObject* data;
     PyObject* description;
-} Row;
+} pysqlite_Row;
 
-extern PyTypeObject RowType;
+extern PyTypeObject pysqlite_RowType;
 
-int row_setup_types(void);
+int pysqlite_row_setup_types(void);
 
 #endif
index 55923e7..86d2178 100644 (file)
@@ -29,7 +29,7 @@
 #include "sqlitecompat.h"
 
 /* prototypes */
-int check_remaining_sql(const char* tail);
+static int pysqlite_check_remaining_sql(const char* tail);
 
 typedef enum {
     LINECOMMENT_1,
@@ -40,7 +40,7 @@ typedef enum {
     NORMAL
 } parse_remaining_sql_state;
 
-int statement_create(Statement* self, Connection* connection, PyObject* sql)
+int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql)
 {
     const char* tail;
     int rc;
@@ -77,7 +77,7 @@ int statement_create(Statement* self, Connection* connection, PyObject* sql)
 
     self->db = connection->db;
 
-    if (rc == SQLITE_OK && check_remaining_sql(tail)) {
+    if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
         (void)sqlite3_finalize(self->st);
         self->st = NULL;
         rc = PYSQLITE_TOO_MUCH_SQL;
@@ -86,7 +86,7 @@ int statement_create(Statement* self, Connection* connection, PyObject* sql)
     return rc;
 }
 
-int statement_bind_parameter(Statement* self, int pos, PyObject* parameter)
+int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
 {
     int rc = SQLITE_OK;
     long longval;
@@ -133,7 +133,7 @@ int statement_bind_parameter(Statement* self, int pos, PyObject* parameter)
     return rc;
 }
 
-void statement_bind_parameters(Statement* self, PyObject* parameters)
+void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
 {
     PyObject* current_param;
     PyObject* adapted;
@@ -154,19 +154,19 @@ void statement_bind_parameters(Statement* self, PyObject* parameters)
             binding_name = sqlite3_bind_parameter_name(self->st, i);
             Py_END_ALLOW_THREADS
             if (!binding_name) {
-                PyErr_Format(ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i);
+                PyErr_Format(pysqlite_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i);
                 return;
             }
 
             binding_name++; /* skip first char (the colon) */
             current_param = PyDict_GetItemString(parameters, binding_name);
             if (!current_param) {
-                PyErr_Format(ProgrammingError, "You did not supply a value for binding %d.", i);
+                PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
                 return;
             }
 
             Py_INCREF(current_param);
-            adapted = microprotocols_adapt(current_param, (PyObject*)&SQLitePrepareProtocolType, NULL);
+            adapted = microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
             if (adapted) {
                 Py_DECREF(current_param);
             } else {
@@ -174,11 +174,11 @@ void statement_bind_parameters(Statement* self, PyObject* parameters)
                 adapted = current_param;
             }
 
-            rc = statement_bind_parameter(self, i, adapted);
+            rc = pysqlite_statement_bind_parameter(self, i, adapted);
             Py_DECREF(adapted);
 
             if (rc != SQLITE_OK) {
-                PyErr_Format(InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
+                PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
                 return;
            }
         }
@@ -186,7 +186,7 @@ void statement_bind_parameters(Statement* self, PyObject* parameters)
         /* parameters passed as sequence */
         num_params = PySequence_Length(parameters);
         if (num_params != num_params_needed) {
-            PyErr_Format(ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.",
+            PyErr_Format(pysqlite_ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.",
                          num_params_needed, num_params);
             return;
         }
@@ -195,7 +195,7 @@ void statement_bind_parameters(Statement* self, PyObject* parameters)
             if (!current_param) {
                 return;
             }
-            adapted = microprotocols_adapt(current_param, (PyObject*)&SQLitePrepareProtocolType, NULL);
+            adapted = microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
 
             if (adapted) {
                 Py_DECREF(current_param);
@@ -204,18 +204,18 @@ void statement_bind_parameters(Statement* self, PyObject* parameters)
                 adapted = current_param;
             }
 
-            rc = statement_bind_parameter(self, i + 1, adapted);
+            rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
             Py_DECREF(adapted);
 
             if (rc != SQLITE_OK) {
-                PyErr_Format(InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
+                PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
                 return;
             }
         }
     }
 }
 
-int statement_recompile(Statement* self, PyObject* params)
+int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
 {
     const char* tail;
     int rc;
@@ -250,7 +250,7 @@ int statement_recompile(Statement* self, PyObject* params)
     return rc;
 }
 
-int statement_finalize(Statement* self)
+int pysqlite_statement_finalize(pysqlite_Statement* self)
 {
     int rc;
 
@@ -267,7 +267,7 @@ int statement_finalize(Statement* self)
     return rc;
 }
 
-int statement_reset(Statement* self)
+int pysqlite_statement_reset(pysqlite_Statement* self)
 {
     int rc;
 
@@ -286,12 +286,12 @@ int statement_reset(Statement* self)
     return rc;
 }
 
-void statement_mark_dirty(Statement* self)
+void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
 {
     self->in_use = 1;
 }
 
-void statement_dealloc(Statement* self)
+void pysqlite_statement_dealloc(pysqlite_Statement* self)
 {
     int rc;
 
@@ -320,7 +320,7 @@ void statement_dealloc(Statement* self)
  *
  * Returns 1 if there is more left than should be. 0 if ok.
  */
-int check_remaining_sql(const char* tail)
+static int pysqlite_check_remaining_sql(const char* tail)
 {
     const char* pos = tail;
 
@@ -382,13 +382,13 @@ int check_remaining_sql(const char* tail)
     return 0;
 }
 
-PyTypeObject StatementType = {
+PyTypeObject pysqlite_StatementType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".Statement",                       /* tp_name */
-        sizeof(Statement),                              /* tp_basicsize */
+        sizeof(pysqlite_Statement),                     /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)statement_dealloc,                  /* tp_dealloc */
+        (destructor)pysqlite_statement_dealloc,         /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -408,7 +408,7 @@ PyTypeObject StatementType = {
         0,                                              /* tp_traverse */
         0,                                              /* tp_clear */
         0,                                              /* tp_richcompare */
-        offsetof(Statement, in_weakreflist),            /* tp_weaklistoffset */
+        offsetof(pysqlite_Statement, in_weakreflist),   /* tp_weaklistoffset */
         0,                                              /* tp_iter */
         0,                                              /* tp_iternext */
         0,                                              /* tp_methods */
@@ -425,8 +425,8 @@ PyTypeObject StatementType = {
         0                                               /* tp_free */
 };
 
-extern int statement_setup_types(void)
+extern int pysqlite_statement_setup_types(void)
 {
-    StatementType.tp_new = PyType_GenericNew;
-    return PyType_Ready(&StatementType);
+    pysqlite_StatementType.tp_new = PyType_GenericNew;
+    return PyType_Ready(&pysqlite_StatementType);
 }
index 57ee36f..10b8823 100644 (file)
@@ -39,21 +39,21 @@ typedef struct
     PyObject* sql;
     int in_use;
     PyObject* in_weakreflist; /* List of weak references */
-} Statement;
+} pysqlite_Statement;
 
-extern PyTypeObject StatementType;
+extern PyTypeObject pysqlite_StatementType;
 
-int statement_create(Statement* self, Connection* connection, PyObject* sql);
-void statement_dealloc(Statement* self);
+int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql);
+void pysqlite_statement_dealloc(pysqlite_Statement* self);
 
-int statement_bind_parameter(Statement* self, int pos, PyObject* parameter);
-void statement_bind_parameters(Statement* self, PyObject* parameters);
+int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter);
+void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters);
 
-int statement_recompile(Statement* self, PyObject* parameters);
-int statement_finalize(Statement* self);
-int statement_reset(Statement* self);
-void statement_mark_dirty(Statement* self);
+int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* parameters);
+int pysqlite_statement_finalize(pysqlite_Statement* self);
+int pysqlite_statement_reset(pysqlite_Statement* self);
+void pysqlite_statement_mark_dirty(pysqlite_Statement* self);
 
-int statement_setup_types(void);
+int pysqlite_statement_setup_types(void);
 
 #endif
index 33748a6..2cb45ab 100644 (file)
@@ -24,8 +24,7 @@
 #include "module.h"
 #include "connection.h"
 
-int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connection
-)
+int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, pysqlite_Connection* connection)
 {
     int rc;
 
@@ -40,7 +39,7 @@ int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connectio
  * Checks the SQLite error code and sets the appropriate DB-API exception.
  * Returns the error code (0 means no error occured).
  */
-int _seterror(sqlite3* db)
+int _pysqlite_seterror(sqlite3* db)
 {
     int errorcode;
 
@@ -53,7 +52,7 @@ int _seterror(sqlite3* db)
             break;
         case SQLITE_INTERNAL:
         case SQLITE_NOTFOUND:
-            PyErr_SetString(InternalError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_InternalError, sqlite3_errmsg(db));
             break;
         case SQLITE_NOMEM:
             (void)PyErr_NoMemory();
@@ -71,23 +70,23 @@ int _seterror(sqlite3* db)
         case SQLITE_PROTOCOL:
         case SQLITE_EMPTY:
         case SQLITE_SCHEMA:
-            PyErr_SetString(OperationalError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_OperationalError, sqlite3_errmsg(db));
             break;
         case SQLITE_CORRUPT:
-            PyErr_SetString(DatabaseError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_DatabaseError, sqlite3_errmsg(db));
             break;
         case SQLITE_TOOBIG:
-            PyErr_SetString(DataError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_DataError, sqlite3_errmsg(db));
             break;
         case SQLITE_CONSTRAINT:
         case SQLITE_MISMATCH:
-            PyErr_SetString(IntegrityError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_IntegrityError, sqlite3_errmsg(db));
             break;
         case SQLITE_MISUSE:
-            PyErr_SetString(ProgrammingError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_ProgrammingError, sqlite3_errmsg(db));
             break;
         default:
-            PyErr_SetString(DatabaseError, sqlite3_errmsg(db));
+            PyErr_SetString(pysqlite_DatabaseError, sqlite3_errmsg(db));
             break;
     }
 
index e99a4dd..b00fe81 100644 (file)
 #include "sqlite3.h"
 #include "connection.h"
 
-int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connection);
+int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, pysqlite_Connection* connection);
 
 /**
  * Checks the SQLite error code and sets the appropriate DB-API exception.
  * Returns the error code (0 means no error occured).
  */
-int _seterror(sqlite3* db);
+int _pysqlite_seterror(sqlite3* db);
 #endif