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).


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1996 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2006-12-11 21:35:05 +00:00
parent 4635caadea
commit 9288bebaec
@@ -361,6 +361,21 @@ public class DepotMarshaller<T>
} finally {
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