From 9eb906e8a7ef92e1523dc65a85978130cced7e20 Mon Sep 17 00:00:00 2001 From: Evax Software Date: Mon, 8 Oct 2012 17:25:14 +0200 Subject: Map utf8mb4 to utf8 in python --- MySQLdb/cursors.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index a8cfa3e..3023fa3 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -47,6 +47,9 @@ from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \ NotSupportedError, ProgrammingError +def normalize_utf8mb4(charset): + return 'utf8' if charset == 'utf8mb4' else charset + class BaseCursor(object): """A base for Cursor classes. Useful attributes: @@ -177,7 +180,7 @@ class BaseCursor(object): """ del self.messages[:] db = self._get_db() - charset = db.character_set_name() + charset = normalize_utf8mb4(db.character_set_name()) if isinstance(query, unicode): query = query.encode(charset) if args is not None: @@ -225,7 +228,7 @@ class BaseCursor(object): del self.messages[:] db = self._get_db() if not args: return - charset = db.character_set_name() + charset = normalize_utf8mb4(db.character_set_name()) if isinstance(query, unicode): query = query.encode(charset) m = insert_values.search(query) if not m: -- cgit v1.2.1