utf-8 encoding troubles
2010-02-05 02:48:15 GMT
I am having troubles with some unicode utf8 characters. They are not displayed properly.
I was trying a lot off different settings on the connection part of the SQLObject scrpit (see below), but not success till now.
============== this code DOES NOT bring the UTF -8 code from the database
==============
from sqlobject import *
mport MySQLdb.converters
def _mysql_timestamp_converter(raw):
"""Convert a MySQL TIMESTAMP to a floating point number representing
the seconds since the Un*x Epoch. It uses custom code the input seems
to be the new (MySQL 4.1+) timestamp format, otherwise code from the
MySQLdb module is used."""
if raw[4] == '-':
return time.mktime(time.strptime(raw, '%Y-%m-%d %H:%M:%S'))
else:
return MySQLdb.converters.mysql_timestamp_converter(raw)
conversions = MySQLdb.converters.conversions.copy()
conversions[MySQLdb.constants.FIELD_TYPE.TIMESTAMP] = _mysql_timestamp_converter
MySQLConnection = mysql.builder()
connection = connectionForURI("mysql://prestashop:prestashop <at> 127.0.0.1:3306/prestashop")
=============================================================================
Finaly I did try the direct use of the MySQLdb and it worsk OK! But I can not see why!!!
============== this code brings the UTF-8 code from the database ==============
import MySQLdb
conn = MySQLdb.connect (host = "localhost",
user = "prestashop",
passwd = "prestashop",
db = "prestashop",
use_unicode = True,
charset = "utf8")
cursor = conn.cursor ()
cursor.execute ('SELECT * FROM prestashop.ps_address')
Thanks for your comments
Petr Jakeš
------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com
_______________________________________________ sqlobject-discuss mailing list sqlobject-discuss <at> lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
RSS Feed