I'm trying to get IF and ELSE statements to work. I've written:-
SET AUTOCOMMIT = 0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
SELECT @ip := `ip` FROM `ip_list` WHERE `ip`='1.1.1.1';
IF @ip != '1.1.1.1' THEN
INSERT INTO `ip_list` ( `ip` ) VALUES( '1.1.1.1' );
END IF;
COMMIT;
I get the normal error ".... for the right syntax to use near 'IF @ip...';
Why isn't this working? I know that this example is similar to ON DUPLICATE KEY UPDATE, but I don't want to use that. Why doesn't mysql like my if? The documents page leaves a little to be desired:-
http://dev.mysql.com/doc/refman/5.0/en/if-statement.html
Lyle
P.S. Update, this does not work either:-
SET AUTOCOMMIT = 0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
SELECT @ip := `ip` FROM `ip_list` WHERE `ip`='1.1.1.1';
INSERT INTO `ip_list` ( `ip` ) VALUES( '1.1.1.1' ) IF ( @ip != '1.1.1.1' );
RETURN @ip;
COMMIT;
Edited 2 time(s). Last edit at 07/29/2008 10:02AM by Lyle Hopkins.