Skip to content

Commit

Permalink
release DB cursor before emitting signals
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Nov 17, 2018
1 parent b9e9e8e commit 3b29d4b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 17 additions & 8 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,23 @@ def initTable_RPC(self, cursor):
General methods
'''
def clearTable(self, table_name):
cleared_RPC = False
try:
cursor = self.getCursor()
cursor.execute("DELETE FROM %s" % table_name)
# in case, reload default RPC and emit changed signal
if table_name == 'CUSTOM_RPC_SERVERS':
self.initTable_RPC(cursor)
self.app.sig_changed_rpcServers.emit()
cleared_RPC = True

except Exception as e:
err_msg = 'error clearing %s in database' % table_name
printException(getCallerName(), getFunctionName(), err_msg, e.args)

finally:
self.releaseCursor()
if cleared_RPC:
self.app.sig_changed_rpcServers.emit()



Expand All @@ -211,26 +214,29 @@ def clearTable(self, table_name):
RPC servers methods
'''
def addRPCServer(self, protocol, host, user, passwd):
added_RPC = False
try:
cursor = self.getCursor()

cursor.execute("INSERT INTO CUSTOM_RPC_SERVERS (protocol, host, user, pass) "
"VALUES (?, ?, ?, ?)",
(protocol, host, user, passwd)
)

self.app.sig_changed_rpcServers.emit()
added_RPC = True

except Exception as e:
err_msg = 'error adding RPC server entry to DB'
printException(getCallerName(), getFunctionName(), err_msg, e.args)
finally:
self.releaseCursor()
if added_RPC:
self.app.sig_changed_rpcServers.emit()




def editRPCServer(self, protocol, host, user, passwd, id):
changed_RPC = False
try:
cursor = self.getCursor()

Expand All @@ -239,14 +245,15 @@ def editRPCServer(self, protocol, host, user, passwd, id):
"WHERE id = ?",
(protocol, host, user, passwd, id)
)

self.app.sig_changed_rpcServers.emit()
changed_RPC = True

except Exception as e:
err_msg = 'error editing RPC server entry to DB'
printException(getCallerName(), getFunctionName(), err_msg, e.args)
finally:
self.releaseCursor()
self.releaseCursor()
if changed_RPC:
self.app.sig_changed_rpcServers.emit()



Expand Down Expand Up @@ -287,19 +294,21 @@ def getRPCServers(self, custom, id=None):


def removeRPCServer(self, index):
removed_RPC = False
try:
cursor = self.getCursor()
cursor.execute("DELETE FROM RPC_SERVERS"
" WHERE id=?", (index,))

self.app.sig_changed_rpcServers.emit()
removed_RPC = True

except Exception as e:
err_msg = 'error removing RPC servers from database'
printException(getCallerName(), getFunctionName(), err_msg, e.args)

finally:
self.releaseCursor()
if removed_RPC:
self.app.sig_changed_rpcServers.emit()



Expand Down
4 changes: 2 additions & 2 deletions src/version.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"number": "0.3.99",
"tag": "n",
"comments": ["update specfile"]
"tag": "o",
"comments": ["DB signals fix"]
}

0 comments on commit 3b29d4b

Please sign in to comment.