diff --git a/README.rst b/README.rst index 35c6e7b..e2a16e0 100644 --- a/README.rst +++ b/README.rst @@ -275,9 +275,7 @@ PostgreSQL `notices `_ are stored in a deque called ``Connection.notices`` and added using the ``append()`` method. Similarly there are ``Connection.notifications`` for `notifications -`_ and -``Connection.parameter_statuses`` for changes to the server configuration. Here's an -example: +`_. Here's an example: >>> import pg8000.native >>> @@ -293,6 +291,26 @@ example: >>> con.close() +Parameter Statuses +`````````````````` + +`Certain parameter values are reported by the server automatically at connection startup or whenever +their values change +`_ and pg8000 +stores the latest values in a dict called ``Connection.parameter_statuses``. Here's an example where +we set the ``aplication_name`` parameter and then read it from the ``parameter_statuses``: + +>>> import pg8000.native +>>> +>>> con = pg8000.native.Connection( +... "postgres", password="cpsnow", application_name='AGI') +>>> +>>> con.parameter_statuses['application_name'] +'AGI' +>>> +>>> con.close() + + LIMIT ALL ````````` diff --git a/pg8000/core.py b/pg8000/core.py index 54ef496..3e55957 100644 --- a/pg8000/core.py +++ b/pg8000/core.py @@ -277,7 +277,7 @@ def __init__( ) self.notifications = deque(maxlen=100) self.notices = deque(maxlen=100) - self.parameter_statuses = deque(maxlen=100) + self.parameter_statuses = {} if user is None: raise InterfaceError("The 'user' connection parameter cannot be None") @@ -842,20 +842,20 @@ def handle_NOTICE_RESPONSE(self, data, context): def handle_PARAMETER_STATUS(self, data, context): pos = data.find(NULL_BYTE) - key, value = data[:pos], data[pos + 1 : -1] - self.parameter_statuses.append((key, value)) - if key == b"client_encoding": - encoding = value.decode("ascii").lower() + key, value = data[:pos].decode("ascii"), data[pos + 1 : -1].decode("ascii") + self.parameter_statuses[key] = value + if key == "client_encoding": + encoding = value.lower() self._client_encoding = PG_PY_ENCODINGS.get(encoding, encoding) - elif key == b"integer_datetimes": - if value == b"on": + elif key == "integer_datetimes": + if value == "on": pass else: pass - elif key == b"server_version": + elif key == "server_version": pass