public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch] Add affected row count support in psycopg2
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][Patch] Add affected row count support in psycopg2
@ 2016-04-12 10:24 Akshay Joshi <[email protected]>
  2016-04-12 16:04 ` Re: [pgAdmin4][Patch] Add affected row count support in psycopg2 Dave Page <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Akshay Joshi @ 2016-04-12 10:24 UTC (permalink / raw)
  To: pgadmin-hackers

Hi All

While implementing Query Tool, we need the affected row count for the
queries (DELETE, SELECT, UPDATE etc..) executed on the database server. I
have implemented the same. Attached is the patch file, please review it and
let me know the review comments if any.


-- 
*Akshay Joshi*
*Principal Software Engineer *



*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*


-- 
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_rows_affected.patch (4.8K, 3-Psycopg2_rows_affected.patch)
  download | inline diff:
diff --git a/web/pgadmin/utils/driver/abstract.py b/web/pgadmin/utils/driver/abstract.py
index e068ca4..2ddc7dd 100644
--- a/web/pgadmin/utils/driver/abstract.py
+++ b/web/pgadmin/utils/driver/abstract.py
@@ -141,6 +141,10 @@ class BaseConnection(object):
     * messages()
       - Implement this method to return the list of the messages/notices from
         the database server.
+
+    * rows_affected()
+      - Implement this method to get the rows affected by the last command
+        executed on the server.
     """
 
     ASYNC_OK = 1
@@ -210,5 +214,9 @@ class BaseConnection(object):
         pass
 
     @abstractmethod
+    def rows_affected(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 8496379..63869e3 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -98,6 +98,9 @@ class Connection(BaseConnection):
     * status_message()
       - Returns the status message returned by the last command executed on the server.
 
+    * rows_affected()
+      - Returns the no of rows affected 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.
@@ -126,6 +129,7 @@ class Connection(BaseConnection):
         self.__async_query_id = None
         self.__backend_pid = None
         self.execution_aborted = False
+        self.row_count = 0
 
         super(Connection, self).__init__()
 
@@ -422,6 +426,7 @@ Attempt to reconnect it failed with the below error:
 
     def execute_scalar(self, query, params=None, formatted_exception_msg=False):
         status, cur = self.__cursor()
+        self.row_count = 0
 
         if not status:
             return False, str(cur)
@@ -451,6 +456,7 @@ Attempt to reconnect it failed with the below error:
                     )
             return False, errmsg
 
+        self.row_count = cur.rowcount
         if cur.rowcount > 0:
             res = cur.fetchone()
             if len(res) > 0:
@@ -518,6 +524,7 @@ Failed to execute query (execute_async) for the server #{server_id} - {conn_id}
             formatted_exception_msg: if True then function return the formatted exception message
         """
         status, cur = self.__cursor()
+        self.row_count = 0
 
         if not status:
             return False, str(cur)
@@ -551,10 +558,13 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
             )
             return False, errmsg
 
+        self.row_count = cur.rowcount
+
         return True, None
 
     def execute_2darray(self, query, params=None, formatted_exception_msg=False):
         status, cur = self.__cursor()
+        self.row_count = 0
 
         if not status:
             return False, str(cur)
@@ -591,6 +601,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
                 ] or []
 
         rows = []
+        self.row_count = cur.rowcount
         if cur.rowcount > 0:
             for row in cur:
                 rows.append(row)
@@ -599,6 +610,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
 
     def execute_dict(self, query, params=None, formatted_exception_msg=False):
         status, cur = self.__cursor()
+        self.row_count = 0
 
         if not status:
             return False, str(cur)
@@ -633,6 +645,7 @@ Failed to execute query (execute_void) for the server #{server_id} - {conn_id}
                 ] or []
 
         rows = []
+        self.row_count = cur.rowcount
         if cur.rowcount > 0:
             for row in cur:
                 rows.append(dict(row))
@@ -789,6 +802,7 @@ Failed to reset the connection of the server due to following error:
 
         colinfo = None
         result = None
+        self.row_count = 0
         if status == self.ASYNC_OK:
 
             # if user has cancelled the transaction then changed the status
@@ -801,6 +815,7 @@ Failed to reset the connection of the server due to following error:
             if cur.description is not None:
                 colinfo = [desc for desc in cur.description]
 
+            self.row_count = cur.rowcount
             if cur.rowcount > 0:
                 result = []
 
@@ -834,6 +849,14 @@ Failed to reset the connection of the server due to following error:
 
         return cur.statusmessage
 
+    def rows_affected(self):
+        """
+        This function will return the no of rows affected by the last command
+        executed on the server.
+        """
+
+        return self.row_count
+
     def cancel_transaction(self, conn_id, did=None):
         """
         This function is used to cancel the running transaction


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

* Re: [pgAdmin4][Patch] Add affected row count support in psycopg2
  2016-04-12 10:24 [pgAdmin4][Patch] Add affected row count support in psycopg2 Akshay Joshi <[email protected]>
@ 2016-04-12 16:04 ` Dave Page <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2016-04-12 16:04 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied.

On Tue, Apr 12, 2016 at 11:24 AM, Akshay Joshi <
[email protected]> wrote:

> Hi All
>
> While implementing Query Tool, we need the affected row count for the
> queries (DELETE, SELECT, UPDATE etc..) executed on the database server. I
> have implemented the same. Attached is the patch file, please review it and
> let me know the review comments if any.
>
>
> --
> *Akshay Joshi*
> *Principal Software Engineer *
>
>
>
> *Phone: +91 20-3058-9517 <%2B91%2020-3058-9517>Mobile: +91 976-788-8246*
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


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


end of thread, other threads:[~2016-04-12 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-04-12 10:24 [pgAdmin4][Patch] Add affected row count support in psycopg2 Akshay Joshi <[email protected]>
2016-04-12 16:04 ` Dave Page <[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