2010-02-26 03:17:52 +03:00
|
|
|
`psycopg2.extensions` -- Extensions to the DB API
|
2010-02-10 00:31:40 +03:00
|
|
|
======================================================
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. module:: psycopg2.extensions
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-13 19:06:39 +03:00
|
|
|
.. testsetup:: *
|
|
|
|
|
2010-02-15 01:03:15 +03:00
|
|
|
from psycopg2.extensions import AsIs, Binary, QuotedString, ISOLATION_LEVEL_AUTOCOMMIT
|
2010-02-13 19:06:39 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
The module contains a few objects and function extending the minimum set of
|
2010-02-11 06:15:14 +03:00
|
|
|
functionalities defined by the |DBAPI|_.
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. class:: connection
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Is the class usually returned by the `~psycopg2.connect()` function.
|
|
|
|
It is exposed by the `extensions` module in order to allow
|
2010-02-09 07:58:28 +03:00
|
|
|
subclassing to extend its behaviour: the subclass should be passed to the
|
2010-02-26 03:17:52 +03:00
|
|
|
`!connect()` function using the `connection_factory` parameter.
|
2010-02-09 07:58:28 +03:00
|
|
|
See also :ref:`subclassing-connection`.
|
2006-01-10 19:13:37 +03:00
|
|
|
|
2010-04-08 16:22:55 +04:00
|
|
|
Subclasses should have constructor signature :samp:`({dsn}, {async}=0)`.
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
For a complete description of the class, see `connection`.
|
2006-01-12 20:41:00 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. class:: cursor
|
2006-01-12 20:41:00 +03:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
It is the class usually returnded by the `connection.cursor()`
|
|
|
|
method. It is exposed by the `extensions` module in order to allow
|
2010-02-09 07:58:28 +03:00
|
|
|
subclassing to extend its behaviour: the subclass should be passed to the
|
2010-02-26 03:17:52 +03:00
|
|
|
`!cursor()` method using the `cursor_factory` parameter. See
|
2010-02-09 07:58:28 +03:00
|
|
|
also :ref:`subclassing-cursor`.
|
2006-01-12 20:41:00 +03:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
For a complete description of the class, see `cursor`.
|
2006-01-12 20:41:00 +03:00
|
|
|
|
2010-02-14 22:42:15 +03:00
|
|
|
.. class:: lobject(conn [, oid [, mode [, new_oid [, new_file ]]]])
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-14 22:42:15 +03:00
|
|
|
Wrapper for a PostgreSQL large object. See :ref:`large-objects` for an
|
|
|
|
overview.
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
The class can be subclassed: see the `connection.lobject()` to know
|
|
|
|
how to specify a `!lobject` subclass.
|
2010-02-14 22:42:15 +03:00
|
|
|
|
2010-02-13 08:49:34 +03:00
|
|
|
.. versionadded:: 2.0.8
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-14 22:42:15 +03:00
|
|
|
.. attribute:: oid
|
|
|
|
|
|
|
|
Database OID of the object.
|
|
|
|
|
|
|
|
.. attribute:: mode
|
|
|
|
|
|
|
|
The mode the database was open (``r``, ``w``, ``rw`` or ``n``).
|
|
|
|
|
|
|
|
.. method:: read(bytes=-1)
|
|
|
|
|
|
|
|
Read a chunk of data from the current file position. If -1 (default)
|
|
|
|
read all the remaining data.
|
|
|
|
|
|
|
|
.. method:: write(str)
|
|
|
|
|
|
|
|
Write a string to the large object. Return the number of bytes
|
|
|
|
written.
|
|
|
|
|
|
|
|
.. method:: export(file_name)
|
|
|
|
|
|
|
|
Export the large object content to the file system.
|
|
|
|
|
|
|
|
The method uses the efficient |lo_export|_ libpq function.
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
.. |lo_export| replace:: `!lo_export()`
|
2010-02-14 22:42:15 +03:00
|
|
|
.. _lo_export: http://www.postgresql.org/docs/8.4/static/lo-interfaces.html#AEN36330
|
|
|
|
|
|
|
|
.. method:: seek(offset, whence=0)
|
|
|
|
|
|
|
|
Set the lobject current position.
|
|
|
|
|
|
|
|
.. method:: tell()
|
|
|
|
|
|
|
|
Return the lobject current position.
|
|
|
|
|
2010-03-29 02:42:56 +04:00
|
|
|
.. method:: truncate(len=0)
|
|
|
|
|
2010-04-08 16:22:55 +04:00
|
|
|
.. versionadded:: 2.2.0
|
2010-03-29 02:42:56 +04:00
|
|
|
|
|
|
|
Truncate the lobject to the given size.
|
|
|
|
|
2010-04-08 16:22:55 +04:00
|
|
|
The method will only be available if Psycopg has been built against libpq
|
|
|
|
from PostgreSQL 8.3 or later and can only be used with PostgreSQL servers
|
|
|
|
running these versions. It uses the |lo_truncate|_ libpq function.
|
2010-03-29 02:42:56 +04:00
|
|
|
|
|
|
|
.. |lo_truncate| replace:: `!lo_truncate()`
|
|
|
|
.. _lo_truncate: http://www.postgresql.org/docs/8.4/static/lo-interfaces.html#AEN36420
|
|
|
|
|
2010-02-14 22:42:15 +03:00
|
|
|
.. method:: close()
|
|
|
|
|
|
|
|
Close the object.
|
|
|
|
|
|
|
|
.. attribute:: closed
|
|
|
|
|
|
|
|
Boolean attribute specifying if the object is closed.
|
|
|
|
|
|
|
|
.. method:: unlink()
|
|
|
|
|
|
|
|
Close the object and remove it from the database.
|
|
|
|
|
|
|
|
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
.. _sql-adaptation-objects:
|
|
|
|
|
|
|
|
SQL adaptation protocol objects
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
Psycopg provides a flexible system to adapt Python objects to the SQL syntax
|
|
|
|
(inspired to the :pep:`246`), allowing serialization in PostgreSQL. See
|
|
|
|
:ref:`adapting-new-types` for a detailed description. The following objects
|
|
|
|
deal with Python objects adaptation:
|
|
|
|
|
|
|
|
.. function:: adapt(obj)
|
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
Return the SQL representation of *obj* as a string. Raise a
|
2010-02-26 03:17:52 +03:00
|
|
|
`~psycopg2.ProgrammingError` if how to adapt the object is unknown.
|
2010-02-11 06:15:14 +03:00
|
|
|
In order to allow new objects to be adapted, register a new adapter for it
|
2010-02-26 03:17:52 +03:00
|
|
|
using the `register_adapter()` function.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
The function is the entry point of the adaptation mechanism: it can be
|
|
|
|
used to write adapters for complex objects by recursively calling
|
2010-02-26 03:17:52 +03:00
|
|
|
`!adapt()` on its components.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
.. function:: register_adapter(class, adapter)
|
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
Register a new adapter for the objects of class *class*.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
*adapter* should be a function taking a single argument (the object
|
2010-02-26 03:17:52 +03:00
|
|
|
to adapt) and returning an object conforming the `ISQLQuote`
|
|
|
|
protocol (e.g. exposing a `!getquoted()` method). The `AsIs` is
|
2010-02-10 07:03:30 +03:00
|
|
|
often useful for this task.
|
|
|
|
|
|
|
|
Once an object is registered, it can be safely used in SQL queries and by
|
2010-02-26 03:17:52 +03:00
|
|
|
the `adapt()` function.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. class:: ISQLQuote(wrapped_object)
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
Represents the SQL adaptation protocol. Objects conforming this protocol
|
2010-02-26 03:17:52 +03:00
|
|
|
should implement a `!getquoted()` method.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Adapters may subclass `!ISQLQuote`, but is not necessary: it is
|
|
|
|
enough to expose a `!getquoted()` method to be conforming.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. attribute:: _wrapped
|
|
|
|
|
|
|
|
The wrapped object passes to the constructor
|
|
|
|
|
|
|
|
.. method:: getquoted()
|
|
|
|
|
|
|
|
Subclasses or other conforming objects should return a valid SQL
|
2010-02-26 03:17:52 +03:00
|
|
|
string representing the wrapped object. The `!ISQLQuote`
|
2010-02-11 06:15:14 +03:00
|
|
|
implementation does nothing.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
.. class:: AsIs
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Adapter conform to the `ISQLQuote` protocol useful for objects
|
2010-02-10 07:03:30 +03:00
|
|
|
whose string representation is already valid as SQL representation.
|
|
|
|
|
|
|
|
.. method:: getquoted()
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Return the `str()` conversion of the wrapped object.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
>>> AsIs(42).getquoted()
|
|
|
|
'42'
|
|
|
|
|
|
|
|
.. class:: QuotedString
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Adapter conform to the `ISQLQuote` protocol for string-like
|
2010-02-10 07:03:30 +03:00
|
|
|
objects.
|
|
|
|
|
|
|
|
.. method:: getquoted()
|
|
|
|
|
|
|
|
Return the string enclosed in single quotes. Any single quote
|
|
|
|
appearing in the the string is escaped by doubling it according to SQL
|
|
|
|
string constants syntax. Backslashes are escaped too.
|
|
|
|
|
|
|
|
>>> QuotedString(r"O'Reilly").getquoted()
|
|
|
|
"'O''Reilly'"
|
|
|
|
|
|
|
|
.. class:: Binary
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Adapter conform to the `ISQLQuote` protocol for binary objects.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
.. method:: getquoted()
|
|
|
|
|
|
|
|
Return the string enclosed in single quotes. It performs the same
|
2010-02-26 03:17:52 +03:00
|
|
|
escaping of the `QuotedString` adapter, plus it knows how to
|
2010-02-10 07:03:30 +03:00
|
|
|
escape non-printable chars.
|
|
|
|
|
|
|
|
>>> Binary("\x00\x08\x0F").getquoted()
|
|
|
|
"'\\\\000\\\\010\\\\017'"
|
|
|
|
|
2010-02-26 03:37:09 +03:00
|
|
|
.. versionchanged:: 2.0.14
|
2010-02-26 03:17:52 +03:00
|
|
|
previously the adapter was not exposed by the `extensions`
|
2010-02-11 06:15:14 +03:00
|
|
|
module. In older version it can be imported from the implementation
|
2010-02-26 03:17:52 +03:00
|
|
|
module `!psycopg2._psycopg`.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. class:: Boolean
|
2010-02-13 00:58:58 +03:00
|
|
|
Float
|
|
|
|
SQL_IN
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-13 00:58:58 +03:00
|
|
|
Specialized adapters for builtin objects.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. class:: DateFromPy
|
2010-02-13 00:58:58 +03:00
|
|
|
TimeFromPy
|
|
|
|
TimestampFromPy
|
|
|
|
IntervalFromPy
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-13 00:58:58 +03:00
|
|
|
Specialized adapters for Python datetime objects.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. class:: DateFromMx
|
2010-02-13 00:58:58 +03:00
|
|
|
TimeFromMx
|
|
|
|
TimestampFromMx
|
|
|
|
IntervalFromMx
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-13 00:58:58 +03:00
|
|
|
Specialized adapters for `mx.DateTime`_ objects.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
.. data:: adapters
|
|
|
|
|
|
|
|
Dictionary of the currently registered object adapters. Use
|
2010-02-26 03:17:52 +03:00
|
|
|
`register_adapter()` to add an adapter for a new type.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Database types casting functions
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
These functions are used to manipulate type casters to convert from PostgreSQL
|
|
|
|
types to Python objects. See :ref:`type-casting-from-sql-to-python` for
|
|
|
|
details.
|
|
|
|
|
|
|
|
.. function:: new_type(oids, name, adapter)
|
|
|
|
|
|
|
|
Create a new type caster to convert from a PostgreSQL type to a Python
|
|
|
|
object. The created object must be registered using
|
2010-02-26 03:17:52 +03:00
|
|
|
`register_type()` to be used.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
:param oids: tuple of OIDs of the PostgreSQL type to convert.
|
|
|
|
:param name: the name of the new type adapter.
|
|
|
|
:param adapter: the adaptation function.
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
The object OID can be read from the `cursor.description` attribute
|
2010-02-11 06:15:14 +03:00
|
|
|
or by querying from the PostgreSQL catalog.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
*adapter* should have signature :samp:`fun({value}, {cur})` where
|
|
|
|
*value* is the string representation returned by PostgreSQL and
|
|
|
|
*cur* is the cursor from which data are read. In case of
|
|
|
|
:sql:`NULL`, *value* will be ``None``. The adapter should return the
|
2010-02-11 06:15:14 +03:00
|
|
|
converted object.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
|
|
|
See :ref:`type-casting-from-sql-to-python` for an usage example.
|
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
|
2010-02-10 07:03:30 +03:00
|
|
|
.. function:: register_type(obj [, scope])
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Register a type caster created using `new_type()`.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
If *scope* is specified, it should be a `connection` or a
|
2010-02-26 03:17:52 +03:00
|
|
|
`cursor`: the type caster will be effective only limited to the
|
2010-02-10 07:03:30 +03:00
|
|
|
specified object. Otherwise it will be globally registered.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: string_types
|
|
|
|
|
|
|
|
The global register of type casters.
|
|
|
|
|
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. index::
|
|
|
|
single: Encoding; Mapping
|
|
|
|
|
|
|
|
.. data:: encodings
|
|
|
|
|
|
|
|
Mapping from `PostgreSQL encoding`__ names to `Python codec`__ names.
|
2010-02-13 00:58:58 +03:00
|
|
|
Used by Psycopg when adapting or casting unicode strings. See
|
|
|
|
:ref:`unicode-handling`.
|
2010-02-11 06:15:14 +03:00
|
|
|
|
|
|
|
.. __: http://www.postgresql.org/docs/8.4/static/multibyte.html
|
|
|
|
.. __: http://docs.python.org/library/codecs.html#standard-encodings
|
|
|
|
|
2005-10-19 16:54:51 +04:00
|
|
|
|
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
.. index::
|
|
|
|
single: Exceptions; Additional
|
|
|
|
|
|
|
|
Additional exceptions
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
The module exports a few exceptions in addition to the :ref:`standard ones
|
|
|
|
<dbapi-exceptions>` defined by the |DBAPI|_.
|
|
|
|
|
|
|
|
.. exception:: QueryCanceledError
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
(subclasses `~psycopg2.OperationalError`)
|
2010-02-13 08:49:34 +03:00
|
|
|
|
|
|
|
Error related to SQL query cancelation. It can be trapped specifically to
|
|
|
|
detect a timeout.
|
|
|
|
|
|
|
|
.. versionadded:: 2.0.7
|
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
|
|
|
|
.. exception:: TransactionRollbackError
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
(subclasses `~psycopg2.OperationalError`)
|
2010-02-13 08:49:34 +03:00
|
|
|
|
|
|
|
Error causing transaction rollback (deadlocks, serialisation failures,
|
|
|
|
etc). It can be trapped specifically to detect a deadlock.
|
|
|
|
|
|
|
|
.. versionadded:: 2.0.7
|
2010-02-11 06:15:14 +03:00
|
|
|
|
2010-02-09 18:32:24 +03:00
|
|
|
|
2010-02-11 08:17:10 +03:00
|
|
|
|
2010-02-09 18:32:24 +03:00
|
|
|
.. index::
|
|
|
|
pair: Isolation level; Constants
|
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. _isolation-level-constants:
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
Isolation level constants
|
|
|
|
-------------------------
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
Psycopg2 `connection` objects hold informations about the PostgreSQL
|
2010-02-09 07:58:28 +03:00
|
|
|
`transaction isolation level`_. The current transaction level can be read
|
2010-02-26 03:17:52 +03:00
|
|
|
from the `~connection.isolation_level` attribute. The default isolation
|
2010-02-11 06:15:14 +03:00
|
|
|
level is :sql:`READ COMMITTED`. A different isolation level con be set
|
2010-02-26 03:17:52 +03:00
|
|
|
through the `~connection.set_isolation_level()` method. The level can be
|
2010-02-11 06:15:14 +03:00
|
|
|
set to one of the following constants:
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: ISOLATION_LEVEL_AUTOCOMMIT
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
No transaction is started when command are issued and no
|
2010-02-26 03:17:52 +03:00
|
|
|
`~connection.commit()` or `~connection.rollback()` is required.
|
2010-02-18 06:51:17 +03:00
|
|
|
Some PostgreSQL command such as :sql:`CREATE DATABASE` or :sql:`VACUUM`
|
|
|
|
can't run into a transaction: to run such command use::
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
>>> conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-18 06:51:17 +03:00
|
|
|
See also :ref:`transactions-control`.
|
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: ISOLATION_LEVEL_READ_UNCOMMITTED
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-03-03 20:43:24 +03:00
|
|
|
The :sql:`READ UNCOMMITTED` isolation level is defined in the SQL standard
|
|
|
|
but not available in the |MVCC| model of PostgreSQL: it is replaced by the
|
|
|
|
stricter :sql:`READ COMMITTED`.
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: ISOLATION_LEVEL_READ_COMMITTED
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
This is the default value. A new transaction is started at the first
|
2010-02-26 03:17:52 +03:00
|
|
|
`~cursor.execute()` command on a cursor and at each new
|
|
|
|
`!execute()` after a `~connection.commit()` or a
|
|
|
|
`~connection.rollback()`. The transaction runs in the PostgreSQL
|
2010-02-11 06:15:14 +03:00
|
|
|
:sql:`READ COMMITTED` isolation level.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: ISOLATION_LEVEL_REPEATABLE_READ
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
The :sql:`REPEATABLE READ` isolation level is defined in the SQL standard
|
|
|
|
but not available in the |MVCC| model of PostgreSQL: it is replaced by the
|
|
|
|
stricter :sql:`SERIALIZABLE`.
|
2010-02-10 07:03:30 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: ISOLATION_LEVEL_SERIALIZABLE
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
Transactions are run at a :sql:`SERIALIZABLE` isolation level. This is the
|
2010-02-09 07:58:28 +03:00
|
|
|
strictest transactions isolation level, equivalent to having the
|
|
|
|
transactions executed serially rather than concurrently. However
|
|
|
|
applications using this level must be prepared to retry reansactions due
|
|
|
|
to serialization failures. See `serializable isolation level`_ in
|
|
|
|
PostgreSQL documentation.
|
2005-11-19 14:23:18 +03:00
|
|
|
|
|
|
|
|
2010-02-09 18:32:24 +03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
pair: Transaction status; Constants
|
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. _transaction-status-constants:
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
Transaction status constants
|
|
|
|
----------------------------
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
These values represent the possible status of a transaction: the current value
|
2010-02-26 03:17:52 +03:00
|
|
|
can be read using the `connection.get_transaction_status()` method.
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: TRANSACTION_STATUS_IDLE
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
The session is idle and there is no current transaction.
|
2006-01-10 19:13:37 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: TRANSACTION_STATUS_ACTIVE
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
A command is currently in progress.
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: TRANSACTION_STATUS_INTRANS
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
The session is idle in a valid transaction block.
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: TRANSACTION_STATUS_INERROR
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
The session is idle in a failed transaction block.
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: TRANSACTION_STATUS_UNKNOWN
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
Reported if the connection with the server is bad.
|
2005-11-19 14:23:18 +03:00
|
|
|
|
|
|
|
|
2010-02-09 18:32:24 +03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
pair: Connection status; Constants
|
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. _connection-status-constants:
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
Connection status constants
|
|
|
|
---------------------------
|
2005-11-19 14:23:18 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
These values represent the possible status of a connection: the current value
|
2010-02-26 03:17:52 +03:00
|
|
|
can be read from the `~connection.status` attribute.
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: STATUS_SETUP
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
Used internally.
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: STATUS_READY
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
Connection established.
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: STATUS_BEGIN
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
Connection established. A transaction is in progress.
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: STATUS_IN_TRANSACTION
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
An alias for `STATUS_BEGIN`
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: STATUS_SYNC
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
Used internally.
|
2005-11-26 10:47:48 +03:00
|
|
|
|
2010-02-09 07:58:28 +03:00
|
|
|
.. data:: STATUS_ASYNC
|
2005-10-19 16:54:51 +04:00
|
|
|
|
2010-02-11 06:15:14 +03:00
|
|
|
Used internally.
|
2005-10-19 16:54:51 +04:00
|
|
|
|
|
|
|
|
2010-02-11 08:17:10 +03:00
|
|
|
|
2010-04-08 16:22:55 +04:00
|
|
|
.. index::
|
|
|
|
pair: Poll status; Constants
|
|
|
|
|
|
|
|
.. _poll-constants:
|
|
|
|
|
|
|
|
Poll constants
|
|
|
|
--------------
|
|
|
|
|
|
|
|
.. versionadded:: 2.2.0
|
|
|
|
|
|
|
|
These values can be returned by `connection.poll()` and `cursor.poll()` during
|
|
|
|
asynchronous communication. See :ref:`async-support`.
|
|
|
|
|
|
|
|
.. data:: POLL_OK
|
|
|
|
|
|
|
|
The data is available (or the file descriptor is ready for writing): there
|
|
|
|
is no need to block anymore.
|
|
|
|
|
|
|
|
.. data:: POLL_READ
|
|
|
|
|
|
|
|
Upon receiving this value, the callback should wait for the connection
|
|
|
|
file descriptor to be ready *for reading*. For example::
|
|
|
|
|
|
|
|
select.select([conn.fileno()], [], [])
|
|
|
|
|
|
|
|
.. data:: POLL_WRITE
|
|
|
|
|
|
|
|
Upon receiving this value, the callback should wait for the connection
|
|
|
|
file descriptor to be ready *for writing*. For example::
|
|
|
|
|
|
|
|
select.select([], [conn.fileno()], [])
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-11 08:17:10 +03:00
|
|
|
Additional database types
|
|
|
|
-------------------------
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
The `!extensions` module includes typecasters for many standard
|
2010-02-11 08:17:10 +03:00
|
|
|
PostgreSQL types. These objects allow the conversion of returned data into
|
|
|
|
Python objects. All the typecasters are automatically registered, except
|
2010-02-26 03:17:52 +03:00
|
|
|
`UNICODE` and `UNICODEARRAY`: you can register them using
|
|
|
|
`register_type()` in order to receive Unicode objects instead of strings
|
2010-02-11 08:17:10 +03:00
|
|
|
from the database. See :ref:`unicode-handling` for details.
|
|
|
|
|
|
|
|
.. data:: BINARYARRAY
|
2010-02-13 00:58:58 +03:00
|
|
|
BOOLEAN
|
|
|
|
BOOLEANARRAY
|
|
|
|
DATE
|
|
|
|
DATEARRAY
|
|
|
|
DATETIMEARRAY
|
|
|
|
DECIMALARRAY
|
|
|
|
FLOAT
|
|
|
|
FLOATARRAY
|
|
|
|
INTEGER
|
|
|
|
INTEGERARRAY
|
|
|
|
INTERVAL
|
|
|
|
INTERVALARRAY
|
|
|
|
LONGINTEGER
|
|
|
|
LONGINTEGERARRAY
|
|
|
|
ROWIDARRAY
|
|
|
|
STRINGARRAY
|
|
|
|
TIME
|
|
|
|
TIMEARRAY
|
|
|
|
UNICODE
|
|
|
|
UNICODEARRAY
|
2010-02-11 08:17:10 +03:00
|
|
|
|