From 5982df0b041cfae6438f96baf89fdf859e63a6b8 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Fri, 29 Jan 2010 22:15:09 +0000 Subject: [PATCH 1/7] add test case that made me add special test for sqlite in insertplayers - can't repeat now so removing test. Error was that a unicode type (name) was encoded to UTF-8 by Charset.to_db_utf8() and then errored when passed to sqlite. sqlite3 can handle unicode types directly so I added a test to skip the to_db_utf8() if using sqlite. Perhaps problem was caused by moving hand history between machines (but shouldn't it still work anyway?) --- regression-test/ps-lhe-unicode1.txt | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 regression-test/ps-lhe-unicode1.txt diff --git a/regression-test/ps-lhe-unicode1.txt b/regression-test/ps-lhe-unicode1.txt new file mode 100755 index 00000000..a8460e9d --- /dev/null +++ b/regression-test/ps-lhe-unicode1.txt @@ -0,0 +1,44 @@ +PokerStars Game #28817981310: Hold'em Limit ($0.25/$0.50) - 2009/05/31 4:38:53 ET +Table 'Mufrid II' 6-max Seat #1 is the button +Seat 1: AirbornMac ($16.90 in chips) +Seat 2: Im a Fishhhh ($6.25 in chips) +Seat 3: SteadyAim ($10 in chips) +Seat 4: DrickDaSlick ($6.40 in chips) +Seat 5: vik55 ($11.65 in chips) +Seat 6: Malbés ($9.55 in chips) +Im a Fishhhh: posts small blind $0.10 +SteadyAim: posts big blind $0.25 +*** HOLE CARDS *** +Dealt to SteadyAim [5s Jc] +DrickDaSlick: folds +vik55: folds +Malbés: raises $0.25 to $0.50 +AirbornMac: folds +Im a Fishhhh: calls $0.40 +SteadyAim: folds +*** FLOP *** [Ks 6c Qh] +Im a Fishhhh: checks +Malbés: bets $0.25 +Im a Fishhhh: calls $0.25 +*** TURN *** [Ks 6c Qh] [Td] +Im a Fishhhh: checks +Malbés: bets $0.50 +Im a Fishhhh: calls $0.50 +*** RIVER *** [Ks 6c Qh Td] [Kd] +Im a Fishhhh: checks +Malbés: checks +*** SHOW DOWN *** +Im a Fishhhh: shows [As 8h] (a pair of Kings) +Malbés: mucks hand +Im a Fishhhh collected $2.65 from pot +*** SUMMARY *** +Total pot $2.75 | Rake $0.10 +Board [Ks 6c Qh Td Kd] +Seat 1: AirbornMac (button) folded before Flop (didn't bet) +Seat 2: Im a Fishhhh (small blind) showed [As 8h] and won ($2.65) with a pair of Kings +Seat 3: SteadyAim (big blind) folded before Flop +Seat 4: DrickDaSlick folded before Flop (didn't bet) +Seat 5: vik55 folded before Flop (didn't bet) +Seat 6: Malbés mucked [7d Jd] + + From 2e970baa8251c3d2319f0dbb14587099b3bc035e Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Fri, 29 Jan 2010 22:29:14 +0000 Subject: [PATCH 2/7] remove sqlite specific test to skip unicode encoding --- pyfpdb/Database.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index a8456294..b0a49112 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1769,10 +1769,7 @@ class Database: def insertPlayer(self, name, site_id): result = None - if self.backend == self.SQLITE: - _name = name - else: - _name = Charset.to_db_utf8(name) + _name = Charset.to_db_utf8(name) c = self.get_cursor() q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s" q = q.replace('%s', self.sql.query['placeholder']) From a7d4c6243ab0b660e859827e8663425473fa3c71 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Fri, 29 Jan 2010 23:29:37 +0000 Subject: [PATCH 3/7] add assignment (but commented out) that fixes unicode probs for me with sqlite --- pyfpdb/Database.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index b0a49112..bf6c04af 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -399,6 +399,11 @@ class Database: self.cursor = self.connection.cursor() self.cursor.execute('PRAGMA temp_store=2') # use memory for temp tables/indexes self.cursor.execute('PRAGMA synchronous=0') # don't wait for file writes to finish + + # sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252) + # feel free to remove or improve this if you understand the problems + # better than me (not hard!) + # Charset.not_needed = True else: raise FpdbError("unrecognised database backend:"+backend) From d147187a712c64632928d53cd2cfd78172401be0 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Fri, 29 Jan 2010 23:36:39 +0000 Subject: [PATCH 4/7] add extra comment/suggestion --- pyfpdb/Database.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index bf6c04af..0b6cac8e 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -403,6 +403,8 @@ class Database: # sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252) # feel free to remove or improve this if you understand the problems # better than me (not hard!) + # I think maybe we need a separate "not_needed" flag for each of the routines + # in Charset.py??? # Charset.not_needed = True else: raise FpdbError("unrecognised database backend:"+backend) From 9932025271d7f6ba25d9c7bf8aa80097ef17b07d Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 30 Jan 2010 11:05:34 +0000 Subject: [PATCH 5/7] move sqlite charset fix to Configuration.py from Database.py, make separate not_needed variables in Charset.py in case we want to update them separately --- pyfpdb/Charset.py | 10 +++++----- pyfpdb/Configuration.py | 10 ++++++++++ pyfpdb/Database.py | 11 ++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index d49b6219..6b5e6b7c 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -28,12 +28,12 @@ encoder_to_utf = codecs.lookup('utf-8') encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING) # I'm saving a few cycles with this one -not_needed = False +not_needed1, not_needed2, not_needed3 = False, False, False if Configuration.LOCALE_ENCODING == 'UTF8': - not_needed = True + not_needed1, not_needed2, not_needed3 = True, True, True def to_utf8(s): - if not_needed: return s + if not_needed1: return s try: #(_out, _len) = encoder_to_utf.encode(s) @@ -44,7 +44,7 @@ def to_utf8(s): raise def to_db_utf8(s): - if not_needed: return s + if not_needed2: return s try: (_out, _len) = encoder_to_utf.encode(unicode(s)) @@ -54,7 +54,7 @@ def to_db_utf8(s): raise def to_gui(s): - if not_needed: return s + if not_needed3: return s try: (_out, _len) = encoder_to_sys.encode(s) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 9c14d16f..9e90a5bb 100644 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -144,6 +144,11 @@ if LOCALE_ENCODING == "US-ASCII": print "Default encoding set to US-ASCII, defaulting to CP1252 instead -- If you're not on a Mac, please report this problem." LOCALE_ENCODING = "cp1252" + +# needs LOCALE_ENCODING (above), imported for sqlite setup in Config class below +import Charset + + ######################################################################## def string_to_bool(string, default=True): """converts a string representation of a boolean value to boolean True or False @@ -648,6 +653,11 @@ class Config: db['db-backend'] = 3 elif self.supported_databases[name].db_server== DATABASE_TYPE_SQLITE: db['db-backend'] = 4 + + # sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252) + # feel free to remove or improve this if you understand the problems + # better than me (not hard!) + #Charset.not_needed1, Charset.not_needed2, Charset.not_needed3 = True, True, True else: raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server) return db diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 0b6cac8e..754af54a 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -372,7 +372,6 @@ class Database: print msg raise FpdbError(msg) elif backend == Database.SQLITE: - log.info("Connecting to SQLite: %(database)s" % {'database':database}) import sqlite3 if use_pool: sqlite3 = pool.manage(sqlite3, pool_size=1) @@ -385,7 +384,8 @@ class Database: log.info("Creating directory: '%s'" % (self.config.dir_databases)) os.mkdir(self.config.dir_databases) database = os.path.join(self.config.dir_databases, database) - log.info(" sqlite db: " + database) + log.info("Connecting to SQLite: %(database)s" % {'database':database}) + print "Connecting to SQLite: %(database)s" % {'database':database} self.connection = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES ) sqlite3.register_converter("bool", lambda x: bool(int(x))) sqlite3.register_adapter(bool, lambda x: "1" if x else "0") @@ -399,13 +399,6 @@ class Database: self.cursor = self.connection.cursor() self.cursor.execute('PRAGMA temp_store=2') # use memory for temp tables/indexes self.cursor.execute('PRAGMA synchronous=0') # don't wait for file writes to finish - - # sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252) - # feel free to remove or improve this if you understand the problems - # better than me (not hard!) - # I think maybe we need a separate "not_needed" flag for each of the routines - # in Charset.py??? - # Charset.not_needed = True else: raise FpdbError("unrecognised database backend:"+backend) From e0c5f52d0f002114c0922994201906ecd99c8dc6 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 30 Jan 2010 11:11:21 +0000 Subject: [PATCH 6/7] uncommented sqlite unicode fix (fix only tested on Windows XP, cp1252) --- pyfpdb/Configuration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 9e90a5bb..639007f1 100644 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -653,11 +653,10 @@ class Config: db['db-backend'] = 3 elif self.supported_databases[name].db_server== DATABASE_TYPE_SQLITE: db['db-backend'] = 4 - # sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252) # feel free to remove or improve this if you understand the problems # better than me (not hard!) - #Charset.not_needed1, Charset.not_needed2, Charset.not_needed3 = True, True, True + Charset.not_needed1, Charset.not_needed2, Charset.not_needed3 = True, True, True else: raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server) return db From e61fb7677c65c04ba1276852a1e446edd07c301b Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 30 Jan 2010 11:18:10 +0000 Subject: [PATCH 7/7] remove unicode test file as error seems to have gone away --- regression-test/ps-lhe-unicode1.txt | 44 ----------------------------- 1 file changed, 44 deletions(-) delete mode 100755 regression-test/ps-lhe-unicode1.txt diff --git a/regression-test/ps-lhe-unicode1.txt b/regression-test/ps-lhe-unicode1.txt deleted file mode 100755 index a8460e9d..00000000 --- a/regression-test/ps-lhe-unicode1.txt +++ /dev/null @@ -1,44 +0,0 @@ -PokerStars Game #28817981310: Hold'em Limit ($0.25/$0.50) - 2009/05/31 4:38:53 ET -Table 'Mufrid II' 6-max Seat #1 is the button -Seat 1: AirbornMac ($16.90 in chips) -Seat 2: Im a Fishhhh ($6.25 in chips) -Seat 3: SteadyAim ($10 in chips) -Seat 4: DrickDaSlick ($6.40 in chips) -Seat 5: vik55 ($11.65 in chips) -Seat 6: Malbés ($9.55 in chips) -Im a Fishhhh: posts small blind $0.10 -SteadyAim: posts big blind $0.25 -*** HOLE CARDS *** -Dealt to SteadyAim [5s Jc] -DrickDaSlick: folds -vik55: folds -Malbés: raises $0.25 to $0.50 -AirbornMac: folds -Im a Fishhhh: calls $0.40 -SteadyAim: folds -*** FLOP *** [Ks 6c Qh] -Im a Fishhhh: checks -Malbés: bets $0.25 -Im a Fishhhh: calls $0.25 -*** TURN *** [Ks 6c Qh] [Td] -Im a Fishhhh: checks -Malbés: bets $0.50 -Im a Fishhhh: calls $0.50 -*** RIVER *** [Ks 6c Qh Td] [Kd] -Im a Fishhhh: checks -Malbés: checks -*** SHOW DOWN *** -Im a Fishhhh: shows [As 8h] (a pair of Kings) -Malbés: mucks hand -Im a Fishhhh collected $2.65 from pot -*** SUMMARY *** -Total pot $2.75 | Rake $0.10 -Board [Ks 6c Qh Td Kd] -Seat 1: AirbornMac (button) folded before Flop (didn't bet) -Seat 2: Im a Fishhhh (small blind) showed [As 8h] and won ($2.65) with a pair of Kings -Seat 3: SteadyAim (big blind) folded before Flop -Seat 4: DrickDaSlick folded before Flop (didn't bet) -Seat 5: vik55 folded before Flop (didn't bet) -Seat 6: Malbés mucked [7d Jd] - -