I'm getting hard time with PhpMyAdmin. My table is :
material(id_item, id_collection,...)
primarey_key(id_item, id_collection).
I want to make a function to prevent loop in Acyclic Graph Database. So i want to force id_collection > id_item for new id_collection.
My function is (i have set //
in SQL tab):
//
CREATE or REPLACE function collections_prevent_cycle()
BEGIN
DECLARE max_of_both SMALLINT;
SET max_of_both := (MAX(GREATEST(id_item, id_collection)) FROM material);
IF NOT EXISTS(SELECT id_collection FROM material where id_collection = NEW.id_collection) THEN
IF (NEW.id_item >= max_of_both) THEN SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'You may not insert items that doesnt exist';
ELSEIF(NEW.id_collection <> max_of_both + 1) THEN SIGNAL'45000'
SET MESSAGE_TEXT = 'You may not insert non stable id_collection';
END IF;
END IF;
RETURN 0;
END;
//
#1064 - 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 'function collections_prevent_cycle() RETURN integer BEGIN DECLARE max_of_b' at line 1
I'm messing with declare but can't get rid off - Anyone could help me plz?
Fixed my first pbm of Delimiter with :