This TriggerAdapter updates the LASTMODIFIED column of the inserted or updated
row:
@Override
public void fire(Connection conn, ResultSet oldRow, ResultSet newRow)
throws SQLException {
if (newRow == null ) return; // This is a DELETE
PreparedStatement statement = conn.prepareStatement(
"update " + schemaName + "." + tableName +
" set LASTMODIFIED = current_timestamp()" +
" where ID = ?"
);
// TODO: This assumes the PK column is named "ID"
Long id = newRow.getLong("ID");
statement.setLong(1, id);
statement.execute();
}
I get an infinite loop when statement.execute() is called, the trigger is fired
again for the timestamp update, and so on. I'm not sure I can come up with a
flag to detect the re-entry of the trigger code. Is there a safe way to modify
the "current" state in a trigger?
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.