Re: [SQLObject] Unable to insert unicode string into the MySQL table
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: sophana <so...@zi...> - 2006-10-10 08:03:09
|
what is your exact sqlobject, mysqldb version and mysql version? Basil Shubin a =C3=A9crit : > Hi friends, > > sophana =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > [skip] > >> But when I use ?use_unicode=3D1&sqlobject_encoding=3Dutf8&charset=3Dut= f8 >> It now works! > > With this '?use_unicode=3D1&sqlobject_encoding=3Dutf8&charset=3Dutf8' I= got > the following error: > /usr/lib/python2.4/site-packages/sqlobject/mysql/mysqlconnection.py:74: > Warning: Data truncated for column 'title' at row 1 > return cursor.execute(myquery) > > For detailed information, please, examine source code in attachment. > -----------------------------------------------------------------------= - > > # -*- coding: utf-8 -*- > > from sqlobject import * > #from lib.dbsql import * > from dbsql import * > > > class Database: > > def __init__(self, user, password, database, server): > connString =3D user + ':' + password + '@' + server + '/' + da= tabase > unicodeString =3D '?use_unicode=3D1&sqlobject_encoding=3Dutf8&c= harset=3Dutf8' > connection =3D connectionForURI('mysql://' + connString + unico= deString) > TownTable._connection =3D connection > > TownTable.createTable(ifNotExists=3DTrue) > > def SelectTowns(self): > towns =3D TownTable.select() > listOfTowns =3D [] > for town in towns: > listOfTowns.append([town.title, town.country, town.id]) > return listOfTowns > > def InsertTown(self, title, country): > town =3D TownTable(title=3Dtitle, country=3Dcountry) > > > if __name__ =3D=3D '__main__': > db =3D Database('dbuser', 'dbpassword', 'demodb', 'localhost') > =20 > db.InsertTown('=D0=BF=E2=95=91=D1=8F=E2=94=8C=D1=8F=E2=94=80=D0=BF=E2= =95=A3=D0=BF=E2=95=A4=D0=BF=E2=95=A3=D0=BF=E2=95=A1=D0=BF=E2=95=AC=D0=BF=E2= =95=A7', 1) > > =20 > -----------------------------------------------------------------------= - > > # -*- coding: utf-8 -*- > > from sqlobject import * > > > class TownTable(SQLObject): > > title =3D UnicodeCol() > country =3D IntCol() > =20 |