Menu

Using mx.DateTime under Python 2.3

Help
2004-10-29
2012-09-19
  • Michael Josephson

    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

     
    • Andy Dustman

      Andy Dustman - 2004-11-02

      You can do that, or you can directly modify MySQLdb.converters.conversions, if you want.

       
    • theIgel

      theIgel - 2005-01-31

      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
      ==============================

       

Log in to post a comment.