Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#83 datetime objects attempt to insert microseconds into MySQL

MySQLdb-0.9.3
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2004-04-12
Michael C. Neel
No

The latest CVS version of MySQLdb uses datetime objects
to represent datetime fields in MySQL, which is great.
However when inserting/updating a datetime field, you
currently need to pre-format a python datetime object
to avoid MySQLdb inserting a date like '2004-04-10
15:33:35.4564626', which will work but throw a warning.

Discussion

  • Andy Dustman
    Andy Dustman
    2004-05-18

    Logged In: YES
    user_id=71372

    How do you feel about doing this in your application:

    d.microseconds = 0 # where d is a datetime object

    Eventually, MySQL will support fractional timestamps.
    Additionally, future versions of MySQLdb (1.1 and up) will
    use the warnings module handle warnings, so this should be
    less of an issue.

     
  • Andy Dustman
    Andy Dustman
    2004-05-18

    Logged In: YES
    user_id=71372

    Oops, it's microsecond, and it's read-only.

    Maybe you could set the microseconds to 0 when you create it?

    Reset status to Open if you reply; otherwise I will probably
    not see it.

     
  • Andy Dustman
    Andy Dustman
    2004-05-18

    Logged In: YES
    user_id=71372

    This has been fixed in the current CVS tree.

     
  • Logged In: YES
    user_id=294560

    The only reason I could see for wanting the driver to trim
    off the microseconds is that frees up the coder to use
    methods like datetime.today(), which help in readability.
    Beside the point now though, thank you for addressing this
    in the code =).