mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-14 04:56:33 +03:00
Use the connection.info properties instead of the legacy methods
This commit is contained in:
parent
704e6797e7
commit
44bd2927c5
|
@ -820,7 +820,7 @@ Transaction status constants
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
These values represent the possible status of a transaction: the current value
|
These values represent the possible status of a transaction: the current value
|
||||||
can be read using the `connection.get_transaction_status()` method.
|
can be read using the `connection.info.transaction_status` property.
|
||||||
|
|
||||||
.. data:: TRANSACTION_STATUS_IDLE
|
.. data:: TRANSACTION_STATUS_IDLE
|
||||||
|
|
||||||
|
|
|
@ -117,9 +117,10 @@ The module interface respects the standard defined in the |DBAPI|_.
|
||||||
|
|
||||||
Integer constant reporting the version of the ``libpq`` library this
|
Integer constant reporting the version of the ``libpq`` library this
|
||||||
``psycopg2`` module was compiled with (in the same format of
|
``psycopg2`` module was compiled with (in the same format of
|
||||||
`~connection.server_version`). If this value is greater or equal than
|
`~psycopg2.extensions.ConnectionInfo.server_version`). If this value is
|
||||||
``90100`` then you may query the version of the actually loaded library
|
greater or equal than ``90100`` then you may query the version of the
|
||||||
using the `~psycopg2.extensions.libpq_version()` function.
|
actually loaded library using the `~psycopg2.extensions.libpq_version()`
|
||||||
|
function.
|
||||||
|
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
|
|
|
@ -185,7 +185,7 @@ def _get_json_oids(conn_or_curs, name='json'):
|
||||||
conn_status = conn.status
|
conn_status = conn.status
|
||||||
|
|
||||||
# column typarray not available before PG 8.3
|
# column typarray not available before PG 8.3
|
||||||
typarray = conn.server_version >= 80300 and "typarray" or "NULL"
|
typarray = conn.info.server_version >= 80300 and "typarray" or "NULL"
|
||||||
|
|
||||||
# get the oid for the hstore
|
# get the oid for the hstore
|
||||||
curs.execute(
|
curs.execute(
|
||||||
|
|
|
@ -352,9 +352,9 @@ class RangeCaster(object):
|
||||||
from psycopg2.extras import _solve_conn_curs
|
from psycopg2.extras import _solve_conn_curs
|
||||||
conn, curs = _solve_conn_curs(conn_or_curs)
|
conn, curs = _solve_conn_curs(conn_or_curs)
|
||||||
|
|
||||||
if conn.server_version < 90200:
|
if conn.info.server_version < 90200:
|
||||||
raise ProgrammingError("range types not available in version %s"
|
raise ProgrammingError("range types not available in version %s"
|
||||||
% conn.server_version)
|
% conn.info.server_version)
|
||||||
|
|
||||||
# Store the transaction status of the connection to revert it after use
|
# Store the transaction status of the connection to revert it after use
|
||||||
conn_status = conn.status
|
conn_status = conn.status
|
||||||
|
|
|
@ -806,7 +806,7 @@ class HstoreAdapter(object):
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
|
|
||||||
# use an old-style getquoted implementation if required
|
# use an old-style getquoted implementation if required
|
||||||
if conn.server_version < 90000:
|
if conn.info.server_version < 90000:
|
||||||
self.getquoted = self._getquoted_8
|
self.getquoted = self._getquoted_8
|
||||||
|
|
||||||
def _getquoted_8(self):
|
def _getquoted_8(self):
|
||||||
|
@ -911,7 +911,7 @@ class HstoreAdapter(object):
|
||||||
conn_status = conn.status
|
conn_status = conn.status
|
||||||
|
|
||||||
# column typarray not available before PG 8.3
|
# column typarray not available before PG 8.3
|
||||||
typarray = conn.server_version >= 80300 and "typarray" or "NULL"
|
typarray = conn.info.server_version >= 80300 and "typarray" or "NULL"
|
||||||
|
|
||||||
rv0, rv1 = [], []
|
rv0, rv1 = [], []
|
||||||
|
|
||||||
|
@ -1097,7 +1097,7 @@ class CompositeCaster(object):
|
||||||
schema = 'public'
|
schema = 'public'
|
||||||
|
|
||||||
# column typarray not available before PG 8.3
|
# column typarray not available before PG 8.3
|
||||||
typarray = conn.server_version >= 80300 and "typarray" or "NULL"
|
typarray = conn.info.server_version >= 80300 and "typarray" or "NULL"
|
||||||
|
|
||||||
# get the type oid and attributes
|
# get the type oid and attributes
|
||||||
curs.execute("""\
|
curs.execute("""\
|
||||||
|
|
|
@ -105,7 +105,7 @@ class AbstractConnectionPool(object):
|
||||||
# Return the connection into a consistent state before putting
|
# Return the connection into a consistent state before putting
|
||||||
# it back into the pool
|
# it back into the pool
|
||||||
if not conn.closed:
|
if not conn.closed:
|
||||||
status = conn.get_transaction_status()
|
status = conn.info.transaction_status
|
||||||
if status == _ext.TRANSACTION_STATUS_UNKNOWN:
|
if status == _ext.TRANSACTION_STATUS_UNKNOWN:
|
||||||
# server connection lost
|
# server connection lost
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -40,7 +40,7 @@ static const char notify_doc[] =
|
||||||
static const char pid_doc[] =
|
static const char pid_doc[] =
|
||||||
"The ID of the backend process that sent the notification.\n\n"
|
"The ID of the backend process that sent the notification.\n\n"
|
||||||
"Note: if the sending session was handled by Psycopg, you can use\n"
|
"Note: if the sending session was handled by Psycopg, you can use\n"
|
||||||
"`~connection.get_backend_pid()` to know its PID.";
|
"`~connection.info.backend_pid` to know its PID.";
|
||||||
|
|
||||||
static const char channel_doc[] =
|
static const char channel_doc[] =
|
||||||
"The name of the channel to which the notification was sent.";
|
"The name of the channel to which the notification was sent.";
|
||||||
|
|
|
@ -192,7 +192,7 @@ class AsyncTests(ConnectingTestCase):
|
||||||
self.assertTrue(self.conn.isexecuting())
|
self.assertTrue(self.conn.isexecuting())
|
||||||
|
|
||||||
# getting transaction status works
|
# getting transaction status works
|
||||||
self.assertEquals(self.conn.get_transaction_status(),
|
self.assertEquals(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_ACTIVE)
|
ext.TRANSACTION_STATUS_ACTIVE)
|
||||||
self.assertTrue(self.conn.isexecuting())
|
self.assertTrue(self.conn.isexecuting())
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ class AsyncTests(ConnectingTestCase):
|
||||||
|
|
||||||
self.assertEquals(self.sync_conn.notifies, [])
|
self.assertEquals(self.sync_conn.notifies, [])
|
||||||
|
|
||||||
pid = self.conn.get_backend_pid()
|
pid = self.conn.info.backend_pid
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
self.wait(self.sync_conn)
|
self.wait(self.sync_conn)
|
||||||
if not self.sync_conn.notifies:
|
if not self.sync_conn.notifies:
|
||||||
|
@ -418,7 +418,7 @@ class AsyncTests(ConnectingTestCase):
|
||||||
def test_notices(self):
|
def test_notices(self):
|
||||||
del self.conn.notices[:]
|
del self.conn.notices[:]
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
if self.conn.server_version >= 90300:
|
if self.conn.info.server_version >= 90300:
|
||||||
cur.execute("set client_min_messages=debug1")
|
cur.execute("set client_min_messages=debug1")
|
||||||
self.wait(cur)
|
self.wait(cur)
|
||||||
cur.execute("create temp table chatty (id serial primary key);")
|
cur.execute("create temp table chatty (id serial primary key);")
|
||||||
|
|
|
@ -87,13 +87,13 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
conn.autocommit = True
|
conn.autocommit = True
|
||||||
conn.isolation_level = 'serializable'
|
conn.isolation_level = 'serializable'
|
||||||
conn.readonly = True
|
conn.readonly = True
|
||||||
if self.conn.server_version >= 90100:
|
if self.conn.info.server_version >= 90100:
|
||||||
conn.deferrable = False
|
conn.deferrable = False
|
||||||
|
|
||||||
self.assert_(conn.autocommit)
|
self.assert_(conn.autocommit)
|
||||||
self.assertEqual(conn.isolation_level, ext.ISOLATION_LEVEL_SERIALIZABLE)
|
self.assertEqual(conn.isolation_level, ext.ISOLATION_LEVEL_SERIALIZABLE)
|
||||||
self.assert_(conn.readonly is True)
|
self.assert_(conn.readonly is True)
|
||||||
if self.conn.server_version >= 90100:
|
if self.conn.info.server_version >= 90100:
|
||||||
self.assert_(conn.deferrable is False)
|
self.assert_(conn.deferrable is False)
|
||||||
|
|
||||||
conn.reset()
|
conn.reset()
|
||||||
|
@ -101,13 +101,13 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
self.assert_(not conn.autocommit)
|
self.assert_(not conn.autocommit)
|
||||||
self.assertEqual(conn.isolation_level, ext.ISOLATION_LEVEL_DEFAULT)
|
self.assertEqual(conn.isolation_level, ext.ISOLATION_LEVEL_DEFAULT)
|
||||||
self.assert_(conn.readonly is None)
|
self.assert_(conn.readonly is None)
|
||||||
if self.conn.server_version >= 90100:
|
if self.conn.info.server_version >= 90100:
|
||||||
self.assert_(conn.deferrable is None)
|
self.assert_(conn.deferrable is None)
|
||||||
|
|
||||||
def test_notices(self):
|
def test_notices(self):
|
||||||
conn = self.conn
|
conn = self.conn
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
if self.conn.server_version >= 90300:
|
if self.conn.info.server_version >= 90300:
|
||||||
cur.execute("set client_min_messages=debug1")
|
cur.execute("set client_min_messages=debug1")
|
||||||
cur.execute("create temp table chatty (id serial primary key);")
|
cur.execute("create temp table chatty (id serial primary key);")
|
||||||
self.assertEqual("CREATE TABLE", cur.statusmessage)
|
self.assertEqual("CREATE TABLE", cur.statusmessage)
|
||||||
|
@ -116,7 +116,7 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
def test_notices_consistent_order(self):
|
def test_notices_consistent_order(self):
|
||||||
conn = self.conn
|
conn = self.conn
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
if self.conn.server_version >= 90300:
|
if self.conn.info.server_version >= 90300:
|
||||||
cur.execute("set client_min_messages=debug1")
|
cur.execute("set client_min_messages=debug1")
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
create temp table table1 (id serial);
|
create temp table table1 (id serial);
|
||||||
|
@ -136,7 +136,7 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
def test_notices_limited(self):
|
def test_notices_limited(self):
|
||||||
conn = self.conn
|
conn = self.conn
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
if self.conn.server_version >= 90300:
|
if self.conn.info.server_version >= 90300:
|
||||||
cur.execute("set client_min_messages=debug1")
|
cur.execute("set client_min_messages=debug1")
|
||||||
for i in range(0, 100, 10):
|
for i in range(0, 100, 10):
|
||||||
sql = " ".join(["create temp table table%d (id serial);" % j
|
sql = " ".join(["create temp table table%d (id serial);" % j
|
||||||
|
@ -153,7 +153,7 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
conn = self.conn
|
conn = self.conn
|
||||||
self.conn.notices = deque()
|
self.conn.notices = deque()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
if self.conn.server_version >= 90300:
|
if self.conn.info.server_version >= 90300:
|
||||||
cur.execute("set client_min_messages=debug1")
|
cur.execute("set client_min_messages=debug1")
|
||||||
|
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
|
@ -183,7 +183,7 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
conn = self.conn
|
conn = self.conn
|
||||||
self.conn.notices = None # will make an error swallowes ok
|
self.conn.notices = None # will make an error swallowes ok
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
if self.conn.server_version >= 90300:
|
if self.conn.info.server_version >= 90300:
|
||||||
cur.execute("set client_min_messages=debug1")
|
cur.execute("set client_min_messages=debug1")
|
||||||
|
|
||||||
cur.execute("create temp table table1 (id serial);")
|
cur.execute("create temp table table1 (id serial);")
|
||||||
|
@ -199,7 +199,7 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
|
|
||||||
def test_tpc_unsupported(self):
|
def test_tpc_unsupported(self):
|
||||||
cnn = self.conn
|
cnn = self.conn
|
||||||
if cnn.server_version >= 80100:
|
if cnn.info.server_version >= 80100:
|
||||||
return self.skipTest("tpc is supported")
|
return self.skipTest("tpc is supported")
|
||||||
|
|
||||||
self.assertRaises(psycopg2.NotSupportedError,
|
self.assertRaises(psycopg2.NotSupportedError,
|
||||||
|
@ -533,7 +533,7 @@ class IsolationLevelsTestCase(ConnectingTestCase):
|
||||||
conn.set_isolation_level(level)
|
conn.set_isolation_level(level)
|
||||||
|
|
||||||
# the only values available on prehistoric PG versions
|
# the only values available on prehistoric PG versions
|
||||||
if conn.server_version < 80000:
|
if conn.info.server_version < 80000:
|
||||||
if level in (
|
if level in (
|
||||||
ext.ISOLATION_LEVEL_READ_UNCOMMITTED,
|
ext.ISOLATION_LEVEL_READ_UNCOMMITTED,
|
||||||
ext.ISOLATION_LEVEL_REPEATABLE_READ):
|
ext.ISOLATION_LEVEL_REPEATABLE_READ):
|
||||||
|
@ -589,35 +589,35 @@ class IsolationLevelsTestCase(ConnectingTestCase):
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
self.assertEqual(ext.TRANSACTION_STATUS_IDLE,
|
self.assertEqual(ext.TRANSACTION_STATUS_IDLE,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
cur.execute("insert into isolevel values (10);")
|
cur.execute("insert into isolevel values (10);")
|
||||||
self.assertEqual(ext.TRANSACTION_STATUS_INTRANS,
|
self.assertEqual(ext.TRANSACTION_STATUS_INTRANS,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
|
|
||||||
conn.set_isolation_level(
|
conn.set_isolation_level(
|
||||||
psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE)
|
psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE)
|
||||||
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
cur.execute("select count(*) from isolevel;")
|
cur.execute("select count(*) from isolevel;")
|
||||||
self.assertEqual(0, cur.fetchone()[0])
|
self.assertEqual(0, cur.fetchone()[0])
|
||||||
|
|
||||||
cur.execute("insert into isolevel values (10);")
|
cur.execute("insert into isolevel values (10);")
|
||||||
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_INTRANS,
|
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_INTRANS,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
conn.set_isolation_level(
|
conn.set_isolation_level(
|
||||||
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
cur.execute("select count(*) from isolevel;")
|
cur.execute("select count(*) from isolevel;")
|
||||||
self.assertEqual(0, cur.fetchone()[0])
|
self.assertEqual(0, cur.fetchone()[0])
|
||||||
|
|
||||||
cur.execute("insert into isolevel values (10);")
|
cur.execute("insert into isolevel values (10);")
|
||||||
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
conn.set_isolation_level(
|
conn.set_isolation_level(
|
||||||
psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED)
|
psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED)
|
||||||
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
self.assertEqual(psycopg2.extensions.TRANSACTION_STATUS_IDLE,
|
||||||
conn.get_transaction_status())
|
conn.info.transaction_status)
|
||||||
cur.execute("select count(*) from isolevel;")
|
cur.execute("select count(*) from isolevel;")
|
||||||
self.assertEqual(1, cur.fetchone()[0])
|
self.assertEqual(1, cur.fetchone()[0])
|
||||||
self.assertEqual(conn.isolation_level,
|
self.assertEqual(conn.isolation_level,
|
||||||
|
@ -713,7 +713,7 @@ class IsolationLevelsTestCase(ConnectingTestCase):
|
||||||
|
|
||||||
self.conn.isolation_level = ext.ISOLATION_LEVEL_REPEATABLE_READ
|
self.conn.isolation_level = ext.ISOLATION_LEVEL_REPEATABLE_READ
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(self.conn.isolation_level,
|
self.assertEqual(self.conn.isolation_level,
|
||||||
ext.ISOLATION_LEVEL_REPEATABLE_READ)
|
ext.ISOLATION_LEVEL_REPEATABLE_READ)
|
||||||
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
||||||
|
@ -732,7 +732,7 @@ class IsolationLevelsTestCase(ConnectingTestCase):
|
||||||
|
|
||||||
self.conn.isolation_level = ext.ISOLATION_LEVEL_READ_UNCOMMITTED
|
self.conn.isolation_level = ext.ISOLATION_LEVEL_READ_UNCOMMITTED
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(self.conn.isolation_level,
|
self.assertEqual(self.conn.isolation_level,
|
||||||
ext.ISOLATION_LEVEL_READ_UNCOMMITTED)
|
ext.ISOLATION_LEVEL_READ_UNCOMMITTED)
|
||||||
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
||||||
|
@ -761,7 +761,7 @@ class IsolationLevelsTestCase(ConnectingTestCase):
|
||||||
|
|
||||||
self.conn.isolation_level = "repeatable read"
|
self.conn.isolation_level = "repeatable read"
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(self.conn.isolation_level,
|
self.assertEqual(self.conn.isolation_level,
|
||||||
ext.ISOLATION_LEVEL_REPEATABLE_READ)
|
ext.ISOLATION_LEVEL_REPEATABLE_READ)
|
||||||
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
||||||
|
@ -780,7 +780,7 @@ class IsolationLevelsTestCase(ConnectingTestCase):
|
||||||
|
|
||||||
self.conn.isolation_level = "read uncommitted"
|
self.conn.isolation_level = "read uncommitted"
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(self.conn.isolation_level,
|
self.assertEqual(self.conn.isolation_level,
|
||||||
ext.ISOLATION_LEVEL_READ_UNCOMMITTED)
|
ext.ISOLATION_LEVEL_READ_UNCOMMITTED)
|
||||||
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
||||||
|
@ -1203,7 +1203,7 @@ class TransactionControlTests(ConnectingTestCase):
|
||||||
self.conn.set_session(
|
self.conn.set_session(
|
||||||
ext.ISOLATION_LEVEL_REPEATABLE_READ)
|
ext.ISOLATION_LEVEL_REPEATABLE_READ)
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
||||||
else:
|
else:
|
||||||
self.assertEqual(cur.fetchone()[0], 'serializable')
|
self.assertEqual(cur.fetchone()[0], 'serializable')
|
||||||
|
@ -1218,7 +1218,7 @@ class TransactionControlTests(ConnectingTestCase):
|
||||||
self.conn.set_session(
|
self.conn.set_session(
|
||||||
isolation_level=ext.ISOLATION_LEVEL_READ_UNCOMMITTED)
|
isolation_level=ext.ISOLATION_LEVEL_READ_UNCOMMITTED)
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
||||||
else:
|
else:
|
||||||
self.assertEqual(cur.fetchone()[0], 'read committed')
|
self.assertEqual(cur.fetchone()[0], 'read committed')
|
||||||
|
@ -1233,7 +1233,7 @@ class TransactionControlTests(ConnectingTestCase):
|
||||||
|
|
||||||
self.conn.set_session("repeatable read")
|
self.conn.set_session("repeatable read")
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
self.assertEqual(cur.fetchone()[0], 'repeatable read')
|
||||||
else:
|
else:
|
||||||
self.assertEqual(cur.fetchone()[0], 'serializable')
|
self.assertEqual(cur.fetchone()[0], 'serializable')
|
||||||
|
@ -1246,7 +1246,7 @@ class TransactionControlTests(ConnectingTestCase):
|
||||||
|
|
||||||
self.conn.set_session("read uncommitted")
|
self.conn.set_session("read uncommitted")
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
if self.conn.server_version > 80000:
|
if self.conn.info.server_version > 80000:
|
||||||
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
self.assertEqual(cur.fetchone()[0], 'read uncommitted')
|
||||||
else:
|
else:
|
||||||
self.assertEqual(cur.fetchone()[0], 'read committed')
|
self.assertEqual(cur.fetchone()[0], 'read committed')
|
||||||
|
@ -1502,42 +1502,42 @@ class AutocommitTests(ConnectingTestCase):
|
||||||
def test_default_no_autocommit(self):
|
def test_default_no_autocommit(self):
|
||||||
self.assert_(not self.conn.autocommit)
|
self.assert_(not self.conn.autocommit)
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
cur.execute('select 1;')
|
cur.execute('select 1;')
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_BEGIN)
|
self.assertEqual(self.conn.status, ext.STATUS_BEGIN)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_INTRANS)
|
ext.TRANSACTION_STATUS_INTRANS)
|
||||||
|
|
||||||
self.conn.rollback()
|
self.conn.rollback()
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
def test_set_autocommit(self):
|
def test_set_autocommit(self):
|
||||||
self.conn.autocommit = True
|
self.conn.autocommit = True
|
||||||
self.assert_(self.conn.autocommit)
|
self.assert_(self.conn.autocommit)
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
cur.execute('select 1;')
|
cur.execute('select 1;')
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
self.conn.autocommit = False
|
self.conn.autocommit = False
|
||||||
self.assert_(not self.conn.autocommit)
|
self.assert_(not self.conn.autocommit)
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
cur.execute('select 1;')
|
cur.execute('select 1;')
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_BEGIN)
|
self.assertEqual(self.conn.status, ext.STATUS_BEGIN)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_INTRANS)
|
ext.TRANSACTION_STATUS_INTRANS)
|
||||||
|
|
||||||
def test_set_intrans_error(self):
|
def test_set_intrans_error(self):
|
||||||
|
@ -1550,24 +1550,24 @@ class AutocommitTests(ConnectingTestCase):
|
||||||
self.conn.set_session(autocommit=True)
|
self.conn.set_session(autocommit=True)
|
||||||
self.assert_(self.conn.autocommit)
|
self.assert_(self.conn.autocommit)
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
cur.execute('select 1;')
|
cur.execute('select 1;')
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
self.conn.set_session(autocommit=False)
|
self.conn.set_session(autocommit=False)
|
||||||
self.assert_(not self.conn.autocommit)
|
self.assert_(not self.conn.autocommit)
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
cur.execute('select 1;')
|
cur.execute('select 1;')
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_BEGIN)
|
self.assertEqual(self.conn.status, ext.STATUS_BEGIN)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_INTRANS)
|
ext.TRANSACTION_STATUS_INTRANS)
|
||||||
self.conn.rollback()
|
self.conn.rollback()
|
||||||
|
|
||||||
|
@ -1575,7 +1575,7 @@ class AutocommitTests(ConnectingTestCase):
|
||||||
self.assert_(self.conn.autocommit)
|
self.assert_(self.conn.autocommit)
|
||||||
cur.execute('select 1;')
|
cur.execute('select 1;')
|
||||||
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
self.assertEqual(self.conn.status, ext.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
ext.TRANSACTION_STATUS_IDLE)
|
ext.TRANSACTION_STATUS_IDLE)
|
||||||
cur.execute("SHOW transaction_isolation;")
|
cur.execute("SHOW transaction_isolation;")
|
||||||
self.assertEqual(cur.fetchone()[0], 'serializable')
|
self.assertEqual(cur.fetchone()[0], 'serializable')
|
||||||
|
|
|
@ -229,22 +229,22 @@ class CursorTests(ConnectingTestCase):
|
||||||
curs.execute("select data from withhold order by data")
|
curs.execute("select data from withhold order by data")
|
||||||
self.assertEqual(curs.fetchone(), (10,))
|
self.assertEqual(curs.fetchone(), (10,))
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_BEGIN)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_BEGIN)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_INTRANS)
|
psycopg2.extensions.TRANSACTION_STATUS_INTRANS)
|
||||||
|
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
self.assertEqual(curs.fetchone(), (20,))
|
self.assertEqual(curs.fetchone(), (20,))
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
curs.close()
|
curs.close()
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
def test_withhold_autocommit(self):
|
def test_withhold_autocommit(self):
|
||||||
|
@ -256,17 +256,17 @@ class CursorTests(ConnectingTestCase):
|
||||||
|
|
||||||
self.assertEqual(curs.fetchone(), (10,))
|
self.assertEqual(curs.fetchone(), (10,))
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
curs.close()
|
curs.close()
|
||||||
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
self.assertEqual(self.conn.status, psycopg2.extensions.STATUS_READY)
|
||||||
self.assertEqual(self.conn.get_transaction_status(),
|
self.assertEqual(self.conn.info.transaction_status,
|
||||||
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
psycopg2.extensions.TRANSACTION_STATUS_IDLE)
|
||||||
|
|
||||||
def test_scrollable(self):
|
def test_scrollable(self):
|
||||||
|
|
|
@ -37,7 +37,7 @@ from .testutils import (decorate_all_tests, skip_if_tpc_disabled,
|
||||||
def skip_if_no_lo(f):
|
def skip_if_no_lo(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def skip_if_no_lo_(self):
|
def skip_if_no_lo_(self):
|
||||||
if self.conn.server_version < 80100:
|
if self.conn.info.server_version < 80100:
|
||||||
return self.skipTest("large objects only supported from PG 8.1")
|
return self.skipTest("large objects only supported from PG 8.1")
|
||||||
else:
|
else:
|
||||||
return f(self)
|
return f(self)
|
||||||
|
@ -403,7 +403,7 @@ decorate_all_tests(LargeObjectTests, skip_if_no_lo, skip_lo_if_green)
|
||||||
def skip_if_no_truncate(f):
|
def skip_if_no_truncate(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def skip_if_no_truncate_(self):
|
def skip_if_no_truncate_(self):
|
||||||
if self.conn.server_version < 80300:
|
if self.conn.info.server_version < 80300:
|
||||||
return self.skipTest(
|
return self.skipTest(
|
||||||
"the server doesn't support large object truncate")
|
"the server doesn't support large object truncate")
|
||||||
|
|
||||||
|
@ -459,9 +459,9 @@ decorate_all_tests(LargeObjectTruncateTests,
|
||||||
|
|
||||||
def _has_lo64(conn):
|
def _has_lo64(conn):
|
||||||
"""Return (bool, msg) about the lo64 support"""
|
"""Return (bool, msg) about the lo64 support"""
|
||||||
if conn.server_version < 90300:
|
if conn.info.server_version < 90300:
|
||||||
return (False, "server version %s doesn't support the lo64 API"
|
return (False, "server version %s doesn't support the lo64 API"
|
||||||
% conn.server_version)
|
% conn.info.server_version)
|
||||||
|
|
||||||
if 'lo64' not in psycopg2.__version__:
|
if 'lo64' not in psycopg2.__version__:
|
||||||
return False, "this psycopg build doesn't support the lo64 API"
|
return False, "this psycopg build doesn't support the lo64 API"
|
||||||
|
|
|
@ -61,7 +61,7 @@ import %(module)s as psycopg2
|
||||||
import %(module)s.extensions as ext
|
import %(module)s.extensions as ext
|
||||||
conn = psycopg2.connect(%(dsn)r)
|
conn = psycopg2.connect(%(dsn)r)
|
||||||
conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT)
|
conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
print(conn.get_backend_pid())
|
print(conn.info.backend_pid)
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
curs.execute("NOTIFY " %(name)r %(payload)r)
|
curs.execute("NOTIFY " %(name)r %(payload)r)
|
||||||
curs.close()
|
curs.close()
|
||||||
|
@ -147,9 +147,9 @@ conn.close()
|
||||||
|
|
||||||
@slow
|
@slow
|
||||||
def test_notify_payload(self):
|
def test_notify_payload(self):
|
||||||
if self.conn.server_version < 90000:
|
if self.conn.info.server_version < 90000:
|
||||||
return self.skipTest("server version %s doesn't support notify payload"
|
return self.skipTest("server version %s doesn't support notify payload"
|
||||||
% self.conn.server_version)
|
% self.conn.info.server_version)
|
||||||
self.autocommit(self.conn)
|
self.autocommit(self.conn)
|
||||||
self.listen('foo')
|
self.listen('foo')
|
||||||
pid = int(self.notify('foo', payload="Hello, world!").communicate()[0])
|
pid = int(self.notify('foo', payload="Hello, world!").communicate()[0])
|
||||||
|
|
|
@ -90,7 +90,7 @@ class QuotingTestCase(ConnectingTestCase):
|
||||||
else:
|
else:
|
||||||
res = curs.fetchone()[0].tobytes()
|
res = curs.fetchone()[0].tobytes()
|
||||||
|
|
||||||
if res[0] in (b'x', ord(b'x')) and self.conn.server_version >= 90000:
|
if res[0] in (b'x', ord(b'x')) and self.conn.info.server_version >= 90000:
|
||||||
return self.skipTest(
|
return self.skipTest(
|
||||||
"bytea broken with server >= 9.0, libpq < 9")
|
"bytea broken with server >= 9.0, libpq < 9")
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ def skip_if_no_hstore(f):
|
||||||
|
|
||||||
class HstoreTestCase(ConnectingTestCase):
|
class HstoreTestCase(ConnectingTestCase):
|
||||||
def test_adapt_8(self):
|
def test_adapt_8(self):
|
||||||
if self.conn.server_version >= 90000:
|
if self.conn.info.server_version >= 90000:
|
||||||
return self.skipTest("skipping dict adaptation with PG pre-9 syntax")
|
return self.skipTest("skipping dict adaptation with PG pre-9 syntax")
|
||||||
|
|
||||||
from psycopg2.extras import HstoreAdapter
|
from psycopg2.extras import HstoreAdapter
|
||||||
|
@ -163,7 +163,7 @@ class HstoreTestCase(ConnectingTestCase):
|
||||||
self.assertQuotedEqual(ii[3], b"('d' => '" + encc + b"')")
|
self.assertQuotedEqual(ii[3], b"('d' => '" + encc + b"')")
|
||||||
|
|
||||||
def test_adapt_9(self):
|
def test_adapt_9(self):
|
||||||
if self.conn.server_version < 90000:
|
if self.conn.info.server_version < 90000:
|
||||||
return self.skipTest("skipping dict adaptation with PG 9 syntax")
|
return self.skipTest("skipping dict adaptation with PG 9 syntax")
|
||||||
|
|
||||||
from psycopg2.extras import HstoreAdapter
|
from psycopg2.extras import HstoreAdapter
|
||||||
|
@ -448,10 +448,10 @@ class HstoreTestCase(ConnectingTestCase):
|
||||||
def skip_if_no_composite(f):
|
def skip_if_no_composite(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def skip_if_no_composite_(self):
|
def skip_if_no_composite_(self):
|
||||||
if self.conn.server_version < 80000:
|
if self.conn.info.server_version < 80000:
|
||||||
return self.skipTest(
|
return self.skipTest(
|
||||||
"server version %s doesn't support composite types"
|
"server version %s doesn't support composite types"
|
||||||
% self.conn.server_version)
|
% self.conn.info.server_version)
|
||||||
|
|
||||||
return f(self)
|
return f(self)
|
||||||
|
|
||||||
|
@ -1436,10 +1436,10 @@ class RangeTestCase(unittest.TestCase):
|
||||||
def skip_if_no_range(f):
|
def skip_if_no_range(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def skip_if_no_range_(self):
|
def skip_if_no_range_(self):
|
||||||
if self.conn.server_version < 90200:
|
if self.conn.info.server_version < 90200:
|
||||||
return self.skipTest(
|
return self.skipTest(
|
||||||
"server version %s doesn't support range types"
|
"server version %s doesn't support range types"
|
||||||
% self.conn.server_version)
|
% self.conn.info.server_version)
|
||||||
|
|
||||||
return f(self)
|
return f(self)
|
||||||
|
|
||||||
|
|
|
@ -234,9 +234,9 @@ def skip_before_postgres(*ver):
|
||||||
def skip_before_postgres_(f):
|
def skip_before_postgres_(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def skip_before_postgres__(self):
|
def skip_before_postgres__(self):
|
||||||
if self.conn.server_version < int("%d%02d%02d" % ver):
|
if self.conn.info.server_version < int("%d%02d%02d" % ver):
|
||||||
return self.skipTest("skipped because PostgreSQL %s"
|
return self.skipTest("skipped because PostgreSQL %s"
|
||||||
% self.conn.server_version)
|
% self.conn.info.server_version)
|
||||||
else:
|
else:
|
||||||
return f(self)
|
return f(self)
|
||||||
|
|
||||||
|
@ -251,9 +251,9 @@ def skip_after_postgres(*ver):
|
||||||
def skip_after_postgres_(f):
|
def skip_after_postgres_(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def skip_after_postgres__(self):
|
def skip_after_postgres__(self):
|
||||||
if self.conn.server_version >= int("%d%02d%02d" % ver):
|
if self.conn.info.server_version >= int("%d%02d%02d" % ver):
|
||||||
return self.skipTest("skipped because PostgreSQL %s"
|
return self.skipTest("skipped because PostgreSQL %s"
|
||||||
% self.conn.server_version)
|
% self.conn.info.server_version)
|
||||||
else:
|
else:
|
||||||
return f(self)
|
return f(self)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user