MySQL Forums
Forum List  »  MySQL Workbench

Conditional Not Working in Script
Posted by: Eric Salsbury
Date: September 16, 2009 11:24AM

I have written an update script that is supposed to check individual revision numbers and apply the revisions to a database if they do not exist. The conditional statements are not working, however. I can't seem to figure out what I am doing wrong with it. Even a simple IF 1 = 1 THEN select * from revisions; END IF; statement fails on running. Here is the script:

SET @cur_rev_num = 0;

SET @description = NULL;



-- UPDATE 1 - (PLACE DESCRIPTION HERE) COPY AND PASTE BELOW CODE TO PRIOR TO EDITTING CURRENT REVISION

SET @cur_rev_num := 1; -- REPLACE THIS VALUE WITH CURRENT UPDATE NUMBER

SET @description := "REPLACE THIS WITH DESCRIPTION";

IF (SELECT COUNT(revision_number) FROM revisions WHERE revision_number = @cur_rev_num) = 0 THEN

--PLACE UPDATE CODE HERE
INSERT INTO users (username, password) values ('joe', 'blow');

INSERT INTO revisions (revision_number, description, committed_on) VALUES(@cur_rev_num, @description, NOW());

END IF;

The error I am getting when I run this script is:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF (SELECT COUNT(revision_number) FROM revisions WHERE revision_number = @cur_re' at line 1

Can anyone shed some light on why no conditional statement seems to be working currently?

Thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
Conditional Not Working in Script
5111
September 16, 2009 11:24AM
2638
September 17, 2009 09:12AM
2596
September 21, 2009 12:24AM


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.