Merge branch 'master' of git://git.assembla.com/fpdboz.git

This commit is contained in:
eblade 2009-08-04 19:57:06 -04:00
commit eae278f40c
2 changed files with 10 additions and 4 deletions

View File

@ -184,6 +184,7 @@ class Database:
self.pcache = None # PlayerId cache self.pcache = None # PlayerId cache
self.cachemiss = 0 # Delete me later - using to count player cache misses self.cachemiss = 0 # Delete me later - using to count player cache misses
self.cachehit = 0 # Delete me later - using to count player cache hits
# config while trying out new hudcache mechanism # config while trying out new hudcache mechanism
self.use_date_in_hudcache = True self.use_date_in_hudcache = True
@ -976,21 +977,26 @@ class Database:
for player in pnames: for player in pnames:
result[player] = self.pcache[player] result[player] = self.pcache[player]
# NOTE: Using the LambdaDict does the same thing as:
#if player in self.pcache:
# #print "DEBUG: cachehit"
# pass
#else:
# self.pcache[player] = self.insertPlayer(player, siteid)
#result[player] = self.pcache[player]
return result return result
def insertPlayer(self, name, site_id): def insertPlayer(self, name, site_id):
self.cachemiss += 1
result = None result = None
c = self.get_cursor() c = self.get_cursor()
c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) c.execute ("SELECT id FROM Players WHERE name=%s", (name,))
tmp=c.fetchall() tmp=c.fetchall()
if (len(tmp)==0): #new player if (len(tmp)==0): #new player
c.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (name, site_id)) c.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (name, site_id))
#Get last id might be faster here.
c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) c.execute ("SELECT id FROM Players WHERE name=%s", (name,))
tmp=c.fetchall() tmp=c.fetchall()
#print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp
print "DEBUG: cache misses: %s" %self.cachemiss
return tmp[0][0] return tmp[0][0]

View File

@ -64,7 +64,7 @@ class fpdb_db:
if backend==fpdb_db.MYSQL_INNODB: if backend==fpdb_db.MYSQL_INNODB:
import MySQLdb import MySQLdb
try: try:
self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True) self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True, charset="utf8")
except: except:
raise fpdb_simple.FpdbError("MySQL connection failed") raise fpdb_simple.FpdbError("MySQL connection failed")
elif backend==fpdb_db.PGSQL: elif backend==fpdb_db.PGSQL: