public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][psycopg2] - Modified status message implementation
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][psycopg2] - Modified status message implementation
@ 2016-04-04 11:23 Neel Patel <[email protected]>
  2016-04-05 08:00 ` Re: [pgAdmin4][psycopg2] - Modified status message implementation Ashesh Vashi <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Neel Patel @ 2016-04-04 11:23 UTC (permalink / raw)
  To: pgadmin-hackers

Hi,

Please find attached patch file which modified the earlier statusmessage
implementation.

*Previous implementation:- *

statusmessage was implemented inside the poll function and if poll result
row is greater than zero then statusmessage was replaced by the result row
returned so if user wants the statusmessage along with returned rows then
current implementation will not work.

*Changes:-*

Now "status_message()" function is implemented to get the status message
returned by last command executed on the server and removed from the poll
function.
If user wants to status messages then they have to call "status_message()"
which will return the status message text.

Do review it and let us know for any comments.

Thanks,
Neel Patel


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] psycopg2_status_message.patch (3.6K, 3-psycopg2_status_message.patch)
  download | inline diff:
diff --git a/web/pgadmin/utils/driver/abstract.py b/web/pgadmin/utils/driver/abstract.py
index 5369251..e068ca4 100644
--- a/web/pgadmin/utils/driver/abstract.py
+++ b/web/pgadmin/utils/driver/abstract.py
@@ -206,5 +206,9 @@ class BaseConnection(object):
         pass
 
     @abstractmethod
+    def status_message(self):
+        pass
+
+    @abstractmethod
     def cancel_transaction(self, conn_id, did=None):
         pass
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py
index 7330a28..8496379 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -95,6 +95,9 @@ class Connection(BaseConnection):
       - This method is used to poll the data of query running on asynchronous
         connection.
 
+    * status_message()
+      - Returns the status message returned by the last command executed on the server.
+
     * cancel_transaction(conn_id, did=None)
       - This method is used to cancel the transaction for the
         specified connection id and database id.
@@ -464,6 +467,7 @@ Attempt to reconnect it failed with the below error:
             params: extra parameters to the function
             formatted_exception_msg: if True then function return the formatted exception message
         """
+        self.__async_cursor = None
         status, cur = self.__cursor()
 
         if not status:
@@ -767,7 +771,7 @@ Failed to reset the connection of the server due to following error:
         cur = self.__async_cursor
         if not cur:
             return False, gettext(
-                "Cursor could not be found for the aysnc connection."
+                "Cursor could not be found for the async connection."
                 ), None
 
         current_app.logger.log(
@@ -784,19 +788,19 @@ Failed to reset the connection of the server due to following error:
             return False, errmsg, None
 
         colinfo = None
+        result = None
         if status == self.ASYNC_OK:
 
             # if user has cancelled the transaction then changed the status
             if self.execution_aborted:
                 status = self.ASYNC_EXECUTION_ABORTED
                 self.execution_aborted = False
-                return status, None, colinfo
+                return status, result, colinfo
 
             # Fetch the column information
             if cur.description is not None:
                 colinfo = [desc for desc in cur.description]
 
-            result = cur.statusmessage
             if cur.rowcount > 0:
                 result = []
 
@@ -809,12 +813,26 @@ Failed to reset the connection of the server due to following error:
                     for row in cur:
                         result.append(dict(row))
                 except psycopg2.ProgrammingError:
-                    result = cur.statusmessage
+                    result = None
 
-            self.__async_cursor = None
-            return status, result, colinfo
+        return status, result, colinfo
+
+    def status_message(self):
+        """
+        This function will return the status message returned by the last command executed on the server.
+        """
+        cur = self.__async_cursor
+        if not cur:
+            return gettext("Cursor could not be found for the async connection.")
+
+        current_app.logger.log(
+            25,
+            "Status message for (Query-id: {query_id})".format(
+                query_id=self.__async_query_id
+                )
+            )
 
-        return status, None, colinfo
+        return cur.statusmessage
 
     def cancel_transaction(self, conn_id, did=None):
         """


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin4][psycopg2] - Modified status message implementation
  2016-04-04 11:23 [pgAdmin4][psycopg2] - Modified status message implementation Neel Patel <[email protected]>
@ 2016-04-05 08:00 ` Ashesh Vashi <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Ashesh Vashi @ 2016-04-05 08:00 UTC (permalink / raw)
  To: Neel Patel <[email protected]>; +Cc: pgadmin-hackers

On Mon, Apr 4, 2016 at 4:53 PM, Neel Patel <[email protected]>
wrote:

> Hi,
>
> Please find attached patch file which modified the earlier statusmessage
> implementation.
>
> *Previous implementation:- *
>
> statusmessage was implemented inside the poll function and if poll result
> row is greater than zero then statusmessage was replaced by the result row
> returned so if user wants the statusmessage along with returned rows then
> current implementation will not work.
>
> *Changes:-*
>
> Now "status_message()" function is implemented to get the status message
> returned by last command executed on the server and removed from the poll
> function.
> If user wants to status messages then they have to call "status_message()"
> which will return the status message text.
>
> Do review it and let us know for any comments.
>
Thanks - committed!

We still need to make it work with the synchronous connection.

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company
<http://www.enterprisedb.com/;


*http://www.linkedin.com/in/asheshvashi*
<http://www.linkedin.com/in/asheshvashi;

>
> Thanks,
> Neel Patel
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>
>


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-04-05 08:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-04-04 11:23 [pgAdmin4][psycopg2] - Modified status message implementation Neel Patel <[email protected]>
2016-04-05 08:00 ` Ashesh Vashi <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox