From 5139b8853888bcaefd7c080abe37228fa139ab66 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 28 Mar 2009 20:32:30 +0900 Subject: [PATCH 1/3] utf8 fix to db connection Change mysql connection type to use_unicode. --- pyfpdb/fpdb_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 771b79fa..eba87f52 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -59,7 +59,7 @@ class fpdb_db: self.database=database if backend==self.MYSQL_INNODB: import MySQLdb - self.db=MySQLdb.connect(host = host, user = user, passwd = password, db = database) + self.db=MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True) elif backend==self.PGSQL: import psycopg2 # If DB connection is made over TCP, then the variables From ae2835cd6b382fa97079f5b2d96b8d1cfc238087 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 28 Mar 2009 19:38:37 +0900 Subject: [PATCH 2/3] GuiBulkImport cli breakage fix --- pyfpdb/GuiBulkImport.py | 2 +- pyfpdb/fpdb_import.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index 1a62a37d..e7964511 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -238,7 +238,7 @@ def main(argv=None): if os.name == 'nt': settings['os'] = 'windows' else: settings['os'] = 'linuxmac' - settings.update(config.get_db_parameters('fpdb')) + settings.update(config.get_db_parameters()) settings.update(config.get_tv_parameters()) settings.update(config.get_import_parameters()) settings.update(config.get_default_paths()) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index fc98a049..6c0af7f5 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -21,7 +21,7 @@ import os # todo: remove this once import_dir is in fpdb_import import sys -from time import time +from time import time, strftime import traceback import math import datetime From 0528aa74dbc131f0dd69098e51ee79f062f7c1df Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 29 Mar 2009 00:07:00 +0900 Subject: [PATCH 3/3] Properly escape player names --- pyfpdb/fpdb_simple.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 2c432c75..c690a5c8 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1393,13 +1393,15 @@ def recogniseTourneyTypeId(cursor, siteId, buyin, fee, knockout, rebuyOrAddon): # then this can be reduced in complexity a bit 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 + q = "SELECT name,id FROM Players WHERE name=%s" % " OR name=".join(["%s" for n in names]) + cursor.execute(q, 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 + q2 = "SELECT name,id FROM Players WHERE name=%s" % " OR name=".join(["%s" for n in notfound]) + cursor.execute(q2, notfound) # get their new ids tmp = dict(cursor.fetchall()) for n in tmp: # put them all into the same dict ids[n] = tmp[n]