From the order of the try/import statements in times.py am I right in thinking that if it's available (e.g. on Python 2.3) the Python datetime module will be used for date handling in preference to mx.DateTime?
If I'd like to force the use of mx.DateTime is it OK to do something like this:
mx_type_conv = MySQLdb.converters.conversions.copy()
mx_type_conv[MySQLdb.FIELD_TYPE.DATE] = MySQLdb.mxdatetimes.DateTime_or_None [ditto for the other field types..]
and then create the connection with conv=mx_type_conv
Would there be a better way of doing this?
Thanks,
-Michael
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
From the order of the try/import statements in times.py am I right in thinking that if it's available (e.g. on Python 2.3) the Python datetime module will be used for date handling in preference to mx.DateTime?
If I'd like to force the use of mx.DateTime is it OK to do something like this:
mx_type_conv = MySQLdb.converters.conversions.copy()
mx_type_conv[MySQLdb.FIELD_TYPE.DATE] = MySQLdb.mxdatetimes.DateTime_or_None
[ditto for the other field types..]
and then create the connection with conv=mx_type_conv
Would there be a better way of doing this?
Thanks,
-Michael
You can do that, or you can directly modify MySQLdb.converters.conversions, if you want.
I did it in sitecustomize.py, so that I need neither to patch my every script nor edit MySQLdb files:
===/usr/lib/python2.3/sitecustomize.py===
import MySQLdb.mxdatetimes as mx
import MySQLdb.converters as cv
cv.conversions[10] = mx.Date_or_None
cv.conversions[11] = mx.TimeDelta_or_None
cv.conversions[12] = mx.DateTime_or_None
==============================