From: Gaƫtan de Menten Date: Mon, 23 Nov 2009 08:35:34 +0000 (+0000) Subject: Prelookup codec in the String result processor for dialects which do not X-Git-Tag: rel_0_6beta1~156 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95e349a5dc2ae88e12845d0fff686069ef547fc7;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Prelookup codec in the String result processor for dialects which do not return Unicode natively, as suggested in #1323. Provides a nice speed boost (~21% total query time). --- diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 137b580c60..99635a55df 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -23,6 +23,7 @@ __all__ = [ 'TypeEngine', 'TypeDecorator', 'AbstractType', 'UserDefinedType', import inspect import datetime as dt from decimal import Decimal as _python_Decimal +import codecs from sqlalchemy import exc, schema from sqlalchemy.sql import expression @@ -530,10 +531,11 @@ class String(Concatenable, TypeEngine): if needs_convert: # note we *assume* that we do not have a unicode object # here, instead of an expensive isinstance() check. - encoding = dialect.encoding + decoder = codecs.getdecoder(dialect.encoding) def process(value): if value is not None: - return value.decode(encoding) + # decoder returns a tuple: (value, len) + return decoder(value)[0] else: return value return process