Hi friends!
I am trying to insert unicode string into the MySQL table, but recive an
error:
Traceback (most recent call last):
File "database.py", line 33, in ?
db.InsertCountry('п╞п©п╬п╫п╦я▐')
File "database.py", line 27, in InsertCountry
country = CountryTable(title=title)
File "/usr/lib/python2.4/site-packages/sqlobject/declarative.py",
line 93, in _wrapper
return fn(self, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1198,
in __init__
self._create(id, **kw)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1225,
in _create
self._SO_finishCreate(id)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1249,
in _SO_finishCreate
id, names, values)
File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 361, in queryInsertID
return self._runWithConnection(self._queryInsertID, soInstance, id,
names, values)
File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 221, in _runWithConnection
val = meth(conn, *args)
File
"/usr/lib/python2.4/site-packages/sqlobject/mysql/mysqlconnection.py",
line 94, in _queryInsertID
self._executeRetry(conn, c, q)
File
"/usr/lib/python2.4/site-packages/sqlobject/mysql/mysqlconnection.py",
line 73, in _executeRetry
myquery = unicode(query, self.encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 43:
ordinal not in range(128)
Sample code in the attachment.
If is it matter something I have the following:
Python 2.4.3
SQLObject 0.7.1
Python MySQLDB 1.2.1
MySQL 5.0.24a
# -*- coding: utf-8 -*-
from sqlobject import *
#from lib.dbsql import *
from dbsql import *
class Database:
def __init__(self, user, password, database, server):
connString = user + ':' + password + '@' + server + '/' + database
connection = connectionForURI('mysql://' + connString)
TownTable._connection = connection
CountryTable._connection = connection
TownTable.createTable(ifNotExists=True)
CountryTable.createTable(ifNotExists=True)
def SelectCountries(self):
countries = CountryTable.select()
listOfCoutries = []
for country in countries:
listOfCoutries.append([country.title, country.id])
return listOfCoutries
def InsertCountry(self, title):
country = CountryTable(title=title)
if __name__ == '__main__':
db = Database('dbuser', 'dbpassword', 'demodb', 'localhost')
db.InsertCountry('ЯпониÑ')
# -*- coding: utf-8 -*-
from sqlobject import *
class TownTable(SQLObject):
title = UnicodeCol()
countries = RelatedJoin('CountryTable')
class CountryTable(SQLObject):
title = UnicodeCol()
towns = RelatedJoin('TownTable')
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss