psycopg2/doc/extensions.rst

167 lines
4.7 KiB
ReStructuredText
Raw Normal View History

2010-02-10 00:31:40 +03:00
:mod:`psycopg2.extensions` -- Extensions to the DB API
======================================================
2005-10-19 16:54:51 +04:00
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
2005-10-19 16:54:51 +04:00
.. module:: psycopg2.extensions
2005-10-19 16:54:51 +04:00
The module contains a few objects and function extending the minimum set of
2010-02-10 00:31:40 +03:00
functionalities defined by the |DBAPI|.
2005-11-19 14:23:18 +03:00
2005-10-19 16:54:51 +04:00
.. class:: connection
2005-10-19 16:54:51 +04:00
Is the class usually returned by the :func:`psycopg2.connect()` function.
It is exposed by the :mod:`extensions` module in order to allow
subclassing to extend its behaviour: the subclass should be passed to the
:func:`connect()` function using the :obj:`connection_factory` parameter.
See also :ref:`subclassing-connection`.
2006-01-10 19:13:37 +03:00
For a complete description of the class, see :class:`connection`.
2006-01-12 20:41:00 +03:00
.. class:: cursor
2006-01-12 20:41:00 +03:00
It is the class usually returnded by the :meth:`connection.cursor()`
method. It is exposed by the :mod:`extensions` module in order to allow
subclassing to extend its behaviour: the subclass should be passed to the
``cursor()`` method using the :obj:`cursor_factory` parameter. See
also :ref:`subclassing-cursor`.
2006-01-12 20:41:00 +03:00
For a complete description of the class, see :class:`cursor`.
2006-01-12 20:41:00 +03:00
.. todo:: row factories
2006-01-12 20:41:00 +03:00
.. class:: lobject
2005-10-19 16:54:51 +04:00
.. todo:: class lobject
2005-10-19 16:54:51 +04:00
.. todo:: finish module extensions
2005-10-19 16:54:51 +04:00
2010-02-09 18:32:24 +03:00
.. index::
pair: Isolation level; Constants
.. _isolation-level-constants:
2005-11-19 14:23:18 +03:00
Isolation level constants
-------------------------
2005-11-19 14:23:18 +03:00
Psycopg2 connection objects hold informations about the PostgreSQL
`transaction isolation level`_. The current transaction level can be read
from the :attr:`connection.isolation_level` attribute. The default isolation
level is ``READ COMMITTED``. A different isolation level con be set through
the :meth:`connection.set_isolation_level()` method. The level can be set to
one of the following constants:
2005-11-19 14:23:18 +03:00
.. data:: ISOLATION_LEVEL_AUTOCOMMIT
2005-11-19 14:23:18 +03:00
No transaction is started when command are issued and no ``commit()`` or
``rollback()`` is required. Some PostgreSQL command such as ``CREATE
DATABASE`` can't run into a transaction: to run such command use::
>>> conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
.. data:: ISOLATION_LEVEL_READ_UNCOMMITTED
2005-11-19 14:23:18 +03:00
This isolation level is defined in the SQL standard but not available in
the MVCC model of PostgreSQL: it is replaced by the stricter ``READ
COMMITTED``.
2005-11-19 14:23:18 +03:00
.. data:: ISOLATION_LEVEL_READ_COMMITTED
This is the default value. A new transaction is started at the first
:meth:`cursor.execute()` command on a cursor and at each new ``execute()``
after a :meth:`connection.commit()` or a :meth:`connection.rollback()`.
The transaction runs in the PostgreSQL ``READ COMMITTED`` isolation level.
.. data:: ISOLATION_LEVEL_REPEATABLE_READ
2005-11-19 14:23:18 +03:00
This isolation level is defined in the SQL standard but not available in
the MVCC model of PostgreSQL: it is replaced by the stricter
``SERIALIZABLE``.
.. data:: ISOLATION_LEVEL_SERIALIZABLE
2005-11-19 14:23:18 +03:00
Transactions are run at a ``SERIALIZABLE`` isolation level. This is the
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
.. _transaction-status-constants:
2005-11-19 14:23:18 +03:00
Transaction status constants
----------------------------
2005-11-19 14:23:18 +03:00
These values represent the possible status of a transaction: the current value
can be read using the :meth:`connection.get_transaction_status()` method.
2005-11-19 14:23:18 +03:00
.. data:: TRANSACTION_STATUS_IDLE
2005-11-19 14:23:18 +03:00
The session is idle and there is no current transaction.
2006-01-10 19:13:37 +03:00
.. data:: TRANSACTION_STATUS_ACTIVE
2005-11-19 14:23:18 +03:00
A command is currently in progress.
2005-10-19 16:54:51 +04:00
.. data:: TRANSACTION_STATUS_INTRANS
2005-10-19 16:54:51 +04:00
The session is idle in a valid transaction block.
.. data:: TRANSACTION_STATUS_INERROR
2005-11-19 14:23:18 +03:00
The session is idle in a failed transaction block.
2005-11-19 14:23:18 +03:00
.. data:: TRANSACTION_STATUS_UNKNOWN
2005-11-19 14:23:18 +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
.. _connection-status-constants:
2005-11-19 14:23:18 +03:00
Connection status constants
---------------------------
2005-11-19 14:23:18 +03:00
These values represent the possible status of a connection: the current value
can be read from the :data:`connection.status` attribute.
2005-10-19 16:54:51 +04:00
.. todo:: check if these values are really useful or not.
2005-10-19 16:54:51 +04:00
.. data:: STATUS_SETUP
2005-10-19 16:54:51 +04:00
Defined but not used.
2005-10-19 16:54:51 +04:00
.. data:: STATUS_READY
2005-10-19 16:54:51 +04:00
Connection established.
2005-10-19 16:54:51 +04:00
.. data:: STATUS_BEGIN
2005-10-19 16:54:51 +04:00
Connection established. A transaction is in progress.
.. data:: STATUS_IN_TRANSACTION
An alias for :data:`STATUS_BEGIN`
.. data:: STATUS_SYNC
Defined but not used.
.. data:: STATUS_ASYNC
2005-10-19 16:54:51 +04:00
Defined but not used.
2005-10-19 16:54:51 +04:00