mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Isolation level changes.
This commit is contained in:
parent
8920c2662b
commit
e1688431e0
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2005-10-08 Federico Di Gregorio <fog@initd.org>
|
||||||
|
|
||||||
|
* lib/psycopg1.py: explicitly set isolation level to 2 on .connect()
|
||||||
|
to mimic psycopg 1 behaviour.
|
||||||
|
|
||||||
|
* psycopg/connection_int.c: now set isolation level from
|
||||||
|
default_transaction_isolation backend environment value.
|
||||||
|
|
||||||
|
* psycopg/pqpath.c: removed serialization level 3: now everybody
|
||||||
|
(except me) has to use the mnemonics defined in psycopg2.extensions.
|
||||||
|
|
||||||
|
* lib/extensions.py: Added mnemonics for serialization levels.
|
||||||
|
|
||||||
2005-10-02 Federico Di Gregorio <fog@debian.org>
|
2005-10-02 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
* psycopg/cursor_type.c (psyco_curs_callproc): applied callproc
|
* psycopg/cursor_type.c (psyco_curs_callproc): applied callproc
|
||||||
|
|
|
@ -41,6 +41,15 @@ from _psycopg import adapt, adapters, encodings, connection, cursor
|
||||||
from _psycopg import string_types, binary_types, new_type, register_type
|
from _psycopg import string_types, binary_types, new_type, register_type
|
||||||
from _psycopg import ISQLQuote
|
from _psycopg import ISQLQuote
|
||||||
|
|
||||||
|
"""Isolation level values."""
|
||||||
|
ISOLATION_LEVEL_AUTOCOMMIT = 0
|
||||||
|
ISOLATION_LEVEL_READ_COMMITED = 1
|
||||||
|
ISOLATION_LEVEL_SERIALIZABLE = 2
|
||||||
|
|
||||||
|
# Postgresql maps the the other standard values to already defined levels
|
||||||
|
ISOLATION_LEVEL_REPEATABLE_READ = ISOLATION_LEVEL_SERIALIZABLE
|
||||||
|
ISOLATION_LEVEL_READ UNCOMMITTED = ISOLATION_LEVEL_READ_COMMITED
|
||||||
|
|
||||||
|
|
||||||
def register_adapter(typ, callable):
|
def register_adapter(typ, callable):
|
||||||
"""Register 'callable' as an ISQLQuote adapter for type 'typ'."""
|
"""Register 'callable' as an ISQLQuote adapter for type 'typ'."""
|
||||||
|
|
|
@ -31,8 +31,9 @@ del connect
|
||||||
def connect(*args, **kwargs):
|
def connect(*args, **kwargs):
|
||||||
"""connect(dsn, ...) -> new psycopg 1.1.x compatible connection object"""
|
"""connect(dsn, ...) -> new psycopg 1.1.x compatible connection object"""
|
||||||
kwargs['connection_factory'] = connection
|
kwargs['connection_factory'] = connection
|
||||||
return _2psycopg.connect(*args, **kwargs)
|
conn = _2psycopg.connect(*args, **kwargs)
|
||||||
|
conn.set_isolation_level(2)
|
||||||
|
return conn
|
||||||
|
|
||||||
class connection(_2connection):
|
class connection(_2connection):
|
||||||
"""psycopg 1.1.x connection."""
|
"""psycopg 1.1.x connection."""
|
||||||
|
|
|
@ -53,11 +53,18 @@ conn_connect(connectionObject *self)
|
||||||
{
|
{
|
||||||
PGconn *pgconn;
|
PGconn *pgconn;
|
||||||
PGresult *pgres;
|
PGresult *pgres;
|
||||||
|
char *data;
|
||||||
|
|
||||||
/* we need the initial date style to be ISO, for typecasters; if the user
|
/* we need the initial date style to be ISO, for typecasters; if the user
|
||||||
later change it, she must know what she's doing... */
|
later change it, she must know what she's doing... */
|
||||||
const char *datestyle = "SET DATESTYLE TO 'ISO'";
|
const char *datestyle = "SET DATESTYLE TO 'ISO'";
|
||||||
const char *encoding = "SHOW client_encoding";
|
const char *encoding = "SHOW client_encoding";
|
||||||
|
const char *isolevel = "SHOW default_transaction_isolation";
|
||||||
|
|
||||||
|
const char *lvl1a = "read uncommitted";
|
||||||
|
const char *lvl1b = "read committed";
|
||||||
|
const char *lvl2a = "repeatable read";
|
||||||
|
const char *lvl2b = "serializable";
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
pgconn = PQconnectdb(self->dsn);
|
pgconn = PQconnectdb(self->dsn);
|
||||||
|
@ -86,7 +93,6 @@ conn_connect(connectionObject *self)
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
if (pgres == NULL || PQresultStatus(pgres) != PGRES_COMMAND_OK ) {
|
if (pgres == NULL || PQresultStatus(pgres) != PGRES_COMMAND_OK ) {
|
||||||
Dprintf("conn_connect: setting datestyle to iso FAILED");
|
|
||||||
PyErr_SetString(OperationalError, "can't set datestyle to ISO");
|
PyErr_SetString(OperationalError, "can't set datestyle to ISO");
|
||||||
PQfinish(pgconn);
|
PQfinish(pgconn);
|
||||||
IFCLEARPGRES(pgres);
|
IFCLEARPGRES(pgres);
|
||||||
|
@ -99,7 +105,6 @@ conn_connect(connectionObject *self)
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
if (pgres == NULL || PQresultStatus(pgres) != PGRES_TUPLES_OK) {
|
if (pgres == NULL || PQresultStatus(pgres) != PGRES_TUPLES_OK) {
|
||||||
Dprintf("conn_connect: fetching current client_encoding FAILED");
|
|
||||||
PyErr_SetString(OperationalError, "can't fetch client_encoding");
|
PyErr_SetString(OperationalError, "can't fetch client_encoding");
|
||||||
PQfinish(pgconn);
|
PQfinish(pgconn);
|
||||||
IFCLEARPGRES(pgres);
|
IFCLEARPGRES(pgres);
|
||||||
|
@ -107,6 +112,26 @@ conn_connect(connectionObject *self)
|
||||||
}
|
}
|
||||||
self->encoding = strdup(PQgetvalue(pgres, 0, 0));
|
self->encoding = strdup(PQgetvalue(pgres, 0, 0));
|
||||||
CLEARPGRES(pgres);
|
CLEARPGRES(pgres);
|
||||||
|
|
||||||
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
|
pgres = PQexec(pgconn, isolevel);
|
||||||
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
|
if (pgres == NULL || PQresultStatus(pgres) != PGRES_TUPLES_OK) {
|
||||||
|
PyErr_SetString(OperationalError,
|
||||||
|
"can't fetch default_isolation_level");
|
||||||
|
PQfinish(pgconn);
|
||||||
|
IFCLEARPGRES(pgres);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
data = PQgetvalue(pgres, 0, 0);
|
||||||
|
if ((strncmp(lvl1a, data, strlen(lvl1a)) == 0)
|
||||||
|
|| (strncmp(lvl1b, data, strlen(lvl1b)) == 0))
|
||||||
|
self->isolation_level = 1;
|
||||||
|
else if ((strncmp(lvl2a, data, strlen(lvl2a)) == 0)
|
||||||
|
|| (strncmp(lvl2b, data, strlen(lvl2b)) == 0))
|
||||||
|
self->isolation_level = 2;
|
||||||
|
CLEARPGRES(pgres);
|
||||||
|
|
||||||
if (PQsetnonblocking(pgconn, 1) != 0) {
|
if (PQsetnonblocking(pgconn, 1) != 0) {
|
||||||
Dprintf("conn_connect: PQsetnonblocking() FAILED");
|
Dprintf("conn_connect: PQsetnonblocking() FAILED");
|
||||||
|
|
|
@ -257,7 +257,6 @@ connection_setup(connectionObject *self, char *dsn)
|
||||||
self->dsn = strdup(dsn);
|
self->dsn = strdup(dsn);
|
||||||
self->notice_list = PyList_New(0);
|
self->notice_list = PyList_New(0);
|
||||||
self->closed = 0;
|
self->closed = 0;
|
||||||
self->isolation_level = 1;
|
|
||||||
self->status = CONN_STATUS_READY;
|
self->status = CONN_STATUS_READY;
|
||||||
self->critical = NULL;
|
self->critical = NULL;
|
||||||
self->async_cursor = NULL;
|
self->async_cursor = NULL;
|
||||||
|
|
|
@ -186,7 +186,6 @@ pq_begin(connectionObject *conn)
|
||||||
const char *query[] = {
|
const char *query[] = {
|
||||||
NULL,
|
NULL,
|
||||||
"BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED",
|
"BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED",
|
||||||
"BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE",
|
|
||||||
"BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"};
|
"BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"};
|
||||||
|
|
||||||
int pgstatus, retvalue = -1;
|
int pgstatus, retvalue = -1;
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -55,7 +55,7 @@ from distutils.command.build_ext import build_ext
|
||||||
from distutils.sysconfig import get_python_inc
|
from distutils.sysconfig import get_python_inc
|
||||||
from distutils.ccompiler import get_default_compiler
|
from distutils.ccompiler import get_default_compiler
|
||||||
|
|
||||||
PSYCOPG_VERSION = '2.0b4'
|
PSYCOPG_VERSION = '2.0rc1'
|
||||||
version_flags = []
|
version_flags = []
|
||||||
|
|
||||||
# to work around older distutil limitations
|
# to work around older distutil limitations
|
||||||
|
|
Loading…
Reference in New Issue
Block a user