variable_get as a mysql function

Here is how you can get an integer variable to be reused in a trigger or a stored procedure:

DELIMITER //
CREATE FUNCTION variable_get(name_asked VARCHAR(255)) RETURNS INT
DETERMINISTIC
BEGIN
  DECLARE v INT;
  SELECT TRIM(BOTH '"' FROM TRIM(TRAILING ';' FROM SUBSTRING_INDEX(value, ':', -1))) INTO v
    FROM variable
    WHERE name = name_asked;
RETURN v;
END //
DELIMITER ;

This mostly works for strings too but if there are quotes in the beginning of the string it will fail. SUBSTRING(SUBSTRING_INDEX(value, ':', 2), 3) contains the length of string -- you can work from there.

 
 

Drupal is a registered trademark of Dries Buytaert.