Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 5a7c6bb

Browse files
Adding the three functions version_major(), version_minor(), and version_patch() to return the major, minor (release series), and patch version numbers from the MySQL version string
1 parent a23c6d8 commit 5a7c6bb

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

functions/version_major.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; version 2 of the License.
6+
--
7+
-- This program is distributed in the hope that it will be useful,
8+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
-- GNU General Public License for more details.
11+
--
12+
-- You should have received a copy of the GNU General Public License
13+
-- along with this program; if not, write to the Free Software
14+
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
DROP FUNCTION IF EXISTS version_major;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='root'@'localhost' FUNCTION version_major ()
21+
RETURNS TINYINT UNSIGNED
22+
COMMENT '
23+
Description
24+
-----------
25+
26+
Returns the major version of MySQL Server.
27+
28+
Returns
29+
-----------
30+
31+
TINYINT UNSIGNED
32+
33+
Example
34+
-----------
35+
36+
mysql> SELECT VERSION(), sys.version_major();
37+
+--------------------------------------+---------------------+
38+
| VERSION() | sys.version_major() |
39+
+--------------------------------------+---------------------+
40+
| 5.7.9-enterprise-commercial-advanced | 5 |
41+
+--------------------------------------+---------------------+
42+
1 row in set (0.00 sec)
43+
'
44+
SQL SECURITY INVOKER
45+
NOT DETERMINISTIC
46+
NO SQL
47+
BEGIN
48+
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 1);
49+
END$$
50+
51+
DELIMITER ;

functions/version_minor.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; version 2 of the License.
6+
--
7+
-- This program is distributed in the hope that it will be useful,
8+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
-- GNU General Public License for more details.
11+
--
12+
-- You should have received a copy of the GNU General Public License
13+
-- along with this program; if not, write to the Free Software
14+
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
DROP FUNCTION IF EXISTS version_minor;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='root'@'localhost' FUNCTION version_minor ()
21+
RETURNS TINYINT UNSIGNED
22+
COMMENT '
23+
Description
24+
-----------
25+
26+
Returns the minor (release series) version of MySQL Server.
27+
28+
Returns
29+
-----------
30+
31+
TINYINT UNSIGNED
32+
33+
Example
34+
-----------
35+
36+
mysql> SELECT VERSION(), sys.server_minor();
37+
+--------------------------------------+---------------------+
38+
| VERSION() | sys.version_minor() |
39+
+--------------------------------------+---------------------+
40+
| 5.7.9-enterprise-commercial-advanced | 7 |
41+
+--------------------------------------+---------------------+
42+
1 row in set (0.00 sec)
43+
'
44+
SQL SECURITY INVOKER
45+
NOT DETERMINISTIC
46+
NO SQL
47+
BEGIN
48+
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 2), '.', -1);
49+
END$$
50+
51+
DELIMITER ;

functions/version_patch.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; version 2 of the License.
6+
--
7+
-- This program is distributed in the hope that it will be useful,
8+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
-- GNU General Public License for more details.
11+
--
12+
-- You should have received a copy of the GNU General Public License
13+
-- along with this program; if not, write to the Free Software
14+
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
DROP FUNCTION IF EXISTS version_patch;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='root'@'localhost' FUNCTION version_patch ()
21+
RETURNS TINYINT UNSIGNED
22+
COMMENT '
23+
Description
24+
-----------
25+
26+
Returns the patch release version of MySQL Server.
27+
28+
Returns
29+
-----------
30+
31+
TINYINT UNSIGNED
32+
33+
Example
34+
-----------
35+
36+
mysql> SELECT VERSION(), sys.version_patch();
37+
+--------------------------------------+---------------------+
38+
| VERSION() | sys.version_patch() |
39+
+--------------------------------------+---------------------+
40+
| 5.7.9-enterprise-commercial-advanced | 9 |
41+
+--------------------------------------+---------------------+
42+
1 row in set (0.00 sec)
43+
'
44+
SQL SECURITY INVOKER
45+
NOT DETERMINISTIC
46+
NO SQL
47+
BEGIN
48+
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', -1);
49+
END$$
50+
51+
DELIMITER ;

0 commit comments

Comments
 (0)