From 3e49e87842b04039d323c6ef8ca0e7dc1a4508b7 Mon Sep 17 00:00:00 2001 From: Worros Date: Mon, 1 Jun 2009 20:53:42 +0800 Subject: [PATCH] Begin moving query functions into fpdb_db function No idea whether the code actually works --- pyfpdb/Hand.py | 1 + pyfpdb/fpdb_db.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index d45bae97..a51b710a 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -86,6 +86,7 @@ Should not commit, and do minimal selects. Callers may want to cache commits db: a connected fpdb_db object""" # TODO: # Players - base playerid and siteid tuple + sqlids = db.getSqlPlayerIDs([p[1] for p in self.players], self.siteId) # HudCache data to come from DerivedStats class # HandsActions - all actions for all players for all streets - self.actions # BoardCards - ? diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index b45d6cbf..51697708 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -221,4 +221,22 @@ class fpdb_db: self.db.commit() print "Finished recreating tables" #end def recreate_tables -#end class fpdb_db + + def getSqlPlayerIDs(names, site_id): + result = [] + notfound = [] + self.cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(names)) + tmp = dict(self.cursor.fetchall()) + for n in names: + if n not in tmp: + notfound.append(n) + else: + result.append(tmp[n]) + if notfound: + cursor.executemany("INSERT INTO Players (name, siteId) VALUES (%s, "+str(site_id)+")", (notfound)) + cursor.execute("SELECT id FROM Players WHERE name='%s'" % "' OR name='".join(notfound)) + tmp = cursor.fetchall() + for n in tmp: + result.append(n[0]) + + return result