]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Adjusted the regexp used in the
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 23 Jan 2012 00:17:21 +0000 (19:17 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 23 Jan 2012 00:17:21 +0000 (19:17 -0500)
    mssql.TIME type to ensure only six digits
    are received for the "microseconds" portion
    of the value, which is expected by
    Python's datetime.time().  Note that
    support for sending microseconds doesn't
    seem to be possible yet with pyodbc
    at least.  [ticket:2340]

CHANGES
lib/sqlalchemy/dialects/mssql/base.py
test/dialect/test_mssql.py

diff --git a/CHANGES b/CHANGES
index 53220bfe599ebf28a7c05641b54064eab2324d7a..b28618d23dc80171bed413540ac3768df0b9daab 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -71,6 +71,16 @@ CHANGES
     for non-reflected "PARTITION" directives,
     thanks to George Reilly [ticket:2376]
 
+- mssql
+  - [bug] Adjusted the regexp used in the
+    mssql.TIME type to ensure only six digits
+    are received for the "microseconds" portion
+    of the value, which is expected by 
+    Python's datetime.time().  Note that
+    support for sending microseconds doesn't
+    seem to be possible yet with pyodbc
+    at least.  [ticket:2340]
+
 - Py3K
   - [bug] Fixed inappropriate usage of util.py3k
     flag and renamed it to util.py3k_warning, since 
index 7df83d0574ea35d146cd26657ea2e082f242b791..4d7dd1c5822ad527fc57bcc3d6d629246456a249 100644 (file)
@@ -296,7 +296,7 @@ class TIME(sqltypes.TIME):
             return value
         return process
 
-    _reg = re.compile(r"(\d+):(\d+):(\d+)(?:\.(\d+))?")
+    _reg = re.compile(r"(\d+):(\d+):(\d+)(?:\.(\d{0,6}))?")
     def result_processor(self, dialect, coltype):
         def process(value):
             if isinstance(value, datetime.datetime):
index 75e9510eb3817da62d5f6cf9aba28f58507ecc0e..94609d9534f81cadcbb737ce4e1712332c5b5ded 100644 (file)
@@ -10,6 +10,7 @@ from sqlalchemy.orm import *
 from sqlalchemy.sql import table, column
 from sqlalchemy.databases import mssql
 from sqlalchemy.dialects.mssql import pyodbc, mxodbc, pymssql
+from sqlalchemy.dialects.mssql.base import TIME
 from sqlalchemy.engine import url
 from test.lib import *
 from test.lib.testing import eq_, emits_warning_on, \
@@ -1108,6 +1109,22 @@ class ParseConnectTest(fixtures.TestBase, AssertsCompiledSQL):
                               'Unrecognized server version info',
                               engine.connect)
 
+class TimeTypeTest(fixtures.TestBase):
+
+    def test_result_processor_no_microseconds(self):
+        expected = datetime.time(12, 34, 56)
+        self._assert_result_processor(expected, '12:34:56')
+
+    def test_result_processor_too_many_microseconds(self):
+        # microsecond must be in 0..999999, should truncate (6 vs 7 digits)
+        expected = datetime.time(12, 34, 56, 123456)
+        self._assert_result_processor(expected, '12:34:56.1234567')
+
+    def _assert_result_processor(self, expected, value):
+        mssql_time_type = TIME()
+        result_processor = mssql_time_type.result_processor(None, None)
+        eq_(expected, result_processor(value))
+
 class TypesTest(fixtures.TestBase, AssertsExecutionResults, ComparesTables):
     __only_on__ = 'mssql'