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

Commit 339d268

Browse files
committed
Merge branch 'development' of https://github.com/MarkLeith/mysql-sys into development
2 parents 0ef8e3d + 8e774d9 commit 339d268

File tree

10 files changed

+261
-0
lines changed

10 files changed

+261
-0
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* Added a new `ps_thread_trx_info()` stored function which outputs, for a given thread id, the transactions, and statements that those transactions have executed, as a JSON object
3030
* Added new `list_add()` and `list_drop()` stored functions, that take a string csv list, and either add or remove items from that list respectively. Can be used to easily update variables that take such lists, like `sql_mode`.
3131
* The `ps_thread_id` stored function now returns the thread id for the current connection if NULL is passed for the in_connection_id parameter
32+
* Added a new `version_major()` stored function, which returns the major version of MySQL Server
33+
* Added a new `version_minor()` stored function, which returns the miner (release series) version of MySQL Server
34+
* Added a new `version_patch()` stored function, which returns the patch release version of MySQL Server
3235

3336
### Bug Fixes
3437

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,6 +4085,69 @@ IF (@sys.statement_truncate_len IS NULL) THEN
40854085
END IF;
40864086
```
40874087
4088+
#### version_major
4089+
4090+
##### Description
4091+
4092+
Returns the major version of MySQL Server.
4093+
4094+
##### Returns
4095+
4096+
TINYINT UNSIGNED
4097+
4098+
##### Example
4099+
```SQL
4100+
mysql> SELECT VERSION(), sys.version_major();
4101+
+--------------------------------------+---------------------+
4102+
| VERSION() | sys.version_major() |
4103+
+--------------------------------------+---------------------+
4104+
| 5.7.9-enterprise-commercial-advanced | 5 |
4105+
+--------------------------------------+---------------------+
4106+
1 row in set (0.00 sec)
4107+
```
4108+
4109+
#### version_minor
4110+
4111+
##### Description
4112+
4113+
Returns the minor (release series) version of MySQL Server.
4114+
4115+
##### Returns
4116+
4117+
TINYINT UNSIGNED
4118+
4119+
##### Example
4120+
```SQL
4121+
mysql> SELECT VERSION(), sys.server_minor();
4122+
+--------------------------------------+---------------------+
4123+
| VERSION() | sys.version_minor() |
4124+
+--------------------------------------+---------------------+
4125+
| 5.7.9-enterprise-commercial-advanced | 7 |
4126+
+--------------------------------------+---------------------+
4127+
1 row in set (0.00 sec)
4128+
```
4129+
4130+
#### version_patch
4131+
4132+
##### Description
4133+
4134+
Returns the patch release version of MySQL Server.
4135+
4136+
##### Returns
4137+
4138+
TINYINT UNSIGNED
4139+
4140+
##### Example
4141+
```SQL
4142+
mysql> SELECT VERSION(), sys.version_patch();
4143+
+--------------------------------------+---------------------+
4144+
| VERSION() | sys.version_patch() |
4145+
+--------------------------------------+---------------------+
4146+
| 5.7.9-enterprise-commercial-advanced | 9 |
4147+
+--------------------------------------+---------------------+
4148+
1 row in set (0.00 sec)
4149+
```
4150+
40884151
40894152
### Procedures
40904153

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 ;

mysql-test/suite/sysschema/r/all_sys_objects_exist.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ ps_thread_id FUNCTION
123123
ps_thread_stack FUNCTION
124124
ps_thread_trx_info FUNCTION
125125
sys_get_config FUNCTION
126+
version_major FUNCTION
127+
version_minor FUNCTION
128+
version_patch FUNCTION
126129
create_synonym_db PROCEDURE
127130
diagnostics PROCEDURE
128131
execute_prepared_stmt PROCEDURE
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SELECT sys.version_major();
2+
SELECT sys.version_minor();
3+
SELECT sys.version_patch();
4+
SELECT @my_version = SUBSTRING(VERSION(), 1, CHAR_LENGTH(@my_version));
5+
@my_version = SUBSTRING(VERSION(), 1, CHAR_LENGTH(@my_version))
6+
1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
########### suite/sysschema/t/version_functions.test #############
2+
# #
3+
# Testing of the sys.version_major(), sys.version_minor(), #
4+
# and sys.version_patch() functions #
5+
# #
6+
# Creation: #
7+
# 2015-08-14 jkrogh Implement this test #
8+
# #
9+
##################################################################
10+
11+
-- source include/not_embedded.inc
12+
13+
# Sanity check - the functions should not return any warnings or errors
14+
--disable_result_log
15+
SELECT sys.version_major();
16+
SELECT sys.version_minor();
17+
SELECT sys.version_patch();
18+
--enable_result_log
19+
20+
# Check that concatenating the three version parts gives the beginning of the output of VERSION()
21+
# This is not truly an independent test, but there isn't really anywhere else to get the actual version,
22+
# so it at least verifies that the three parts go back together in the right way.
23+
let $MY_VERSION=`SELECT CONCAT(sys.version_major(), '.', sys.version_minor(), '.', sys.version_patch())`;
24+
--disable_query_log ONCE
25+
eval SET @my_version = '$MY_VERSION';
26+
27+
SELECT @my_version = SUBSTRING(VERSION(), 1, CHAR_LENGTH(@my_version));

sys_56.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ SOURCE ./functions/ps_thread_id.sql
3838
SOURCE ./functions/ps_thread_account.sql
3939
SOURCE ./functions/ps_thread_stack.sql
4040
SOURCE ./functions/sys_get_config.sql
41+
SOURCE ./functions/version_major.sql
42+
SOURCE ./functions/version_minor.sql
43+
SOURCE ./functions/version_patch.sql
4144

4245
SOURCE ./views/i_s/innodb_buffer_stats_by_schema.sql
4346
SOURCE ./views/i_s/x_innodb_buffer_stats_by_schema.sql

sys_57.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ SOURCE ./functions/ps_thread_account.sql
3939
SOURCE ./functions/ps_thread_stack.sql
4040
SOURCE ./functions/ps_thread_trx_info.sql
4141
SOURCE ./functions/sys_get_config.sql
42+
SOURCE ./functions/version_major.sql
43+
SOURCE ./functions/version_minor.sql
44+
SOURCE ./functions/version_patch.sql
4245

4346
SOURCE ./views/i_s/innodb_buffer_stats_by_schema.sql
4447
SOURCE ./views/i_s/x_innodb_buffer_stats_by_schema.sql

0 commit comments

Comments
 (0)