I have a mysql table that is updated through a web page. Some columns are formatted as integer. There will be a mysql error if you try to enter “”, ” “, or any string that cannot be rounded to integer automatically. Instead of editing my PHP to handle these corrections, I would like to make a trigger BEFORE UPDATE on this table that sets the field value to zero if it is an incorrect integer value. In another stack overflow post I found that you could test for integer value using ceil(field) = field. Here is the create trigger syntax:
delimiter|
create trigger before_folding_update before update on daily_folding_report
for each row
begin
if ceil(new.jobnum) != new.jobnum then
set new.jobnum = 0;
end if;
end|
If I put do:
update daily_folding_report set jobnum = 'a'
I still get the error: Incorrect integer value: 'a' for column 'jobnum' at row 1. Does anyone else know how I can accomplish this?
As far as I know, all value checks are done before the triggers. Why aren’t you just doing this in your PHP code?