summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-10-10 14:25:21 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-10-10 14:25:21 -0400
commitce2c4509176da6c125ec239931f05a946ac44d58 (patch)
tree6bc57993f236f06fbd6a6b1ac4a205490a5fc2a8 /lib/sqlalchemy/dialects/mysql
parentb7ecadfbde9a17eb32fc08d0e33f1a135de9ccc2 (diff)
downloadsqlalchemy-ce2c4509176da6c125ec239931f05a946ac44d58.tar.gz
- [feature] Added TIME type to mysql dialect,
accepts "fst" argument which is the new "fractional seconds" specifier for recent MySQL versions. The datatype will interpret a microseconds portion received from the driver, however note that at this time most/all MySQL DBAPIs do not support returning this value. [ticket:2534] - attempted to modernize the types tests in test_mysql a little, though has a long way to go
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py45
1 files changed, 39 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 4c983ad30..1ba567682 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -676,19 +676,49 @@ class BIT(sqltypes.TypeEngine):
return value
return process
-class _MSTime(sqltypes.Time):
- """MySQL TIME type."""
+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.
+
+ """
__visit_name__ = 'TIME'
+ def __init__(self, timezone=False, fsp=None):
+ """Construct a MySQL TIME type.
+
+ :param timezone: not used by the MySQL dialect.
+ :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.
+
+ .. versionadded:: 0.8 The MySQL-specific TIME
+ type as well as fractional seconds support.
+
+ """
+ super(TIME, self).__init__(timezone=timezone)
+ self.fsp = fsp
+
def result_processor(self, dialect, coltype):
time = datetime.time
def process(value):
# convert from a timedelta value
if value is not None:
+ microseconds = value.microseconds
seconds = value.seconds
minutes = seconds / 60
- return time(minutes / 60, minutes % 60, seconds - minutes * 60)
+ return time(minutes / 60,
+ minutes % 60,
+ seconds - minutes * 60,
+ microsecond=microseconds)
else:
return None
return process
@@ -1157,7 +1187,7 @@ class SET(_StringType):
return process
# old names
-MSTime = _MSTime
+MSTime = TIME
MSSet = SET
MSEnum = ENUM
MSLongBlob = LONGBLOB
@@ -1191,7 +1221,7 @@ MSInteger = INTEGER
colspecs = {
sqltypes.Numeric: NUMERIC,
sqltypes.Float: FLOAT,
- sqltypes.Time: _MSTime,
+ sqltypes.Time: TIME,
sqltypes.Enum: ENUM,
}
@@ -1703,7 +1733,10 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
return "DATE"
def visit_TIME(self, type_):
- return "TIME"
+ if getattr(type_, 'fsp', None):
+ return "TIME(%d)" % type_.fsp
+ else:
+ return "TIME"
def visit_TIMESTAMP(self, type_):
return 'TIMESTAMP'