x
1
BEGIN
2
DECLARE myresult INT(11);
3
4
5
DECLARE ver_1_string VARCHAR(255);
6
DECLARE ver_2_string VARCHAR(255);
7
DECLARE ver_1_current_value INT(11);
8
DECLARE ver_2_current_value INT(11);
9
10
SET @result = 0;
11
12
13
SELECT CONCAT(version_1,'.') INTO @ver_1_string;
14
SELECT CONCAT(version_2,'.') INTO @ver_2_string;
15
16
searchloop: LOOP
17
18
19
IF @ver_1_string IS NULL OR LENGTH(@ver_1_string) = 0 THEN
20
SET @ver_1_current_value = -1;
21
ELSE
22
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;
23
SELECT RIGHT(@ver_1_string,LENGTH(@ver_1_string) - INSTR(@ver_1_string,'.')) AS ver_1_string INTO @ver_1_string;
24
END IF;
25
26
IF @ver_2_string IS NULL OR LENGTH(@ver_2_string) = 0 THEN
27
SET @ver_2_current_value = -1;
28
ELSE
29
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;
30
SELECT RIGHT(@ver_2_string,LENGTH(@ver_2_string) - INSTR(@ver_2_string,'.')) AS ver_2_string INTO @ver_2_string;
31
END IF;
32
33
IF @ver_1_current_value < @ver_2_current_value THEN
34
SET @myresult = -1;
35
LEAVE searchloop;
36
ELSEIF @ver_1_current_value > @ver_2_current_value THEN
37
SET @myresult = 1;
38
LEAVE searchloop;
39
ELSEIF (@ver_1_current_value = -1) AND (@ver_2_current_value = -1) THEN
40
SET @myresult = 0;
41
LEAVE searchloop;
42
END IF;
43
44
END LOOP searchloop;
45
RETURN @myresult;
46
END