Menu

DateTime objects returned from query

Help
2001-04-27
2012-09-19
  • Greg Fortune

    Greg Fortune - 2001-04-27

    Python 2.0
    MySQLdb 0.3.5

    If DateTime is available, MySQLdb returns a DateTime object for each Date field in the requested query. 

    Although DateTime objects are incredibly powerful, I'm just looking for the date as a string and am forced to convert the string after it's returned from the database or using the FORMAT function in my SQL query.

    Both ideas will work, but it would be nice to be able to turn off the use of DateTime in the MySQLdb module as needed.  It didn't appear to be possible from looking at the CVS source without directly changing things in MySQLdb.py.  Would it be possible to add this ability?

     
    • Andy Dustman

      Andy Dustman - 2001-04-27

      Two options:

      1) don't install mx.DateTime.

      2) Make your own version of MySQLdb.quote_conv, sans DateTime convertors, and pass this to connect(), i.e.

      my_type_conv = MySQLdb.type_conv.copy()
      del my_type_conv[MySQLdb.FIELD_TYPE.DATE]
      db = MySQLdb.connect(...,conv=my_type_conv)

      Note that column types not present in type_conv are converted to strings.

       
      • Greg Fortune

        Greg Fortune - 2001-04-27

        "2) Make your own version of MySQLdb.quote_conv, sans DateTime convertors, and pass this to connect(), i.e."

        Thanks a bunch.  That's exactly what I was looking for.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.