labtech
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
LT_CompareVersions
Parameters
Name
Type
Mode
version_1
varchar(255)
IN
version_2
varchar(255)
IN
Definition
BEGIN DECLARE myresult INT(11); DECLARE ver_1_string VARCHAR(255); DECLARE ver_2_string VARCHAR(255); DECLARE ver_1_current_value INT(11); DECLARE ver_2_current_value INT(11); SET @result = 0; SELECT CONCAT(version_1,'.') INTO @ver_1_string; SELECT CONCAT(version_2,'.') INTO @ver_2_string; searchloop: LOOP IF @ver_1_string IS NULL OR LENGTH(@ver_1_string) = 0 THEN SET @ver_1_current_value = -1; ELSE SELECT IFNULL(CONVERT(SUBSTR(@ver_1_string,1,INSTR(@ver_1_string,'.')-1),SIGNED),-1) AS ver_1_current_value INTO @ver_1_current_value; SELECT RIGHT(@ver_1_string,LENGTH(@ver_1_string) - INSTR(@ver_1_string,'.')) AS ver_1_string INTO @ver_1_string; END IF; IF @ver_2_string IS NULL OR LENGTH(@ver_2_string) = 0 THEN SET @ver_2_current_value = -1; ELSE SELECT IFNULL(CONVERT(SUBSTR(@ver_2_string,1,INSTR(@ver_2_string,'.')-1),SIGNED),-1) AS ver_2_current_value INTO @ver_2_current_value; SELECT RIGHT(@ver_2_string,LENGTH(@ver_2_string) - INSTR(@ver_2_string,'.')) AS ver_2_string INTO @ver_2_string; END IF; IF @ver_1_current_value < @ver_2_current_value THEN SET @myresult = -1; LEAVE searchloop; ELSEIF @ver_1_current_value > @ver_2_current_value THEN SET @myresult = 1; LEAVE searchloop; ELSEIF (@ver_1_current_value = -1) AND (@ver_2_current_value = -1) THEN SET @myresult = 0; LEAVE searchloop; END IF; END LOOP searchloop; RETURN @myresult; END