From 95e349a5dc2ae88e12845d0fff686069ef547fc7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ga=C3=ABtan=20de=20Menten?= Date: Mon, 23 Nov 2009 08:35:34 +0000 Subject: [PATCH] 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). --- lib/sqlalchemy/types.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 -- 2.47.3