IF statement
Posted by:
didaniman
Date: July 29, 2005 12:18AM
Lectori salutem (hail reader)
After about five hours trying, I still can't get this statement to work, I hope anyone can help me with this:
SET @i := 0;
SELECT @i := `id` FROM `files` WHERE `name` LIKE 'readme.txt%' AND `path` LIKE '/docs/%';
CASE
WHEN @i = NULL THEN INSERT INTO `files` (`name`, `path`, `server`, `dir`, `timestamp`, `size`) VALUES ('readme.txt', '/docs/%', '1', 'no', NOW(), 0)
WHEN @i > 0 UPDATE `files` SET `timestamp` = NOW() where `id` = @i
END CASE;
Or this, for that matter:
SET @i := 0;
SELECT @i := `id` FROM `files` WHERE `name` LIKE 'readme.txt%' AND `path` LIKE '/docs/%';
IF @i > 0 THEN UPDATE `files` SET `timestamp` = NOW() where `id` = @i
ELSE
INSERT INTO `files` (`name`, `path`, `server`, `dir`, `timestamp`, `size`) VALUES ('readme.txt', '/docs/%', '1', 'no', NOW(), 0)
END IF;
Or, if anyone get's the point of this statement, and has another method, please post as well.
Thanks in advance,
Daan Meijer