#64 mysql_timestamp_converter misparses

MySQLdb-0.9.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2003-08-22
Adam J. Bliss
No

MySQLdb Version: 0.9.2
MySQL version: 4.1.0-alpha-max-nt

An automatically generated entry in a column of type
TIMESTAMP looks like this: "2003-08-22 17:03:57". But
in times.py, line 105 attempts to parse it differently
(without the delimiters between fields), and causes
int() to raise a ValueError on invalid literal "8-".

I applied the following patch and it seems to work now.
<pre><tt>
--- times.py.orig Tue May 22 20:08:10 2001
+++ times.py.patched Thu Aug 21 17:35:30 2003
@@ -101,8 +101,8 @@

def mysql_timestamp_converter(s):
"""Convert a MySQL TIMESTAMP to a Timestamp object."""
- s = s + "0"(14-len(s)) # padding
- parts = map(int, filter(None, (s[:4],s[4:6],s[6:8],
-

s[8:10],s[10:12],s[12:14])))
+ s = s + "0"
(19-len(s)) # padding
+ parts = map(int, filter(None, (s[:4],s[5:7],s[8:10],
+
s[11:13],s[14:16],s[17:19])))
try: return apply(Timestamp, tuple(parts))
except: return None
</pre></tt>

Discussion

  • Andy Dustman
    Andy Dustman
    2003-08-24

    Logged In: YES
    user_id=71372

    Evidently the formatting has changed in MySQL-4.1. I'm not
    fixing this; your patch breaks on MySQL<4.1. The plan is for
    MySQLdb-2 to support MySQL-4.1 and up.