From 56e7c7b5780f278ed6e4201793f2dc3531b6a88a Mon Sep 17 00:00:00 2001 From: Pietro Brenna Date: Wed, 5 Aug 2020 09:10:31 +0200 Subject: [PATCH] Fix bug di mysql vecchissimo --- jaydebeapi/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jaydebeapi/__init__.py b/jaydebeapi/__init__.py index a890c3d..5167920 100644 --- a/jaydebeapi/__init__.py +++ b/jaydebeapi/__init__.py @@ -617,10 +617,18 @@ def _unknownSqlTypeConverter(rs, col): return rs.getObject(col) def _to_datetime(rs, col): - java_val = rs.getTimestamp(col) + import jpype + SQLException = jpype.java.sql.SQLException + try: + java_val = rs.getTimestamp(col) + except: + java_val = bytes(rs.getBytes(col)).decode('utf-8') if not java_val: return - d = datetime.datetime.strptime(str(java_val)[:19], "%Y-%m-%d %H:%M:%S") + try: + d = datetime.datetime.strptime(str(java_val)[:19], "%Y-%m-%d %H:%M:%S") + except ValueError: + return "" d = d.replace(microsecond=int(str(java_val.getNanos())[:6])) return str(d)