"""
import datetime
-import inspect
import re
import sys
from ...engine import default
from ... import types as sqltypes
from ...util import topological
-from ...types import DATE, DATETIME, BOOLEAN, TIME, \
+from ...types import DATE, BOOLEAN, \
BLOB, BINARY, VARBINARY
RESERVED_WORDS = set(
class TIME(sqltypes.TIME):
- """MySQL TIME type.
-
- Recent versions of MySQL add support for
- fractional seconds precision. While the
- :class:`.mysql.TIME` type now supports this,
- note that many DBAPI drivers may not yet
- include support.
-
- """
+ """MySQL TIME type. """
__visit_name__ = 'TIME'
:param fsp: fractional seconds precision value.
MySQL 5.6 supports storage of fractional seconds;
this parameter will be used when emitting DDL
- for the TIME type. Note that many DBAPI drivers
- may not yet have support for fractional seconds,
- however.
+ for the TIME type.
+
+ .. note::
+
+ DBAPI driver support for fractional seconds may
+ be limited; current support includes
+ MySQL Connector/Python.
.. versionadded:: 0.8 The MySQL-specific TIME
type as well as fractional seconds support.
class TIMESTAMP(sqltypes.TIMESTAMP):
- """MySQL TIMESTAMP type."""
+ """MySQL TIMESTAMP type.
+
+ """
+
__visit_name__ = 'TIMESTAMP'
+ def __init__(self, timezone=False, fsp=None):
+ """Construct a MySQL TIMESTAMP type.
+
+ :param timezone: not used by the MySQL dialect.
+ :param fsp: fractional seconds precision value.
+ MySQL 5.6.4 supports storage of fractional seconds;
+ this parameter will be used when emitting DDL
+ for the TIMESTAMP type.
+
+ .. note::
+
+ DBAPI driver support for fractional seconds may
+ be limited; current support includes
+ MySQL Connector/Python.
+
+ .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.TIMESTAMP`
+ with fractional seconds support.
+
+ """
+ super(TIMESTAMP, self).__init__(timezone=timezone)
+ self.fsp = fsp
+
+
+class DATETIME(sqltypes.DATETIME):
+ """MySQL DATETIME type.
+
+ """
+
+ __visit_name__ = 'DATETIME'
+
+ def __init__(self, timezone=False, fsp=None):
+ """Construct a MySQL DATETIME type.
+
+ :param timezone: not used by the MySQL dialect.
+ :param fsp: fractional seconds precision value.
+ MySQL 5.6.4 supports storage of fractional seconds;
+ this parameter will be used when emitting DDL
+ for the DATETIME type.
+
+ .. note::
+
+ DBAPI driver support for fractional seconds may
+ be limited; current support includes
+ MySQL Connector/Python.
+
+ .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.DATETIME`
+ with fractional seconds support.
+
+ """
+ super(DATETIME, self).__init__(timezone=timezone)
+ self.fsp = fsp
+
class YEAR(sqltypes.TypeEngine):
"""MySQL YEAR type, for single byte storage of years 1901-2155."""
return "BIT"
def visit_DATETIME(self, type_):
- return "DATETIME"
+ if getattr(type_, 'fsp', None):
+ return "DATETIME(%d)" % type_.fsp
+ else:
+ return "DATETIME"
def visit_DATE(self, type_):
return "DATE"
return "TIME"
def visit_TIMESTAMP(self, type_):
- return 'TIMESTAMP'
+ if getattr(type_, 'fsp', None):
+ return "TIMESTAMP(%d)" % type_.fsp
+ else:
+ return "TIMESTAMP"
def visit_YEAR(self, type_):
if type_.display_width is None:
roundtrip([False, False, 0, 0, 0], [False, False, False,
False, 0])
- def test_timestamp(self):
- """Exercise funky TIMESTAMP default syntax."""
+ def test_timestamp_fsp(self):
+ self.assert_compile(
+ mysql.TIMESTAMP(fsp=5),
+ "TIMESTAMP(5)"
+ )
+
+ def test_timestamp_defaults(self):
+ """Exercise funky TIMESTAMP default syntax when used in columns."""
columns = [
([TIMESTAMP],
[(now, now), (None, now)]
)
- def test_time(self):
+ def test_datetime_generic(self):
+ self.assert_compile(
+ mysql.DATETIME(),
+ "DATETIME"
+ )
+
+ def test_datetime_fsp(self):
+ self.assert_compile(
+ mysql.DATETIME(fsp=4),
+ "DATETIME(4)"
+ )
+
+
+ def test_time_generic(self):
""""Exercise TIME."""
self.assert_compile(
"TIME"
)
+ def test_time_fsp(self):
self.assert_compile(
mysql.TIME(fsp=5),
"TIME(5)"
)
+ def test_time_result_processor(self):
eq_(
mysql.TIME().result_processor(None, None)(
datetime.timedelta(seconds=35, minutes=517,