From 2896b256ec78ed3bd978ba1982a004a99d4811e8 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 20 Feb 2007 02:17:56 +0000 Subject: [PATCH] Do the same magic for DATETIME that we do when adding a TIMESTAMP column. --- .../com/samskivert/jdbc/depot/DepotMarshaller.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index da8a302..bc8ecd2 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -745,13 +745,15 @@ public class DepotMarshaller log.info("Adding column to " + getTableName() + ": " + coldef); ctx.invoke(new Modifier.Simple(query)); - // if the column is a TIMESTAMP column, we need to run a special query to update all - // existing rows to the current time because MySQL annoyingly assigns them a default - // value of "0000-00-00 00:00:00" regardless of whether we explicitly provide a - // "DEFAULT" value for the column or not - if (coldef.toLowerCase().indexOf(" timestamp") != -1) { + // if the column is a TIMESTAMP or DATETIME column, we need to run a special query to + // update all existing rows to the current time because MySQL annoyingly assigns + // TIMESTAMP columns a value of "0000-00-00 00:00:00" regardless of whether we + // explicitly provide a "DEFAULT" value for the column or not, and DATETIME columns + // cannot accept CURRENT_TIME or NOW() defaults at all. + if (coldef.toLowerCase().indexOf(" timestamp") != -1 || + coldef.toLowerCase().indexOf(" datetime") != -1) { query = "update " + getTableName() + " set " + fmarsh.getColumnName() + " = NOW()"; - log.info("Assigning current time to TIMESTAMP column: " + query); + log.info("Assigning current time to column: " + query); ctx.invoke(new Modifier.Simple(query)); } }