MySQL Forums
Forum List  »  Triggers

Cant do anything in a trigger
Posted by: t rela
Date: May 28, 2012 07:21AM

Hi

I have a simpe trigger which islisted below

Delimiter $$
CREATE TRIGGER chk_post_insert BEFORE INSERT ON wp_posts
FOR EACH ROW BEGIN
IF NEW.post_author = 1 AND NEW.post_type != 'page' THEN
INSERT INTO WP_DUP_POSTS (post_author , post_date , post_date_gmt , post_content ,
post_title, post_excerpt , post_status, comment_status, ping_status ,
post_password , post_name , to_ping, pinged , post_modified , post_modified_gmt ,
post_content_filtered , post_parent, guid , post_type , post_mime_type )
VALUES( NEW.post_author,NEW.post_date ,NEW.post_date_gmt , NEW.post_content, NEW.post_title, NEW.post_excerpt, NEW.post_status, NEW.comment_status,NEW.ping_status,NEW.post_password,NEW.post_name, NEW.to_ping, NEW.pinged, NEW.post_modified, NEW.post_modified_gmt , NEW.post_content_filtered, NEW.post_parent, NEW.guid, NEW.post_type, NEW.post_mime_type);
SET NEW.post_status = 'trash';
END IF;
END $$
Delimiter ;
First of all, it gives error at line 1, After removing the "Delimiter " and its corresponding line, it is giving error at line 3 which is
IF NEW.post_author = 1 AND NEW.post_type != 'page' THEN
I changed this to
IF NEW.post_author = 1 THEN
then it is giving an error at insert statement. I cant even declare a variable anywhere inside the trigger with the statemnt DECLARE changed int. Error is pointing at that line. Cant user strcmp expression. My SQL version is 5.0.91.

I changed the whole trigger to the following code. Still the error is pointing at line 3.

CREATE TRIGGER chk_post_insert BEFORE INSERT ON `wp_posts`
FOR EACH ROW
BEGIN
IF ( NEW.post_author = 0 OR NEW.post_author = 1 ) THEN

SET NEW.post_status := 'trash';

END IF;

END ;
What am i doing wrong?



Edited 2 time(s). Last edit at 05/28/2012 07:27AM by t rela.

Options: ReplyQuote


Subject
Views
Written By
Posted
Cant do anything in a trigger
2255
May 28, 2012 07:21AM
1081
May 29, 2012 10:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.