summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl-Aksel Puulmann <oxymaccy@gmail.com>2015-01-06 23:52:43 +0200
committerKarl-Aksel Puulmann <oxymaccy@gmail.com>2015-01-07 00:58:28 +0200
commit4aaa117cddb61e20a40ea63adc7a61d4be4e8e39 (patch)
treef09235e7aefc8d364b3fbc10e7986ffc5294a16e
parentf3f8c92d755c3f28c92bef1cf91581b1939f0a18 (diff)
Force psycopg to decode strings received from database to unicode.
Unicode data caused queries to output nothing and exit with an UnicodeDecodeError.
-rw-r--r--pgcli/pgexecute.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index e4eab6bf..2426882c 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -1,9 +1,15 @@
import logging
import psycopg2
+import psycopg2.extensions
from .packages import pgspecial
_logger = logging.getLogger(__name__)
+# Cast all database input to unicode automatically.
+# See http://initd.org/psycopg/docs/usage.html#unicode-handling for more info.
+psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
+psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
+
def _parse_dsn(dsn, default_user, default_password, default_host,
default_port):
"""