Roundtrip SQL data especially datetime

dyork reverseyorkage at david.com
Sun Dec 17 09:25:19 EST 2006


"John Nagle" <nagle at animats.com> wrote in message 
news:i5Mgh.8778$Ga1.6636 at newssvr12.news.prodigy.net...
>    Actually, MySQLdb isn't released for Python 2.5 yet, so for
> anything with a database, you need an older version of Python.

It's not really a problem so far.

>    If you really want to change the conversions for TIMESTAMP, add the
> "conv" argument to "connect".  Make a copy of 
> "MySQLdb.converters.conversions",
> then replace the key "MySQLdb.FIELD_TYPE.TIMESTAMP", which normally has
> the value 'mysql_timestamp_converter' with your own converter.  You can
> then get the interface to emit a "datetime" object.

Thanks! Very helpful. Actually, it's DATETIME I want and not TIMESTAMP, but 
you certainly pointed me in the right direction.

Turns out the author of MySQLdb knows his onions, and virtually all of what 
I need is in there. Seems it's critical to send in the right Python type to 
trigger the right conversion routine to get the right result, and some of 
the choices are not completely obvious. Still, the concept is good.

>    None of this will help performance; dates and times are sent over the
> connection to a MySQL database as strings.

Whenever you touch SQL (a) you talk strings and (b) performance belongs on a 
different planet. I can live with that.

DY 





More information about the Python-list mailing list