From dbac1ee9f7a6d7bf0f066d87d1ac493431316517 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Tue, 22 Mar 2016 17:17:45 +0100 Subject: [PATCH] sqlExecute now returns rowcount This allows tracking of how many rows were changed, for example for UPDATE, DELETE, INSERT. --- src/class_sqlThread.py | 4 +++- src/helper_sql.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 0c28bc22..c0b74794 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -546,10 +546,12 @@ class sqlThread(threading.Thread): return else: parameters = shared.sqlSubmitQueue.get() + rowcount = 0 # print 'item', item # print 'parameters', parameters try: self.cur.execute(item, parameters) + rowcount = self.cur.rowcount except Exception as err: if str(err) == 'database or disk is full': logger.fatal('(while cur.execute) Alert: Your disk or data storage volume is full. sqlThread will now exit.') @@ -564,5 +566,5 @@ class sqlThread(threading.Thread): os._exit(0) - shared.sqlReturnQueue.put(self.cur.fetchall()) + shared.sqlReturnQueue.put((self.cur.fetchall(), rowcount)) # shared.sqlSubmitQueue.task_done() diff --git a/src/helper_sql.py b/src/helper_sql.py index c50db192..d27401cf 100644 --- a/src/helper_sql.py +++ b/src/helper_sql.py @@ -16,7 +16,7 @@ def sqlQuery(sqlStatement, *args): else: sqlSubmitQueue.put(args) - queryreturn = sqlReturnQueue.get() + queryreturn, rowcount = sqlReturnQueue.get() sqlLock.release() return queryreturn @@ -30,9 +30,10 @@ def sqlExecute(sqlStatement, *args): else: sqlSubmitQueue.put(args) - sqlReturnQueue.get() + queryreturn, rowcount = sqlReturnQueue.get() sqlSubmitQueue.put('commit') sqlLock.release() + return rowcount def sqlStoredProcedure(procName): sqlLock.acquire()