#197 datetime.timedelta not written correctly

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2006-07-24
Mario Frasca
No

MySQLdb:

MySQLdb.version
'1.2.1_p2'

MySQL:
mariof@andromeda:~$ mysql --version
mysql Ver 14.12 Distrib 5.0.18, for pc-linux-gnu
(i386) using readline 5.0

Python: 2.4.1

mariof@andromeda:~$ uname -a
Linux andromeda 2.6.16-desktops #1 SMP Thu Mar 23
12:38:16 CET 2006 i686 GNU/Linux


writing a value into a TIME field (a time INTERVAL not
a time-of-day), so I'm trying to write a
datetime.timedelta...

import MySQLdb
import datetime
db = MySQLdb.connect(...)
cr = db.cursor()
cr.execute('create table test (f time)')
0L
cr.execute('insert into test values (%s)',
datetime.timedelta(1,2,3))
1L
cr.execute('select * from test')
1L
cr.fetchone()
(datetime.timedelta(0, 1),)

see that the value retrieved (zero days, 1 second) is
not the same as the value written (one day, two
seconds, 3 microseconds). microseconds are lost
anyways by the engine, but the other fields ought to be
written correctly.

I have redefined format_TIME in times.py and it works
for me... (with the limitations about second fractions)

def format_TIME(v):
seconds = int(v.seconds) % 60
minutes = int(v.seconds / 60) % 60
hours = int(v.seconds / 3600) % 24

return '%d %d:%d:%d' % (v.days, hours, minutes, seconds)

Discussion

  • Andy Dustman
    Andy Dustman
    2006-08-26

    Logged In: YES
    user_id=71372

    Fixed in development version; please test 1.2.2b1 when it is
    released (mysql-python-test).