Allow the connection driver to return notices/messages from the server.

This commit is contained in:
Ashesh Vashi 2016-03-04 10:35:50 +00:00 committed by Dave Page
parent d2e372114b
commit 0b43443151
2 changed files with 31 additions and 8 deletions

View File

@ -10,7 +10,6 @@
"""Implement the Base class for Driver and Connection""" """Implement the Base class for Driver and Connection"""
from abc import ABCMeta, abstractmethod, abstractproperty from abc import ABCMeta, abstractmethod, abstractproperty
from flask import session
from .registry import DriverRegistry from .registry import DriverRegistry
import six import six
@ -125,16 +124,23 @@ class BaseConnection(object):
management. management.
* _wait(conn) * _wait(conn)
- Implement this method to wait for asynchronous connection. This is a blocking call. - Implement this method to wait for asynchronous connection to finish the
execution, hence - it must be a blocking call.
* _wait_timeout(conn, time) * _wait_timeout(conn, time)
- Implement this method to wait for asynchronous connection with timeout. This is a non blocking call. - Implement this method to wait for asynchronous connection with timeout.
This must be a non blocking call.
* poll() * poll()
- Implement this method to poll the data of query running on asynchronous connection. - Implement this method to poll the data of query running on asynchronous
connection.
* cancel_transaction(conn_id, did=None) * cancel_transaction(conn_id, did=None)
- Implement this method to cancel the running transaction. - Implement this method to cancel the running transaction.
* messages()
- Implement this method to return the list of the messages/notices from
the database server.
""" """
ASYNC_OK = 1 ASYNC_OK = 1

View File

@ -7,7 +7,11 @@
# #
########################################################################## ##########################################################################
"""Implementation of Connection, ServerManager and Driver classes""" """
Implementation of Connection, ServerManager and Driver classes using the
psycopg2. It is a wrapper around the actual psycopg2 driver, and connection
object.
"""
from datetime import datetime from datetime import datetime
@ -79,17 +83,24 @@ class Connection(BaseConnection):
- Release the connection object of psycopg2 - Release the connection object of psycopg2
* _wait(conn) * _wait(conn)
- This method is used to wait for asynchronous connection. This is a blocking call. - This method is used to wait for asynchronous connection. This is a
blocking call.
* _wait_timeout(conn, time) * _wait_timeout(conn, time)
- This method is used to wait for asynchronous connection with timeout. This is a non blocking call. - This method is used to wait for asynchronous connection with timeout.
This is a non blocking call.
* poll() * poll()
- This method is used to poll the data of query running on asynchronous connection. - This method is used to poll the data of query running on asynchronous
connection.
* cancel_transaction(conn_id, did=None) * cancel_transaction(conn_id, did=None)
- This method is used to cancel the transaction for the - This method is used to cancel the transaction for the
specified connection id and database id. specified connection id and database id.
* messages()
- Returns the list of messages/notices sends from the PostgreSQL database
server.
""" """
def __init__(self, manager, conn_id, db, auto_reconnect=True, async=0): def __init__(self, manager, conn_id, db, auto_reconnect=True, async=0):
assert(manager is not None) assert(manager is not None)
@ -781,6 +792,12 @@ Polling result for (Query-id: {query_id})""".format(query_id=self.__async_query_
return status, msg return status, msg
def messages(self):
"""
Returns the list of the messages/notices send from the database server.
"""
return self.pg_conn.notices if self.pg_conn else []
class ServerManager(object): class ServerManager(object):
""" """