From fbf0307f6374a595c266377409df82017a6708c4 Mon Sep 17 00:00:00 2001 From: parmentelat Date: Thu, 13 Dec 2018 16:08:14 +0100 Subject: [PATCH] that one was hard to pinpoint: we DON'T want to convert str to bytes, when normalizing prior to talking to the db; quite the opposite ! --- PLC/PostgreSQL.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/PLC/PostgreSQL.py b/PLC/PostgreSQL.py index 2368419..dcf0608 100644 --- a/PLC/PostgreSQL.py +++ b/PLC/PostgreSQL.py @@ -60,14 +60,16 @@ class PostgreSQL: @staticmethod # From pgdb, and simplify code + # this is **very different** from the python2 code ! def _quote(x): if isinstance(x, DateTimeType): x = str(x) - elif isinstance(x, str): - x = x.encode('utf-8') + elif isinstance(x, bytes): + x = x.decode('utf-8') - if isinstance(x, bytes): - x = "'%s'" % str(x).replace("\\", "\\\\").replace("'", "''") + if isinstance(x, str): + x = x.replace("\\", "\\\\").replace("'", "''") + x = f"'{x}'" elif isinstance(x, (int, float)): pass elif x is None: -- 2.43.0