If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help me! big problem with dynamic SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-09, 05:26
alibabasakura alibabasakura is offline
Registered User
 
Join Date: Mar 2009
Posts: 3
Help me! big problem with dynamic SQL

Hi all,

I'm have a procedure:

Quote:
DROP PROCEDURE IF EXISTS sp_UpdateMetaArticle;
delimiter $$
CREATE PROCEDURE sp_UpdateMetaArticle(IN meta_key varchar(255), IN meta_value varchar(255), IN post_id integer)
BEGIN
SET @sql = concat('UPDATE do_articles SET ', meta_key, '=? WHERE PostId=?');
PREPARE stmp FROM @sql;
EXECUTE stmp USING @meta_value, @post_id;
DEALLOCATE PREPARE stmp;
END;
And a trigger

Quote:
DROP TRIGGER IF EXISTS tg_PostMetaUpdate;
delimiter $$
CREATE TRIGGER tg_PostMetaUpdate AFTER UPDATE ON wp_postmeta
FOR EACH ROW BEGIN
CALL sp_UpdateMetaArticle(NEW.meta_key, NEW.meta_value, NEW.post_id);
END;
........and my problem:

When have update in table postmeta => run tg_PostMetaUpdate

.. but no run dynamic SQL

Quote:
SET @sql = concat('UPDATE do_articles SET ', meta_key, '=? WHERE PostId=?');
PREPARE stmp FROM @sql;
EXECUTE stmp USING @meta_value, @post_id;
DEALLOCATE PREPARE stmp;
But, run procedure by phpMyAdmin

Quote:
CALL sp_UpdateMetaArticle('Description', 'Vnexpress.net', 12);
Is ok

I want run procedure in trigger

Help me!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On