Revert Eric's change that failed on special chars in player name.

Should be able to get the new player id from connction.insert_id().
This commit is contained in:
Ray 2009-03-27 13:21:33 -04:00
parent 503262d398
commit c8d80eef19

View File

@ -1393,19 +1393,33 @@ def recogniseTourneyTypeId(cursor, siteId, buyin, fee, knockout, rebuyOrAddon):
# then this can be reduced in complexity a bit # then this can be reduced in complexity a bit
def recognisePlayerIDs(cursor, names, site_id): def recognisePlayerIDs(cursor, names, site_id):
cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(names)) # get all playerids by the names passed in result = []
ids = dict(cursor.fetchall()) # convert to dict for i in xrange(len(names)):
if len(ids) != len(names): cursor.execute ("SELECT id FROM Players WHERE name=%s", (names[i],))
notfound = [n for n in names if n not in ids] # make list of names not in database tmp=cursor.fetchall()
if notfound: # insert them into database if (len(tmp)==0): #new player
cursor.executemany("INSERT INTO Players (name, siteId) VALUES (%s, "+str(site_id)+")", (notfound)) cursor.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (names[i], site_id))
cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(notfound)) # get their new ids #print "Number of players rows inserted: %d" % cursor.rowcount
tmp = dict(cursor.fetchall()) cursor.execute ("SELECT id FROM Players WHERE name=%s", (names[i],))
for n in tmp: # put them all into the same dict tmp=cursor.fetchall()
ids[n] = tmp[n] #print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp
result.append(tmp[0][0])
# return them in the SAME ORDER that they came in in the names argument, rather than the order they came out of the DB return result
return [ids[n] for n in names]
#def recognisePlayerIDs(cursor, names, site_id):
# cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(names)) # get all playerids by the names passed in
# ids = dict(cursor.fetchall()) # convert to dict
# if len(ids) != len(names):
# notfound = [n for n in names if n not in ids] # make list of names not in database
# if notfound: # insert them into database
# cursor.executemany("INSERT INTO Players (name, siteId) VALUES (%s, "+str(site_id)+")", (notfound))
# cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(notfound)) # get their new ids
# tmp = dict(cursor.fetchall())
# for n in tmp: # put them all into the same dict
# ids[n] = tmp[n]
#
# # return them in the SAME ORDER that they came in in the names argument, rather than the order they came out of the DB
# return [ids[n] for n in names]
#end def recognisePlayerIDs #end def recognisePlayerIDs