close connections from get_db()
This commit is contained in:
parent
c08e7cabc0
commit
097077174b
@ -204,7 +204,9 @@ class Module(object):
|
||||
version = cur.fetchone()
|
||||
if (version != None):
|
||||
version = version[0]
|
||||
conn.close()
|
||||
except sqlite3.Error as e:
|
||||
conn.close()
|
||||
print("sqlite error:" + str(e))
|
||||
|
||||
return version
|
||||
@ -216,8 +218,10 @@ class Module(object):
|
||||
try:
|
||||
db.execute('UPDATE drbotzo_modules SET version = ? WHERE module = ?', (version, modulename))
|
||||
db.commit()
|
||||
db.close()
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
db.close()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
|
@ -51,8 +51,10 @@ class Facts(Module):
|
||||
''')
|
||||
db.execute('INSERT INTO drbotzo_modules VALUES (?,?)', (self.__class__.__name__, 1))
|
||||
db.commit()
|
||||
db.close()
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
db.close()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
@ -90,8 +92,9 @@ class Facts(Module):
|
||||
if len(facts) > 0:
|
||||
fact = facts[random.randint(1,len(facts))-1]
|
||||
return self.reply(connection, event, fact['fact'].rstrip().encode('utf-8', 'ignore'))
|
||||
|
||||
db.close()
|
||||
except sqlite3.Error as e:
|
||||
db.close()
|
||||
return self.reply(connection, event, "sqlite error: " + str(e))
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
|
@ -72,9 +72,11 @@ class Karma(Module):
|
||||
sql = 'INSERT INTO drbotzo_modules VALUES (?,?)'
|
||||
conn.execute(sql, (self.__class__.__name__, 1))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
version = 1
|
||||
except sqlite3.Error as e:
|
||||
conn.rollback()
|
||||
conn.close()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
if (version < 2):
|
||||
@ -88,9 +90,11 @@ class Karma(Module):
|
||||
sql = 'UPDATE drbotzo_modules SET version = ? WHERE module = ?'
|
||||
conn.execute(sql, (2, self.__class__.__name__))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
version = 2
|
||||
except sqlite3.Error as e:
|
||||
conn.rollback()
|
||||
conn.close()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
if (version < 3):
|
||||
@ -100,9 +104,11 @@ class Karma(Module):
|
||||
conn.execute('''
|
||||
UPDATE karma_log SET key = LOWER(key)''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
self.db_register_module_version(self.__class__.__name__, version)
|
||||
except sqlite3.Error as e:
|
||||
conn.rollback()
|
||||
conn.close()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
@ -149,8 +155,10 @@ class Karma(Module):
|
||||
'''
|
||||
conn.execute(sql, (key.decode('utf-8', 'ignore').lower(), value, nick, userhost))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except sqlite3.Error as e:
|
||||
conn.rollback()
|
||||
conn.close()
|
||||
return "sqlite error: " + str(e)
|
||||
|
||||
def handle_report_query(self, connection, nick, userhost, what):
|
||||
@ -187,8 +195,10 @@ class Karma(Module):
|
||||
result = cursor.fetchone()
|
||||
list = ', '.join(list)
|
||||
message = '{header} {list}'.format(header=header, list=list)
|
||||
conn.close()
|
||||
except sqlite3.Error as e:
|
||||
conn.rollback()
|
||||
conn.close()
|
||||
return "sqlite error: " + str(e)
|
||||
return message
|
||||
|
||||
@ -210,8 +220,9 @@ class Karma(Module):
|
||||
neg = value[1]
|
||||
total = pos+neg;
|
||||
reply = '{nick}: {statnick} has given {pos} postive karma and {neg} negative karma, for a total of {total} karma'.format(nick=nick, statnick=statnick, pos=pos, neg=neg, total=total)
|
||||
|
||||
conn.close()
|
||||
except sqlite3.Error as e:
|
||||
conn.close()
|
||||
return "sqlite error: " + str(e)
|
||||
|
||||
return reply
|
||||
@ -239,7 +250,9 @@ class Karma(Module):
|
||||
|
||||
reply = '{nick}: {key} has {value[0]!s} points of karma (rank {rank})'.format(
|
||||
nick=nick, key=key, value=value, rank=rank)
|
||||
conn.close()
|
||||
except sqlite3.Error as e:
|
||||
conn.close()
|
||||
return "sqlite error: " + str(e)
|
||||
|
||||
return reply
|
||||
|
Loading…
Reference in New Issue
Block a user