From 99487b66c6e2f7ef6feab58dc8e438875380e81a Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sat, 15 Feb 2014 18:58:12 +1300 Subject: [PATCH] further DB work --- core/main.py | 6 ++++-- plugins/tell.py | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/main.py b/core/main.py index 69d44e7..39811c0 100644 --- a/core/main.py +++ b/core/main.py @@ -64,6 +64,7 @@ def run(bot, func, input): if args: if uses_db: # create SQLAlchemy session + bot.logger.debug("Opened DB session for: {}".format(func._filename)) input.db = input.bot.db_session() if 'input' in args: input.input = input @@ -86,7 +87,7 @@ def run(bot, func, input): return finally: if uses_db: - print "Close" + bot.logger.debug("Closed DB session for: {}".format(func._filename)) input.db.close() else: try: @@ -124,6 +125,7 @@ class Handler(object): break if uses_db: + # self.bot.logger.debug("Opened ST DB session for: {}".format(self.func._filename)) input.db = input.bot.db_session() try: @@ -132,7 +134,7 @@ class Handler(object): self.bot.logger.exception("Error in plugin {}:".format(self.func._filename)) finally: if uses_db: - print "Closett" + # self.bot.logger.debug("Closed ST DB session for: {}".format(self.func._filename)) input.db.close() def stop(self): diff --git a/plugins/tell.py b/plugins/tell.py index b29cf5b..2afaac7 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -23,8 +23,8 @@ def db_init(db): def get_tells(db, user_to): return db.execute("select user_from, message, time, chan from tell where" - " user_to=lower(?) order by time", - (user_to.lower(),)).fetchall() + " user_to=lower(:user) order by time", + {'user': user_to}).fetchall() @hook.singlethread @@ -46,8 +46,8 @@ def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, con if len(tells) > 1: reply += " (+{} more, {}showtells to view)".format(len(tells) - 1, conn.conf["command_prefix"]) - db.execute("delete from tell where user_to=lower(?) and message=?", - (nick, message)) + db.execute("delete from tell where user_to=lower(:user) and message=:message", + {'user': nick, 'message': message}) db.commit() notice(reply)