]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove MySQL UTC_TIMESTAMP rule
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 13 Apr 2017 14:11:41 +0000 (10:11 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 13 Apr 2017 14:44:00 +0000 (10:44 -0400)
Removed an ancient and unnecessary intercept of the UTC_TIMESTAMP
MySQL function, which was getting in the way of using it with a
parameter.

Change-Id: I6e6b52c051418bcb9d31987e78299310810cb78d
Fixes: #3966
(cherry picked from commit c0b85ad6ad1df2497a95c87d837c32d87f17291f)

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_compiler.py
test/dialect/mysql/test_dialect.py

index 423a7342aa8ece2758017fc9830991a549e5d2a0..169c7636029c518bd6c8d7043bdd8397e9faf17c 100644 (file)
 .. changelog::
     :version: 1.1.10
 
+    .. change:: 3966
+        :tags: bug, mysql
+        :tickets: 3966
+
+        Removed an ancient and unnecessary intercept of the UTC_TIMESTAMP
+        MySQL function, which was getting in the way of using it with a
+        parameter.
+
     .. change:: 3961
         :tags: bug, mysql
         :tickets: 3961
index 3f06fa81fa75ca36630255100cd2a573902d4791..9a1ec8553379b47e6f1144e981a25b249ae8739e 100644 (file)
@@ -799,9 +799,6 @@ class MySQLCompiler(compiler.SQLCompiler):
     def visit_random_func(self, fn, **kw):
         return "rand%s" % self.function_argspec(fn)
 
-    def visit_utc_timestamp_func(self, fn, **kw):
-        return "UTC_TIMESTAMP"
-
     def visit_sysdate_func(self, fn, **kw):
         return "SYSDATE()"
 
index be5f002e3ad1e7d5304aa6f998632371d2a950f0..3c33f540c0266029dc97f26c0250537daffcb7b4 100644 (file)
@@ -336,7 +336,12 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
         )
 
     def test_utc_timestamp(self):
-        self.assert_compile(func.utc_timestamp(), "UTC_TIMESTAMP")
+        self.assert_compile(func.utc_timestamp(), "utc_timestamp()")
+
+    def test_utc_timestamp_fsp(self):
+        self.assert_compile(
+            func.utc_timestamp(5), "utc_timestamp(%s)",
+            checkparams={"utc_timestamp_1": 5})
 
     def test_sysdate(self):
         self.assert_compile(func.sysdate(), "SYSDATE()")
index cf8712e04cd1cea61da94d0e3ea1ab36cd253123..e6bff35530d35aa8635c70a9ee3c10218254ef13 100644 (file)
@@ -126,6 +126,87 @@ class DialectTest(fixtures.TestBase):
             assert c.execute('SELECT @@tx_isolation;').scalar() == mysql_value
 
 
+class RemoveUTCTimestampTest(fixtures.TablesTest):
+    """This test exists because we removed the MySQL dialect's
+    override of the UTC_TIMESTAMP() function, where the commit message
+    for this feature stated that "it caused problems with executemany()".
+    Since no example was provided, we are trying lots of combinations
+    here.
+
+    [ticket:3966]
+
+    """
+    __only_on__ = 'mysql'
+    __backend__ = True
+
+    @classmethod
+    def define_tables(cls, metadata):
+        Table(
+            't', metadata,
+            Column('id', Integer, primary_key=True),
+            Column('x', Integer),
+            Column('data', DateTime)
+        )
+
+        Table(
+            't_default', metadata,
+            Column('id', Integer, primary_key=True),
+            Column('x', Integer),
+            Column('idata', DateTime, default=func.utc_timestamp()),
+            Column('udata', DateTime, onupdate=func.utc_timestamp())
+        )
+
+    def test_insert_executemany(self):
+        with testing.db.connect() as conn:
+            conn.execute(
+                self.tables.t.insert().values(data=func.utc_timestamp()),
+                [{"x": 5}, {"x": 6}, {"x": 7}]
+            )
+
+    def test_update_executemany(self):
+        with testing.db.connect() as conn:
+            timestamp = datetime.datetime(2015, 4, 17, 18, 5, 2)
+            conn.execute(
+                self.tables.t.insert(),
+                [
+                    {"x": 5, "data": timestamp},
+                    {"x": 6, "data": timestamp},
+                    {"x": 7, "data": timestamp}]
+            )
+
+            conn.execute(
+                self.tables.t.update().
+                values(data=func.utc_timestamp()).
+                where(self.tables.t.c.x == bindparam('xval')),
+                [{"xval": 5}, {"xval": 6}, {"xval": 7}]
+            )
+
+    def test_insert_executemany_w_default(self):
+        with testing.db.connect() as conn:
+            conn.execute(
+                self.tables.t_default.insert(),
+                [{"x": 5}, {"x": 6}, {"x": 7}]
+            )
+
+    def test_update_executemany_w_default(self):
+        with testing.db.connect() as conn:
+            timestamp = datetime.datetime(2015, 4, 17, 18, 5, 2)
+            conn.execute(
+                self.tables.t_default.insert(),
+                [
+                    {"x": 5, "idata": timestamp},
+                    {"x": 6, "idata": timestamp},
+                    {"x": 7, "idata": timestamp}]
+            )
+
+            conn.execute(
+                self.tables.t_default.update().
+                values(idata=func.utc_timestamp()).
+                where(self.tables.t_default.c.x == bindparam('xval')),
+                [{"xval": 5}, {"xval": 6}, {"xval": 7}]
+            )
+
+
 class SQLModeDetectionTest(fixtures.TestBase):
     __only_on__ = 'mysql'
     __backend__ = True