dabo Commit
Revision 5100
Date: 2009-03-01 18:39:25 -0800 (Sun, 01 Mar 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5100
Changed:
U trunk/dabo/db/dbMySQL.py
Log:
MySQLdb by default assumes latin-1 is the encoding. This change tries to get
the encoding from the database description, if it's available.
Diff:
Modified: trunk/dabo/db/dbMySQL.py
===================================================================
--- trunk/dabo/db/dbMySQL.py 2009-03-02 02:38:18 UTC (rev 5099)
+++ trunk/dabo/db/dbMySQL.py 2009-03-02 02:39:25 UTC (rev 5100)
@@ -39,11 +39,33 @@
conversions[decimal.Decimal] = dec2str
kwargs["conv"] = conversions
+
+ # Determine default charset
+ charset = None
+ db = connectInfo.Database
+ if db:
+ try:
+ cn = dbapi.connect(host=connectInfo.Host,
user=connectInfo.User,
+ passwd=connectInfo.revealPW(),
port=port)
+ crs = cn.cursor()
+ # Params don't work here; need direct string to
execute
+ crs.execute("show create database %s" % (db, ))
+ charset = crs.fetchone()[1].split("DEFAULT
CHARACTER SET")[1].split()[0]
+ self.Encoding = charset
+ except IndexError:
+ pass
+ if charset is None:
+ # Use the app encoding
+ try:
+ charset = self.Application.Encoding
+ except AttributeError:
+ charset = dabo.defaultEncoding
+ charset = charset.lower().replace("-", "")
try:
self._connection = dbapi.connect(host=connectInfo.Host,
user = connectInfo.User, passwd =
connectInfo.revealPW(),
- db=connectInfo.Database, port=port,
**kwargs)
+ db=connectInfo.Database, port=port,
charset=charset, **kwargs)
except Exception, e:
try:
errMsg = str(e).decode(self.Encoding)
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]