]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed mysql bug involving reflection of CURRENT_TIMESTAMP
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 20 Oct 2010 21:44:35 +0000 (17:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 20 Oct 2010 21:44:35 +0000 (17:44 -0400)
default used with ON UPDATE clause, thanks to
Taavi Burns [ticket:1940]

CHANGES
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/test_mysql.py

diff --git a/CHANGES b/CHANGES
index c2ebff1c498bccd2e9f1d06573ea0a066b06d3d4..375ce905950ecdf6998ea67cea33f9d402cf5745 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -201,6 +201,11 @@ CHANGES
    - Fixed bug which prevented "domain" built from a 
      custom type such as "enum" from being reflected.
      [ticket:1933]
+
+- mysql
+   - Fixed bug involving reflection of CURRENT_TIMESTAMP 
+     default used with ON UPDATE clause, thanks to 
+     Taavi Burns [ticket:1940]
      
 - mssql
    - Fixed reflection bug which did not properly handle
index a2d3748f330d54f816b0887521bc4d3b22b5907f..660d201d1811eba190251f89fea3b0836d6463f4 100644 (file)
@@ -2371,8 +2371,8 @@ class MySQLTableDefinitionParser(object):
             r'(?: +COLLATE +(?P<collate>[\w_]+))?'
             r'(?: +(?P<notnull>NOT NULL))?'
             r'(?: +DEFAULT +(?P<default>'
-              r'(?:NULL|\x27(?:\x27\x27|[^\x27])*\x27|\w+)'
-              r'(?:ON UPDATE \w+)?'
+              r'(?:NULL|\x27(?:\x27\x27|[^\x27])*\x27|\w+'
+              r'(?: +ON UPDATE \w+)?)'
             r'))?'
             r'(?: +(?P<autoincr>AUTO_INCREMENT))?'
             r'(?: +COMMENT +(P<comment>(?:\x27\x27|[^\x27])+))?'
index 7c4cc2309f05f51321b1ab7647f34e2e6cc06d4b..78e1b9ab0c25644b249995f163d146594d02746c 100644 (file)
@@ -763,6 +763,9 @@ class ReflectionTest(TestBase, AssertsExecutionResults):
             Column('c4', TIMESTAMP, DefaultClause('2009-04-05 12:00:00'
                    )),
             Column('c5', TIMESTAMP),
+            Column('c6', TIMESTAMP,
+                   DefaultClause(sql.text("CURRENT_TIMESTAMP "
+                                          "ON UPDATE CURRENT_TIMESTAMP"))),
             )
         def_table.create()
         try:
@@ -780,6 +783,13 @@ class ReflectionTest(TestBase, AssertsExecutionResults):
         assert str(reflected.c.c3.server_default.arg) == "'abc'"
         assert str(reflected.c.c4.server_default.arg) \
             == "'2009-04-05 12:00:00'"
+        assert reflected.c.c5.default is None
+        assert reflected.c.c5.server_default is None
+        assert reflected.c.c6.default is None
+        eq_(
+            str(reflected.c.c6.server_default.arg).upper(),
+            "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
+        )
         reflected.create()
         try:
             reflected2 = Table('mysql_def', MetaData(testing.db),
@@ -791,6 +801,13 @@ class ReflectionTest(TestBase, AssertsExecutionResults):
         assert str(reflected2.c.c3.server_default.arg) == "'abc'"
         assert str(reflected2.c.c4.server_default.arg) \
             == "'2009-04-05 12:00:00'"
+        assert reflected.c.c5.default is None
+        assert reflected.c.c5.server_default is None
+        assert reflected.c.c6.default is None
+        eq_(
+            str(reflected.c.c6.server_default.arg).upper(),
+            "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
+        )
 
     def test_reflection_with_table_options(self):
         comment = r"""Comment types type speedily ' " \ '' Fun!"""