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