somehow a call to get_cursor() got turned into just a db pass .. and removed the debug code in recogniseplayerids

This commit is contained in:
eblade 2009-08-07 17:18:51 -04:00
parent 43b41e88f4
commit 4445881bfe
2 changed files with 1 additions and 10 deletions

View File

@ -93,7 +93,7 @@ def mainParser(settings, siteID, category, hand, config, db = None, writeq = Non
seatLines.append(line)
names = fpdb_simple.parseNames(seatLines)
playerIDs = fpdb_simple.recognisePlayerIDs(db, names, siteID) # inserts players as needed
playerIDs = fpdb_simple.recognisePlayerIDs(db.get_cursor(), names, siteID) # inserts players as needed
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines)
startCashes = tmp['startCashes']
seatNos = tmp['seatNos']

View File

@ -985,28 +985,19 @@ def recogniseTourneyTypeId(cursor, siteId, buyin, fee, knockout, rebuyOrAddon):
# return result
def recognisePlayerIDs(cursor, names, site_id):
# print "\nrecognisePlayerIDs names=",len(names),names
q = "SELECT name,id FROM Players WHERE siteid=%d and (name=%s)" % (site_id, " OR name=".join(["%s" for n in names]))
# print "q=",q
cursor.execute(q, names) # get all playerids by the names passed in
ids = dict(cursor.fetchall()) # convert to dict
# print "ids(1)=",len(ids),ids
if len(ids) != len(names):
notfound = [n for n in names if n not in ids] # make list of names not in database
# print "notfound=", notfound
if notfound: # insert them into database
cursor.executemany("INSERT INTO Players (name, siteId) VALUES (%s, "+str(site_id)+")", [(n,) for n in notfound])
q2 = "SELECT name,id FROM Players WHERE siteid=%d and (name=%s)" % (site_id, " OR name=".join(["%s" for n in notfound]))
cursor.execute(q2, notfound) # get their new ids
tmp = cursor.fetchall()
# print "tmp=", tmp
for n,id in tmp: # put them all into the same dict
ids[n] = id
# return them in the SAME ORDER that they came in in the names argument, rather than the order they came out of the DB
# print "ids=",ids
# list = [ids[n] for n in names]
# print "list=",list
# print "\n"
return [ids[n] for n in names]
#end def recognisePlayerIDs