mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00

* Turn autocommit off initially * Add support for mysql_autocommit, _commit, and _rollback API functions (new in MySQL-4.1) * Remove Connection.begin(); use SQL BEGIN or START TRANSACTION instead * pytimes (standard datetime module) is now the default implementation * Detect and handle MySQL-4.1 and newer TIMESTAMP (looks like DATETIME) * UnicodeType and ObjectType now always handled (required features) * Ditch support for L at the end of long integer * Remove z and crypt libs if building for Windows * Version 1.1.2
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
"""times module
|
|
|
|
This module provides some Date and Time classes for dealing with MySQL data.
|
|
"""
|
|
|
|
from _mysql import string_literal
|
|
|
|
try:
|
|
from pytimes import *
|
|
|
|
except ImportError:
|
|
try:
|
|
from mxdatetimes import *
|
|
|
|
except ImportError:
|
|
# no DateTime? We'll muddle through somehow.
|
|
from stringtimes import *
|
|
|
|
def DateTime2literal(d, c):
|
|
"""Format a DateTime object as an ISO timestamp."""
|
|
return string_literal(format_TIMESTAMP(d),c)
|
|
|
|
def DateTimeDelta2literal(d, c):
|
|
"""Format a DateTimeDelta object as a time."""
|
|
return string_literal(format_TIME(d),c)
|
|
|
|
def mysql_timestamp_converter(s):
|
|
"""Convert a MySQL TIMESTAMP to a Timestamp object."""
|
|
# MySQL>4.1 returns TIMESTAMP in the same format as DATETIME
|
|
if s[4] == '-': return DateTime_or_None(s)
|
|
s = s + "0"*(14-len(s)) # padding
|
|
parts = map(int, filter(None, (s[:4],s[4:6],s[6:8],
|
|
s[8:10],s[10:12],s[12:14])))
|
|
try: return Timestamp(*parts)
|
|
except: return None
|