From 9acf3404005333daaa9658c4e2c22ad58ad1f99b Mon Sep 17 00:00:00 2001 From: Harshal Dhumal Date: Fri, 31 Mar 2017 21:11:25 -0400 Subject: [PATCH] Generic function qtLiteral was not adapting values properly when they contain non ascii characters. Fixes #2305 --- web/pgadmin/utils/driver/psycopg2/__init__.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py index bdbbee405..5c4f9ac28 100644 --- a/web/pgadmin/utils/driver/psycopg2/__init__.py +++ b/web/pgadmin/utils/driver/psycopg2/__init__.py @@ -1828,21 +1828,20 @@ class Driver(BaseDriver): @staticmethod def qtLiteral(value): - try: - res = adapt(value).getquoted() - except UnicodeEncodeError: - # We will handle special characters with utf8 encoding - adapted = adapt(value) + adapted = adapt(value) + + # Not all adapted objects have encoding + # e.g. + # psycopg2.extensions.BOOLEAN + # psycopg2.extensions.FLOAT + # psycopg2.extensions.INTEGER + # etc... + if hasattr(adapted, 'encoding'): adapted.encoding = 'utf8' - res = adapted.getquoted() + res = adapted.getquoted() - # Returns in bytes, we need to convert it in string if isinstance(res, bytes): - try: - res = res.decode() - except UnicodeDecodeError: - res = res.decode('utf-8') - + return res.decode('utf-8') return res @staticmethod