From b7ca7a77a7940373fba45004382dace12544d0a5 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Mon, 6 Jul 2009 09:01:49 +0300 Subject: [PATCH] Work around error with no database Instead of blindly trusting that SELECT ... works, use try-catch to get around errors when the database doesn't have the tables yet. --- pyfpdb/Database.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 0f354054..243f9aa3 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -72,19 +72,22 @@ class Database: cur = self.connection.cursor() self.hand_1day_ago = 0 - cur.execute(self.sql.query['get_hand_1day_ago']) - row = cur.fetchone() - if row and row[0]: - self.hand_1day_ago = row[0] - #print "hand 1day ago =", self.hand_1day_ago + try: + cur.execute(self.sql.query['get_hand_1day_ago']) + row = cur.fetchone() + if row and row[0]: + self.hand_1day_ago = row[0] + #print "hand 1day ago =", self.hand_1day_ago - d = timedelta(days=self.hud_days) - now = datetime.utcnow() - d - self.date_ndays_ago = "d%02d%02d%02d" % (now.year-2000, now.month, now.day) + d = timedelta(days=self.hud_days) + now = datetime.utcnow() - d + self.date_ndays_ago = "d%02d%02d%02d" % (now.year-2000, now.month, now.day) - self.hand_nhands_ago = 0 # todo - #cur.execute(self.sql.query['get_table_name'], (hand_id, )) - #row = cur.fetchone() + self.hand_nhands_ago = 0 # todo + #cur.execute(self.sql.query['get_table_name'], (hand_id, )) + #row = cur.fetchone() + except: # no tables created yet + pass self.saveActions = False if self.import_options['saveActions'] == False else True def do_connect(self, c):