Do the same magic for DATETIME that we do when adding a TIMESTAMP column.

This commit is contained in:
Michael Bayne
2007-02-20 02:17:56 +00:00
parent 7fa2a1a2b8
commit 2896b256ec
@@ -745,13 +745,15 @@ public class DepotMarshaller<T extends PersistentRecord>
log.info("Adding column to " + getTableName() + ": " + coldef); log.info("Adding column to " + getTableName() + ": " + coldef);
ctx.invoke(new Modifier.Simple(query)); ctx.invoke(new Modifier.Simple(query));
// if the column is a TIMESTAMP column, we need to run a special query to update all // if the column is a TIMESTAMP or DATETIME column, we need to run a special query to
// existing rows to the current time because MySQL annoyingly assigns them a default // update all existing rows to the current time because MySQL annoyingly assigns
// value of "0000-00-00 00:00:00" regardless of whether we explicitly provide a // TIMESTAMP columns a value of "0000-00-00 00:00:00" regardless of whether we
// "DEFAULT" value for the column or not // explicitly provide a "DEFAULT" value for the column or not, and DATETIME columns
if (coldef.toLowerCase().indexOf(" timestamp") != -1) { // 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()"; 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)); ctx.invoke(new Modifier.Simple(query));
} }
} }