Hand.select(): Minor update

- Fix query after schema change.
- Convert code attempting to use row_factory to a slower equivalent
This commit is contained in:
Worros 2011-03-01 16:13:58 +08:00
parent f85cbef28b
commit 302af8eae9

View File

@ -359,11 +359,17 @@ db: a connected Database object"""
# NOTE: This relies on row_factory = sqlite3.Row (set in connect() params) # NOTE: This relies on row_factory = sqlite3.Row (set in connect() params)
# Need to find MySQL and Postgres equivalents # Need to find MySQL and Postgres equivalents
# MySQL maybe: cursorclass=MySQLdb.cursors.DictCursor # MySQL maybe: cursorclass=MySQLdb.cursors.DictCursor
res = c.fetchone() #res = c.fetchone()
# Using row_factory is global, and affects the rest of fpdb. The following 2 line achieves
# a similar result
res = [dict(line) for line in [zip([ column[0] for column in c.description], row) for row in c.fetchall()]]
res = res[0]
#res['tourneyId'] #res['seats'] #res['rush'] #res['tourneyId'] #res['seats'] #res['rush']
self.tablename = res['tableName'] self.tablename = res['tableName']
self.handid = res['siteHandNo'] self.handid = res['siteHandNo']
#print "DBEUG: res['startTime']: %s" % res['startTime']
self.startTime = datetime.datetime.strptime(res['startTime'], "%Y-%m-%d %H:%M:%S+00:00") self.startTime = datetime.datetime.strptime(res['startTime'], "%Y-%m-%d %H:%M:%S+00:00")
self.maxseats = res['maxSeats'] self.maxseats = res['maxSeats']
@ -396,16 +402,19 @@ db: a connected Database object"""
Players as p, Players as p,
Hands as h Hands as h
WHERE WHERE
h.id = %s h.id = %s
and ha.handsPlayerId = hp.id AND ha.handId = h.id
and hp.playerId = p.id AND ha.playerId = hp.playerid
AND hp.playerId = p.id
AND h.id = hp.handId AND h.id = hp.handId
ORDER BY ORDER BY
ha.id ASC ha.id ASC
; """ """
q = q.replace('%s', db.sql.query['placeholder']) q = q.replace('%s', db.sql.query['placeholder'])
c.execute(q, (handId,)) c.execute(q, (handId,))
for row in c.fetchall(): res = [dict(line) for line in [zip([ column[0] for column in c.description], row) for row in c.fetchall()]]
for row in res:
name = row['name'] name = row['name']
street = row['street'] street = row['street']
act = row['actionId'] act = row['actionId']
@ -414,7 +423,6 @@ db: a connected Database object"""
street = self.allStreets[int(street)+1] street = self.allStreets[int(street)+1]
#print "DEBUG: name: '%s' street: '%s' act: '%s' bet: '%s'" %(name, street, act, bet) #print "DEBUG: name: '%s' street: '%s' act: '%s' bet: '%s'" %(name, street, act, bet)
if act == 2: # Small Blind if act == 2: # Small Blind
print "DEBUG: addBlind(%s, 'small blind', %s" %(name, str(bet))
self.addBlind(name, 'small blind', str(bet)) self.addBlind(name, 'small blind', str(bet))
elif act == 4: # Big Blind elif act == 4: # Big Blind
self.addBlind(name, 'big blind', str(bet)) self.addBlind(name, 'big blind', str(bet))
@ -426,6 +434,8 @@ db: a connected Database object"""
self.addFold(street, name) self.addFold(street, name)
elif act == 11: # Check elif act == 11: # Check
self.addCheck(street, name) self.addCheck(street, name)
elif act == 7: # Raise
self.addRaiseBy(street, name, str(bet))
else: else:
print "DEBUG: unknown action: '%s'" % act print "DEBUG: unknown action: '%s'" % act