Basil Shubin пишет:
> sophana пишет:
>> Oleg Broytmann a écrit :
>>> On Sat, Oct 07, 2006 at 03:37:14PM +0700, Basil Shubin wrote:
>>>   
>>>> I am trying to insert unicode string into the MySQL table, but recive an 
>>>> error:
>>>>     
>>> [skip]
>>>   
>>>>     connString =  user + ':' + password + '@' + server + '/' + database
>>>>     
>>>    I wonder if anybody's reading this mailing list? People are rushing to
>>> report problems that should be fixed already - and nobody has reported if
>>> the latest patches helped or not. :(
>>>
>>>    Most of these Unicode-related problem in MySQL should disappear if you
>>> upgrade to the latest code from 0.7-bugfix branch from SVN. I'd like to
>>> hear a report from anyone who has tried it.
>>>
>>>    You also need to set you client and DB encodings:
>>>
>>> connString =  user + ':' + password + '@' + server + '/' + database + 
>>> "?chrset=utf8&sqlobject_encoding=utf-8"
>>>
>>> Oleg.
>>>   
>> Ok did a test:
>> setup: centos 4, mysql5.0.22 , MySQL-python24 1.2.2b1, python24,
>> SQLObject-0.7.2a_r1987-py2.4
>>
>> a little test program:
>>
>> from sqlobject import *
>> database='mysql://xxx?use_unicode=1&sqlobject_encoding=utf8'
>>
>> connection = connectionForURI(database)
>> sqlhub.processConnection = connection
>>
>> connection.debug=True
>>
>> class TestSql(SQLObject):
>>     test = UnicodeCol()
>>
>> TestSql.createTable(ifNotExists=True)
>> s=u'\ufffd'
>> x=s.encode('utf8')
>> print x,s
>> a=TestSql(test=s)
>> a
>>
>> does not work:
>>   File
>> "/usr/lib/python2.4/site-packages/SQLObject-0.7.2a_r1987-py2.4.egg/sqlobject/dbconnection.py",
>> line 221, in _runWithConnection
>>     val = meth(conn, *args)
>>   File
>> "/usr/lib/python2.4/site-packages/SQLObject-0.7.2a_r1987-py2.4.egg/sqlobject/mysql/mysqlconnection.py",
>> line 98, in _queryInsertID
>>     self._executeRetry(conn, c, q)
>>   File
>> "/usr/lib/python2.4/site-packages/SQLObject-0.7.2a_r1987-py2.4.egg/sqlobject/mysql/mysqlconnection.py",
>> line 78, in _executeRetry
>>     return cursor.execute(myquery)
>>   File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 149, in execute
>> UnicodeEncodeError: 'latin-1' codec can't encode character u'\ufffd' in
>> position 37: ordinal not in range(256)
>>
>> But when I use ?use_unicode=1&sqlobject_encoding=utf8&charset=utf8
>> It now works!
>>
>> I thought that the charset parameter was not needed anymore?
> 
> If I try to insert the unicode string I got following warning:
> /usr/lib/python2.4/site-packages/SQLObject-0.7.2a_r2017-py2.4.egg/sqlobject/mysql/mysqlconnection.py:78:
>  
> Warning: Data truncated for column 'title' at row 1
>    return cursor.execute(myquery)
> [[u'?????????', 2L, 1L]]
> 
> String itself looking strange, only an '????' chars?
> 
> I am totaly confused, what shall I do, if I want insert a cyrillic 
> strings? Maybe the unicode is not a right solution? But I want use it in 
> my wxPython application where all strings is a unicode strings.

Hmm... This warning appears only for cyrillic strings. The 
'TownTable._connection.query("SET NAMES utf8")' wan't help. :-(

I am totaly confused.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to