Documentation for set_transaction() and autocommit improved

This commit is contained in:
Daniele Varrazzo 2011-06-03 01:46:56 +01:00
parent 4d3c6865ee
commit 530ba78881
3 changed files with 26 additions and 10 deletions

8
NEWS
View File

@ -1,8 +1,12 @@
What's new in psycopg 2.4.2 What's new in psycopg 2.4.2
--------------------------- ---------------------------
- Allow using the isolation level "repeatable read" which is distinct - Added 'set_transaction()' method and 'autocommit' property to the
from "serializable" in PostgreSQL 9.1. connection. Added support for read-only sessions and, for PostgreSQL
9.1, for the "repeatable read" isolation level and the "deferrable"
transaction property.
- Psycopg doesn't execute queries at connection time to find the
default isolation level.
- Don't build mx.DateTime support if the module can't be imported - Don't build mx.DateTime support if the module can't be imported
(ticket #53). (ticket #53).

View File

@ -327,7 +327,7 @@ The ``connection`` class
pair: Transaction; Autocommit pair: Transaction; Autocommit
pair: Transaction; Isolation level pair: Transaction; Isolation level
.. method:: set_transaction(isolation_level=None, readonly=None, deferrable=None, autocommit=None) .. method:: set_transaction([isolation_level,] [readonly,] [deferrable,] [autocommit])
Set one or more parameters for the next transactions or statements in Set one or more parameters for the next transactions or statements in
the current session. See |SET TRANSACTION|_ for further details. the current session. See |SET TRANSACTION|_ for further details.
@ -336,9 +336,11 @@ The ``connection`` class
.. _SET TRANSACTION: http://www.postgresql.org/docs/9.1/static/sql-set-transaction.html .. _SET TRANSACTION: http://www.postgresql.org/docs/9.1/static/sql-set-transaction.html
:param isolation_level: set the `isolation level`_ for the next :param isolation_level: set the `isolation level`_ for the next
transactions/statements. The value should be one of the transactions/statements. The value can be one of the
:ref:`constants <isolation-level-constants>` defined in the :ref:`constants <isolation-level-constants>` defined in the
`~psycopg2.extensions` module. `~psycopg2.extensions` module or one of the literal values
``read uncommitted``, ``read committed``, ``repeatable read``,
``serializable``.
:param readonly: if `!True`, set the connection to read only; :param readonly: if `!True`, set the connection to read only;
read/write if `!False`. read/write if `!False`.
:param deferrable: if `!True`, set the connection to deferrable; :param deferrable: if `!True`, set the connection to deferrable;
@ -347,12 +349,15 @@ The ``connection`` class
PostgreSQL session setting but an alias for setting the PostgreSQL session setting but an alias for setting the
`autocommit` attribute. `autocommit` attribute.
The parameters *isolation_level*, *readonly* and *deferrable* also
accept the string ``default`` as a value: the effect is to reset the
parameter to the server default.
.. _isolation level: .. _isolation level:
http://www.postgresql.org/docs/9.1/static/transaction-iso.html http://www.postgresql.org/docs/9.1/static/transaction-iso.html
The function must be invoked with no transaction in progress. At every The function must be invoked with no transaction in progress. At every
function invocation, only the parameters whose value is not `!None` are function invocation, only the specified parameters are changed.
changed.
The default for the values are defined by the server configuration: The default for the values are defined by the server configuration:
see values for |default_transaction_isolation|__, see values for |default_transaction_isolation|__,
@ -382,6 +387,10 @@ The ``connection`` class
execution: the methods `commit()` or `rollback()` must be manually execution: the methods `commit()` or `rollback()` must be manually
invoked to terminate the transaction. invoked to terminate the transaction.
The autocommit mode is useful to execute commands requiring to be run
outside a transaction, such as :sql:`CREATE DATABASE` or
:sql:`VACUUM`.
The default is `!False` (manual commit) as per DBAPI specification. The default is `!False` (manual commit) as per DBAPI specification.
.. warning:: .. warning::
@ -402,9 +411,8 @@ The ``connection`` class
.. note:: .. note::
From version 2.4.2, replaced by `set_transaction()` and From version 2.4.2, `set_transaction()` and `autocommit`, offer
`autocommit`, offering finer control on the transaction finer control on the transaction characteristics.
characteristics.
Read or set the `transaction isolation level`_ for the current session. Read or set the `transaction isolation level`_ for the current session.
The level defines the different phenomena that can happen in the The level defines the different phenomena that can happen in the

View File

@ -519,6 +519,10 @@ outside any transaction: in order to be able to run these commands from
Psycopg, the session must be in autocommit mode. Read the documentation for Psycopg, the session must be in autocommit mode. Read the documentation for
`connection.set_isolation_level()` to know how to change the commit mode. `connection.set_isolation_level()` to know how to change the commit mode.
.. note::
From version 2.4.2 you can use the `~connection.autocommit` property to
switch a connection in autocommit mode.
.. index:: .. index::