[CONPY-117] Add conversion support Created: 2020-09-29  Updated: 2020-10-06  Resolved: 2020-10-04

Status: Closed
Project: MariaDB Connector/Python
Component/s: Generic
Affects Version/s: N/A
Fix Version/s: 1.0.3

Type: Task Priority: Major
Reporter: Georg Richter Assignee: Georg Richter
Resolution: Fixed Votes: 0
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


Generated at Thu Feb 08 03:30:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.