Solved

Trigger Update not working if starts null

Posted on 2014-09-30
1
203 Views
Last Modified: 2014-10-17
If got a simple trigger which is to update a log table (which I unfortunately need), however if the value of `phoneNumber` is its default of Null, when I update it like:-
UPDATE `contract` SET `phoneNumber` = '44464' WHERE `contract`.`priID` = 8;

Open in new window

I dont get a line in the logger, however if I execute again differently so the so OLD.`phoneNumber` isnt null then trigger fires fine and runs the insert command.

My trigger code is:-
Begin
IF OLD.`phoneNumber` <> NEW.`phoneNumber` THEN
             INSERT INTO `mobilephones`.`_logger` (`dateTime`, `connectionID`, `table`, `priID`, `feild`, `newValue`,`action`) VALUES (NOW(), CONNECTION_ID(), 'contract', NEW.`priID`, 'phoneNumber', NEW.`phoneNumber`, 'Update');
END IF; 
End

Open in new window


Any ideas what Im doing wrong?
0
Comment
Question by:tonelm54
1 Comment
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40353211
The article below might shed some light

http://coldfusionbeyond.com/post.cfm/mysql-trigger-flakiness-and-null-in-comparisons

Basically saying that comparing null to null gives null and not 1 (equal).

Not sure if the suggested work around can help but it might give some insight.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now