Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-117

Add conversion support

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: N/A
    • Fix Version/s: 1.0.3
    • Component/s: Generic
    • Labels:
      None

      Description

      Provide a converter to convert values into another format, e.g. datetime.timedelta to datetime.time:

      import mariadb
      from mariadb.constants import CLIENT, FIELD_TYPE
      import datetime
       
      def timedelta_to_time(s):
          return (datetime.datetime.min + s).time()
       
      conversions = {
          **{FIELD_TYPE.TIME: timedelta_to_time}
      }
       
      conn= mariadb.connect(db="test", converter=conversions)
      cursor=conn.cursor()
      cursor.execute("SELECT CAST(NOW() AS TIME)")
      row= cursor.fetchone()
      print(row)
      del cursor, conn
      

      Instead of datetime.timedelta result will be datetime.time

        Attachments

          Activity

            People

            Assignee:
            georg Georg Richter
            Reporter:
            georg Georg Richter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: