Solved

Trigger Update not working if starts null

Posted on 2014-09-30
1
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 56

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
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://…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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