Works for me
CREATE TABLE employee(name text,editby text);
CREATE TRIGGER update_editby AFTER INSERT ON employee
BEGIN
UPDATE employee SET editby = 'unknown' WHERE editby = '' AND rowid =
new.rowid;
END;
INSERT INTO employee VALUES('Ralph','');
SELECT * FROM employee:
Ralph|unknown
You may be wanting to check for NULL though instead of double tics '' if that's
what you're doing. They're not the same. Double tics is a zero-length string
and NULL is empty.
Then this will work:
CREATE TABLE employee(name text,editby text);
CREATE TRIGGER update_editby AFTER INSERT ON employee
BEGIN
UPDATE employee SET editby = 'unknown' WHERE editby IS NULL AND rowid =
new.rowid;
END;
INSERT INTO employee (name) VALUES('Ralph');
SELECT * FROM employee;
Ralph|unknown
Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Advanced GEOINT Solutions Operating Unit
Northrop Grumman Information Systems
________________________________
From: [email protected] [[email protected]] on
behalf of jwzumwalt [[email protected]]
Sent: Tuesday, December 13, 2011 9:55 AM
To: [email protected]
Subject: EXT :[sqlite] Need trigger
I am attempting to crete a trigger that fills a field with "unknown" if a
update leaves it empty.
the trigger I tried is shown below, but it does not seem to work. Any ideas
what I am doing wrong?
Thanks - JZ
$query = "CREATE TRIGGER update_editby AFTER INSERT ON employee
BEGIN
UPDATE employee SET editby = 'unknown' WHERE editby = '' AND rowid =
new.rowid;
END;
";
--
View this message in context:
http://old.nabble.com/Need-trigger-tp32966496p32966496.html
Sent from the SQLite mailing list archive at Nabble.com.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users