I have a simple MySQL function for comparing versions:
CREATE FUNCTION `compareVersions` (
versionA VARCHAR(50),
versionB VARCHAR(50)) RETURNS INT DETERMINISTIC NO SQL
BEGIN
DECLARE a1 INT;
DECLARE b1 INT;
DECLARE c1 INT;
DECLARE d1 INT;
DECLARE a2 INT;
DECLARE b2 INT;
DECLARE c2 INT;
DECLARE d2 INT; SET a1 = SUBSTRING_INDEX( `versionA` , '.', 1 );
SET b1 = SUBSTRING_INDEX(SUBSTRING_INDEX( `versionA` , '.', 2 ),'.',-1);
SET c1 = SUBSTRING_INDEX(SUBSTRING_INDEX( `versionA` , '.', -2 ),'.',1);
SET d1 = SUBSTRING_INDEX( `versionA` , '.', -1 );
SET a2 = SUBSTRING_INDEX( `versionB` , '.', 1 );
SET b2 = SUBSTRING_INDEX(SUBSTRING_INDEX( `versionB` , '.', 2 ),'.',-1);
SET c2 = SUBSTRING_INDEX(SUBSTRING_INDEX( `versionB` , '.', -2 ),'.',1);
SET d2 = SUBSTRING_INDEX( `versionB` , '.', -1 );
IF (a1 > a2) THEN
RETURN -1;
ELSEIF ((a1 = a2) AND (b1 > b2)) THEN
RETURN -1;
ELSEIF ((a1 = a2) AND (b1 = b2) AND (c1 > c2)) THEN
RETURN -1;
ELSEIF ((a1 = a2) AND (b1 = b2) AND (c1 = c2) AND (d1 > d2)) THEN
RETURN -1;
ELSEIF ((a1 = a2) AND (b1 = b2) AND (c1 = c2) AND (d1 = d2)) THEN
RETURN 0;
ELSE
RETURN 1;
END IF;
END $$
and its creation fails with
You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
This is almost the same as this question, but my function does not read any SQL data, it is simple, deterministic and I see no reason why it should require any extra privileges. It is not clear to me from the documentation if the SUPER privilege is required for creating all functions (which would be ridiculous, making stored functions unavailable to many users, everyone who does not have access to their database configuration). I do not even know if the function works, this was the first thing that came to mind, but the syntax should be correct (the delimiter is set in PHPMyAdmin). Getting all data from database and comparing them in the PHP application can be done, but I think it is easiest done this way. Is it possible? Does anybody have a better solution for comparing versions?