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.
This commit is contained in:
Mika Bostrom 2009-07-06 09:01:49 +03:00
parent dd4aeffa4f
commit b7ca7a77a7

View File

@ -72,19 +72,22 @@ class Database:
cur = self.connection.cursor() cur = self.connection.cursor()
self.hand_1day_ago = 0 self.hand_1day_ago = 0
cur.execute(self.sql.query['get_hand_1day_ago']) try:
row = cur.fetchone() cur.execute(self.sql.query['get_hand_1day_ago'])
if row and row[0]: row = cur.fetchone()
self.hand_1day_ago = row[0] if row and row[0]:
#print "hand 1day ago =", self.hand_1day_ago self.hand_1day_ago = row[0]
#print "hand 1day ago =", self.hand_1day_ago
d = timedelta(days=self.hud_days) d = timedelta(days=self.hud_days)
now = datetime.utcnow() - d now = datetime.utcnow() - d
self.date_ndays_ago = "d%02d%02d%02d" % (now.year-2000, now.month, now.day) self.date_ndays_ago = "d%02d%02d%02d" % (now.year-2000, now.month, now.day)
self.hand_nhands_ago = 0 # todo self.hand_nhands_ago = 0 # todo
#cur.execute(self.sql.query['get_table_name'], (hand_id, )) #cur.execute(self.sql.query['get_table_name'], (hand_id, ))
#row = cur.fetchone() #row = cur.fetchone()
except: # no tables created yet
pass
self.saveActions = False if self.import_options['saveActions'] == False else True self.saveActions = False if self.import_options['saveActions'] == False else True
def do_connect(self, c): def do_connect(self, c):