Some character set improvements

The strings (names) as stored in database should always be UTF-8;
whatever the display locale is, we then need to convert from the storage
encoding to session encoding. When making database queries with players
names in them, the names must be reconverted to UTF-8.
This commit is contained in:
Mika Bostrom 2010-01-21 21:24:55 +02:00
parent e915b0b62c
commit a841603460
6 changed files with 27 additions and 10 deletions

View File

@ -48,6 +48,7 @@ import Configuration
import SQL
import Card
import Tourney
import Charset
from Exceptions import *
log = Configuration.get_logger("logging.conf")
@ -602,7 +603,8 @@ class Database:
def get_player_id(self, config, site, player_name):
c = self.connection.cursor()
c.execute(self.sql.query['get_player_id'], (player_name, site))
p_name = Charset.to_utf8(player_name)
c.execute(self.sql.query['get_player_id'], (p_name, site))
row = c.fetchone()
if row:
return row[0]
@ -615,7 +617,8 @@ class Database:
if site_id is None:
site_id = -1
c = self.get_cursor()
c.execute(self.sql.query['get_player_names'], (like_player_name, site_id, site_id))
p_name = Charset.to_utf8(like_player_name)
c.execute(self.sql.query['get_player_names'], (p_name, site_id, site_id))
rows = c.fetchall()
return rows

View File

@ -29,6 +29,7 @@ import gobject
import Configuration
import fpdb_db
import FpdbSQLQueries
import Charset
class Filters(threading.Thread):
def __init__(self, db, config, qdict, display = {}, debug=True):
@ -238,6 +239,7 @@ class Filters(threading.Thread):
print "DEBUG: %s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
def createPlayerLine(self, hbox, site, player):
print 'DEBUG :: add:"%s"' % player
label = gtk.Label(site +" id:")
hbox.pack_start(label, False, False, 0)
@ -254,13 +256,17 @@ class Filters(threading.Thread):
completion.set_model(liststore)
completion.set_text_column(0)
names = self.db.get_player_names(self.conf) # (config=self.conf, site_id=None, like_player_name="%")
for n in names:
liststore.append(n)
for n in names: # list of single-element "tuples"
_n = Charset.to_gui(n[0])
_nt = (_n, )
liststore.append(_nt)
self.__set_hero_name(pname, site)
def __set_hero_name(self, w, site):
self.heroes[site] = w.get_text()
_name = w.get_text()
_guiname = Charset.to_gui(_name)
self.heroes[site] = _guiname
# print "DEBUG: setting heroes[%s]: %s"%(site, self.heroes[site])
def __set_num_hands(self, w, val):
@ -417,7 +423,8 @@ class Filters(threading.Thread):
vbox.pack_start(hBox, False, True, 0)
player = self.conf.supported_sites[site].screen_name
self.createPlayerLine(hBox, site, player)
_pname = Charset.to_gui(player)
self.createPlayerLine(hBox, site, _pname)
if "GroupsAll" in display and display["GroupsAll"] == True:
hbox = gtk.HBox(False, 0)

View File

@ -145,7 +145,8 @@ class GuiGraphViewer (threading.Thread):
if sites[site] == True:
sitenos.append(siteids[site])
c = self.db.get_cursor()
c.execute(self.sql.query['getPlayerId'], (heroes[site],))
_hname = Charset.to_utf8(heroes[site])
c.execute(self.sql.query['getPlayerId'], (_hname,))
result = c.fetchall()
if len(result) == 1:
playerids.append( int(result[0][0]) )

View File

@ -189,7 +189,8 @@ class GuiPlayerStats (threading.Thread):
sitenos.append(siteids[site])
# Nasty hack to deal with multiple sites + same player name -Eric
que = self.sql.query['getPlayerId'] + " AND siteId=%d" % siteids[site]
self.cursor.execute(que, (heroes[site],))
_hname = Charset.to_utf8(heroes[site])
self.cursor.execute(que, (_hname,))
result = self.db.cursor.fetchall()
if len(result) == 1:
playerids.append(result[0][0])

View File

@ -47,6 +47,7 @@ import fpdb_import
import Database
import Filters
import FpdbSQLQueries
import Charset
class GuiSessionViewer (threading.Thread):
def __init__(self, config, querylist, mainwin, debug=True):
@ -181,7 +182,10 @@ class GuiSessionViewer (threading.Thread):
for site in sites:
if sites[site] == True:
sitenos.append(siteids[site])
self.cursor.execute(self.sql.query['getPlayerId'], (heroes[site],))
_q = self.sql.query['getPlayerId']
_name = Charset.to_utf8(heroes[site])
print 'DEBUG(_name) :: %s' % _name
self.cursor.execute(_q, (_name,)) # arg = tuple
result = self.db.cursor.fetchall()
if len(result) == 1:
playerids.append(result[0][0])

View File

@ -80,7 +80,8 @@ class GuiTableViewer (threading.Thread):
#then the data rows
for player in range(len(self.player_names)):
tmp=[]
tmp.append(self.player_names[player][0])
p_name = Charset.to_gui(self.player_names[player][0])
tmp.append(p_name)
seatCount=len(self.player_names)
if seatCount>=8: