Skip to content

Commit

Permalink
Remember prepared statements
Browse files Browse the repository at this point in the history
Never close prepared statements, and remember them and reuse them.
Essentially this is removing the use_cache option, and always using
it.
  • Loading branch information
tlocke committed Jun 7, 2014
1 parent 041b9ab commit 18a0965
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 372 deletions.
31 changes: 11 additions & 20 deletions doc/quickstart.rst
@@ -1,15 +1,24 @@
Quick Start
===========

Key Points
----------

- Runs on Python version 2.5, 2.6, 2.7, 3.2, 3.3 and 3.4
- Runs on CPython, Jython and PyPy
- Although it's possible for threads to share cursors and connections, for
performance reasons it's best to use one thread per connection.
- Internally, all queries use prepared statements. pg8000 remembers that a
prepared statement has been created, and uses it on subsequent queries.

Installation
------------
pg8000 is available for Python 2.5, 2.6, 2.7, 3.2, 3.3 and 3.4 (and has been
tested on CPython, Jython and PyPy).

To install pg8000 using `pip <https://pypi.python.org/pypi/pip>`_ type:

``pip install pg8000``


Interactive Example
-------------------

Expand Down Expand Up @@ -74,21 +83,3 @@ turned on by using the autocommit property of the connection.
>>> conn.autocommit = False
>>> cursor.close()
>>> conn.close()
Try the use_cache feature:
.. code-block:: python
>>> conn = pg8000.connect(
... user="postgres", password="C.P.Snow", use_cache=True)
>>> cur = conn.cursor()
>>> cur.execute("select cast(%s as varchar) as f1", ('Troon',))
>>> res = cur.fetchall()
Now subsequent queries with the same parameter types and SQL will use the
cached prepared statement.
.. code-block:: python
>>> cur.execute("select cast(%s as varchar) as f1", ('Trunho',))
>>> res = cur.fetchall()
6 changes: 2 additions & 4 deletions pg8000/__init__.py
Expand Up @@ -142,12 +142,10 @@ def __neq__(self, other):
# @return An instance of {@link #ConnectionWrapper ConnectionWrapper}.
def connect(
user, host='localhost', unix_sock=None, port=5432, database=None,
password=None, socket_timeout=60, ssl=False, use_cache=False,
**kwargs):
password=None, socket_timeout=60, ssl=False, **kwargs):

return pg8000.core.Connection(
user, host, unix_sock, port, database, password, socket_timeout, ssl,
use_cache)
user, host, unix_sock, port, database, password, socket_timeout, ssl)

##
# The DBAPI level supported. Currently 2.0. This property is part of the
Expand Down

0 comments on commit 18a0965

Please sign in to comment.