So, I finally decided to learn how to use stored procedures, and although I have their work, I'm not sure if I am doing this correctly. the best way. So here is what I have.
Three procedures: TryAddTag, CheckTagExists and AddTag.
TryAddTag is a procedure that is my intermediary between other code (like PHP, etc.) and two other procedures, so this is the call that is called.
TryAddTag
DELIMITER // CREATE PROCEDURE TryAddTag( IN tagName VARCHAR(255) ) BEGIN
Addtag
DELIMITER // CREATE PROCEDURE AddTag( IN tagName VARCHAR(255) ) BEGIN INSERT INTO tags VALUES( NULL, tagName ); END // DELIMITER ;
CheckTagExists
DELIMITER // CREATE PROCEDURE CheckTagExists( IN tagName VARCHAR(255), OUT doesTagExist BOOL ) BEGIN
My concerns stem from this and using @doesTagExist.
-- Check if tag already exists CALL CheckTagExists(tagName, @doesTagExist);
Is one of these variables used correctly? And / or, how can I use the DECLARE'd variable to store the result of CheckTagExists in TryAddTag? I was expecting something like
... DECLARE doesTagExist BOOL; SET doesTagExist = CheckTagExist('str'); ...
or something like that...
sql mysql stored-procedures
Dan
source share