On Feb 11, 2009, at 8:05 AM, 一首诗 wrote:
>
> Hi all,
>
> I'm using sqlalchemy as my ORM library and it works fines until today
> one of my test case fail
>
> ===================================================
> sqlalchemy.exc.ProgrammingError: (ProgrammingError) You must not use
> 8-
> bit bytestrings unless you use a text_factory that can interpret 8-bit
> bytestrings (like text_factory = str). It is highly recommended that
> you instead just switch your application to Unicode strings. u'INSERT
> INTO b_taa_role (role_name, activity, grantable, hierarchy, creator,
> related_smf, related_domain, priority) VALUES
> (?, ?, ?, ?, ?, ?, ?, ?)' ['\xe7\xae\xa1\xe7\x90\x86\xe5\x91\x98',
> None, None, None, None, None, None, 0]
> ===================================================
>
> The problem is : it only fails on one system.
>
> I've test the case in 3 computer, 2 ubuntu and 1 ubuntu server.
>
> It only fails on ubuntu server edition.
>
> The locale setting, python version, and sqlalchemy version is
> identical!
> As the final running environment is not decided yer, I am afraid this
> will be a big problem.
>
> I have considered to use unicode every where, but the problem is,
> most of the data will retrieved will be in utf8. So if I choose
> unicode, I have to translate every string parameter.
unfortunately that's what's required. The best practice in Python
is that any data entering your application should be decoded to Python
unicode objects immediately - that way you never need to be concerned
about encodings within the application. If/when you migrate to
Python 3.0, its actually not possible to have a string object without
decoding at some step.
the error message is raised by Pysqlite, and the reason its only on
one system may be that the error message is a recent addition to
pysqlite as of very recent versions.
A SQLAlchemy technique to convert the data as it becomes a bind
parameter would be:
class UTF8String(TypeDecorator):
impl = Unicode
def process_bind_param(self, value, dialect):
return value.decode('utf-8')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---