Add some hackery to work around MySQL's strange habit of assigning 0 instead of

the current time when adding a TIMESTAMP column to a table (even if you
explicitly define the TIMESTAMP column with DEFAULT CURRENT_TIMESTAMP).
This commit is contained in:
Michael Bayne
2006-12-11 21:35:05 +00:00
parent 14c8d8cfb2
commit d06b9685dc
@@ -361,6 +361,21 @@ public class DepotMarshaller<T>
} finally { } finally {
stmt.close(); stmt.close();
} }
// 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) {
query = "update " + getTableName() + " set " + fmarsh.getColumnName() + " = NOW()";
log.info("Assigning current time to TIMESTAMP column: " + query);
stmt = conn.createStatement();
try {
stmt.executeUpdate(query);
} finally {
stmt.close();
}
}
} }
// TODO: run any registered hand migrations // TODO: run any registered hand migrations