MySQL Conditional Trigger
| From: | Dee Ayy | Date: | Fri, 31 Oct 2008 16:09:15 +0000 |
| Subject: | MySQL Conditional Trigger | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-45576@lists.php.net to get a copy of this message | ||
I don't think my trigger likes a comparison with a variable which is
NULL. The docs seem to have a few interesting variations on playing
with NULL and I was hoping someone would just throw me a fish so I
don't have to try every permutation (possibly using CASE, IFNULL,
etc.).
If my ShipDate (which is a date datatype which can be NULL) changes to
a non-null value, I want my IF statement to evaluate to TRUE.
IF NULL changes to aDate : TRUE
IF aDate changes to aDifferentDate : TRUE
IF anyDate changes to NULL : FALSE
In my trigger I have:
...
IF OLD.ShipDate != NEW.ShipDate AND NEW.ShipDate IS NOT NULL THEN
...
Which only works when ShipDate was not NULL to begin with.
I suppose it evaluates the following to FALSE
IF NULL != '2008-10-31' AND '2008-10-31' IS NOT NULL THEN
(not liking the "NULL != '2008-10-31'" part)
Please give me the correct syntax.
TIA