Author: cito
Date: Sun Jan 31 14:51:16 2016
New Revision: 801
Log:
Add documentation and tests for two older methods
transaction() was there since 3.6 and parameter() since 4.0,
but they have never been documented or tested
Modified:
trunk/docs/contents/pg/connection.rst
trunk/docs/contents/pg/db_wrapper.rst
trunk/docs/contents/pg/module.rst
trunk/tests/test_classic_connection.py
Modified: trunk/docs/contents/pg/connection.rst
==============================================================================
--- trunk/docs/contents/pg/connection.rst Sun Jan 31 13:46:53 2016
(r800)
+++ trunk/docs/contents/pg/connection.rst Sun Jan 31 14:51:16 2016
(r801)
@@ -110,6 +110,53 @@
allows you to explicitly close it. It is mainly here to allow
the DB-SIG API wrapper to implement a close function.
+transaction -- get the current transaction state
+------------------------------------------------
+
+.. method:: Connection.transaction()
+
+ Get the current in-transaction status of the server
+
+ :returns: the current in-transaction status
+ :rtype: int
+ :raises TypeError: too many (any) arguments
+ :raises TypeError: invalid connection
+
+The status returned by this method can be :const:`TRANS_IDLE` (currently idle),
+:const:`TRANS_ACTIVE` (a command is in progress), :const:`TRANS_INTRANS` (idle,
+in a valid transaction block), or :const:`TRANS_INERROR` (idle, in a failed
+transaction block). :const:`TRANS_UNKNOWN` is reported if the connection is
+bad. The status :const:`TRANS_ACTIVE` is reported only when a query has been
+sent to the server and not yet completed.
+
+parameter -- get a current server parameter setting
+---------------------------------------------------
+
+.. method:: Connection.parameter(name)
+
+ Looks up a current parameter setting of the server
+
+ :param str name: the name of the parameter to look up
+ :returns: the current setting of the specified parameter
+ :rtype: str or None
+ :raises TypeError: too many (any) arguments
+ :raises TypeError: invalid connection
+
+Certain parameter values are reported by the server automatically at
+connection startup or whenever their values change. This method can be used
+to interrogate these settings. It returns the current value of a parameter
+if known, or *None* if the parameter is not known.
+
+You can use this method to check the settings of important parameters such as
+`server_version`, `server_encoding`, `client_encoding`, `application_name`,
+`is_superuser`, `session_authorization`, `DateStyle`, `IntervalStyle`,
+`TimeZone`, `integer_datetimes`, and `standard_conforming_strings`.
+
+Values that are not reported by this method can be requested using
+:meth:`DB.get_parameter`.
+
+.. versionadded:: 4.0
+
fileno -- returns the socket used to connect to the database
------------------------------------------------------------
Modified: trunk/docs/contents/pg/db_wrapper.rst
==============================================================================
--- trunk/docs/contents/pg/db_wrapper.rst Sun Jan 31 13:46:53 2016
(r800)
+++ trunk/docs/contents/pg/db_wrapper.rst Sun Jan 31 14:51:16 2016
(r801)
@@ -172,9 +172,13 @@
its values will be set to the current parameter settings corresponding
to its keys.
-By passing the special name `'all'` as the parameter, you can get a dict
+By passing the special name ``'all'`` as the parameter, you can get a dict
of all existing configuration parameters.
+Note that you can request most of the important parameters also using
+:meth:`Connection.parameter()` which does not involve a database query
+like it is the case for :meth:`DB.get_parameter` and :meth:`DB.set_parameter`.
+
.. versionadded:: 4.2
.. method:: DB.set_parameter(parameter, [value], [local])
@@ -201,7 +205,7 @@
case, you should not pass a value, since the values for the parameters
will be taken from the dict.
-By passing the special name `'all'` as the parameter, you can reset
+By passing the special name ``'all'`` as the parameter, you can reset
all existing settable run-time parameters to their default values.
If you set *local* to `True`, then the command takes effect for only the
Modified: trunk/docs/contents/pg/module.rst
==============================================================================
--- trunk/docs/contents/pg/module.rst Sun Jan 31 13:46:53 2016 (r800)
+++ trunk/docs/contents/pg/module.rst Sun Jan 31 14:51:16 2016 (r801)
@@ -526,15 +526,27 @@
You should refer to the libpq description in the PostgreSQL user manual
for more information about them. These constants are:
-.. data:: version, __version__
+.. data:: version
+.. data:: __version__
constants that give the current version
-.. data:: INV_READ, INV_WRITE
+.. data:: INV_READ
+.. data:: INV_WRITE
large objects access modes,
used by :meth:`Connection.locreate` and :meth:`LargeObject.open`
-.. data:: SEEK_SET, SEEK_CUR, SEEK_END:
+.. data:: SEEK_SET
+.. data:: SEEK_CUR
+.. data:: SEEK_END
positional flags, used by :meth:`LargeObject.seek`
+
+.. data:: TRANS_IDLE
+.. data:: TRANS_ACTIVE
+.. data:: TRANS_INTRANS
+.. data:: TRANS_INERROR
+.. data:: TRANS_UNKNOWN
+
+ transaction states, used by :meth:`Connection.transaction`
Modified: trunk/tests/test_classic_connection.py
==============================================================================
--- trunk/tests/test_classic_connection.py Sun Jan 31 13:46:53 2016
(r800)
+++ trunk/tests/test_classic_connection.py Sun Jan 31 14:51:16 2016
(r801)
@@ -255,6 +255,38 @@
self.assertIsInstance(r, int)
self.assertGreaterEqual(r, 0)
+ def testMethodTransaction(self):
+ transaction = self.connection.transaction
+ self.assertRaises(TypeError, transaction, None)
+ self.assertEqual(transaction(), pg.TRANS_IDLE)
+ self.connection.query('begin')
+ self.assertEqual(transaction(), pg.TRANS_INTRANS)
+ self.connection.query('rollback')
+ self.assertEqual(transaction(), pg.TRANS_IDLE)
+
+ def testMethodParameter(self):
+ parameter = self.connection.parameter
+ query = self.connection.query
+ self.assertRaises(TypeError, parameter)
+ r = parameter('this server setting does not exist')
+ self.assertIsNone(r)
+ s = query('show server_version').getresult()[0][0].upper()
+ self.assertIsNotNone(s)
+ r = parameter('server_version')
+ self.assertEqual(r, s)
+ s = query('show server_encoding').getresult()[0][0].upper()
+ self.assertIsNotNone(s)
+ r = parameter('server_encoding')
+ self.assertEqual(r, s)
+ s = query('show client_encoding').getresult()[0][0].upper()
+ self.assertIsNotNone(s)
+ r = parameter('client_encoding')
+ self.assertEqual(r, s)
+ s = query('show server_encoding').getresult()[0][0].upper()
+ self.assertIsNotNone(s)
+ r = parameter('server_encoding')
+ self.assertEqual(r, s)
+
class TestSimpleQueries(unittest.TestCase):
"""Test simple queries via a basic pg connection."""
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql