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

Commit 5f17b5c

Browse files
committed
Merge pull request #93 from MarkLeith/development
Release 1.5.0
2 parents e9413d9 + 5454b99 commit 5f17b5c

File tree

171 files changed

+8249
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+8249
-662
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gen/

NEWS.md

Lines changed: 90 additions & 30 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1283 additions & 177 deletions
Large diffs are not rendered by default.

before_setup.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ SET sql_log_bin = 0;
2020
CREATE DATABASE IF NOT EXISTS sys DEFAULT CHARACTER SET utf8;
2121

2222
USE sys;
23-
24-
CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'root'@'localhost' SQL SECURITY INVOKER VIEW version AS SELECT '1.4.0' AS sys_version, version() AS mysql_version;

functions/format_bytes.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ BEGIN
7777
ELSEIF bytes >= 1073741824 THEN RETURN CONCAT(ROUND(bytes / 1073741824, 2), ' GiB');
7878
ELSEIF bytes >= 1048576 THEN RETURN CONCAT(ROUND(bytes / 1048576, 2), ' MiB');
7979
ELSEIF bytes >= 1024 THEN RETURN CONCAT(ROUND(bytes / 1024, 2), ' KiB');
80-
ELSE RETURN CONCAT(bytes, ' bytes');
80+
ELSE RETURN CONCAT(ROUND(bytes, 0), ' bytes');
8181
END IF;
8282
END$$
8383

functions/format_path.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ DROP FUNCTION IF EXISTS format_path;
1818
DELIMITER $$
1919

2020
CREATE DEFINER='root'@'localhost' FUNCTION format_path (
21-
path VARCHAR(260)
21+
path VARCHAR(512)
2222
)
23-
RETURNS VARCHAR(260) CHARSET UTF8
23+
RETURNS VARCHAR(512) CHARSET UTF8
2424
COMMENT '
2525
Description
2626
-----------
@@ -34,13 +34,13 @@ CREATE DEFINER='root'@'localhost' FUNCTION format_path (
3434
Parameters
3535
-----------
3636
37-
path (VARCHAR(260)):
37+
path (VARCHAR(512)):
3838
The raw file path value to format.
3939
4040
Returns
4141
-----------
4242
43-
VARCHAR(260) CHARSET UTF8
43+
VARCHAR(512) CHARSET UTF8
4444
4545
Example
4646
-----------
@@ -65,7 +65,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION format_path (
6565
DETERMINISTIC
6666
NO SQL
6767
BEGIN
68-
DECLARE v_path VARCHAR(260);
68+
DECLARE v_path VARCHAR(512);
6969
DECLARE v_undo_dir VARCHAR(1024);
7070

7171
-- OSX hides /private/ in variables, but Performance Schema does not

functions/format_path_57.sql

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 format_path;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='root'@'localhost' FUNCTION format_path (
21+
path VARCHAR(512)
22+
)
23+
RETURNS VARCHAR(512) CHARSET UTF8
24+
COMMENT '
25+
Description
26+
-----------
27+
28+
Takes a raw path value, and strips out the datadir or tmpdir
29+
replacing with @@datadir and @@tmpdir respectively.
30+
31+
Also normalizes the paths across operating systems, so backslashes
32+
on Windows are converted to forward slashes
33+
34+
Parameters
35+
-----------
36+
37+
path (VARCHAR(512)):
38+
The raw file path value to format.
39+
40+
Returns
41+
-----------
42+
43+
VARCHAR(512) CHARSET UTF8
44+
45+
Example
46+
-----------
47+
48+
mysql> select @@datadir;
49+
+-----------------------------------------------+
50+
| @@datadir |
51+
+-----------------------------------------------+
52+
| /Users/mark/sandboxes/SmallTree/AMaster/data/ |
53+
+-----------------------------------------------+
54+
1 row in set (0.06 sec)
55+
56+
mysql> select format_path(\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\') AS path;
57+
+--------------------------+
58+
| path |
59+
+--------------------------+
60+
| @@datadir/mysql/proc.MYD |
61+
+--------------------------+
62+
1 row in set (0.03 sec)
63+
'
64+
SQL SECURITY INVOKER
65+
DETERMINISTIC
66+
NO SQL
67+
BEGIN
68+
DECLARE v_path VARCHAR(512);
69+
DECLARE v_undo_dir VARCHAR(1024);
70+
71+
-- OSX hides /private/ in variables, but Performance Schema does not
72+
IF path LIKE '/private/%'
73+
THEN SET v_path = REPLACE(path, '/private', '');
74+
ELSE SET v_path = path;
75+
END IF;
76+
77+
-- @@global.innodb_undo_directory is only set when separate undo logs are used
78+
SET v_undo_dir = IFNULL((SELECT VARIABLE_NAME FROM performance_schema.global_variables WHERE VARIABLE_NAME = 'innodb_undo_directory'), '');
79+
80+
IF v_path IS NULL THEN RETURN NULL;
81+
ELSEIF v_path LIKE CONCAT(@@global.datadir, '%') ESCAPE '|' THEN
82+
RETURN REPLACE(REPLACE(REPLACE(v_path, @@global.datadir, '@@datadir/'), '\\\\', ''), '\\', '/');
83+
ELSEIF v_path LIKE CONCAT(@@global.tmpdir, '%') ESCAPE '|' THEN
84+
RETURN REPLACE(REPLACE(REPLACE(v_path, @@global.tmpdir, '@@tmpdir/'), '\\\\', ''), '\\', '/');
85+
ELSEIF v_path LIKE CONCAT(@@global.slave_load_tmpdir, '%') ESCAPE '|' THEN
86+
RETURN REPLACE(REPLACE(REPLACE(v_path, @@global.slave_load_tmpdir, '@@slave_load_tmpdir/'), '\\\\', ''), '\\', '/');
87+
ELSEIF v_path LIKE CONCAT(@@global.innodb_data_home_dir, '%') ESCAPE '|' THEN
88+
RETURN REPLACE(REPLACE(REPLACE(v_path, @@global.innodb_data_home_dir, '@@innodb_data_home_dir/'), '\\\\', ''), '\\', '/');
89+
ELSEIF v_path LIKE CONCAT(@@global.innodb_log_group_home_dir, '%') ESCAPE '|' THEN
90+
RETURN REPLACE(REPLACE(REPLACE(v_path, @@global.innodb_log_group_home_dir, '@@innodb_log_group_home_dir/'), '\\\\', ''), '\\', '/');
91+
ELSEIF v_path LIKE CONCAT(v_undo_dir, '%') ESCAPE '|' THEN
92+
RETURN REPLACE(REPLACE(REPLACE(v_path, v_undo_dir, '@@innodb_undo_directory/'), '\\\\', ''), '\\', '/');
93+
ELSE RETURN v_path;
94+
END IF;
95+
END$$
96+
97+
DELIMITER ;

functions/format_statement.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION format_statement (
2525
Description
2626
-----------
2727
28-
Formats a normalized statement, truncating it if it\'s > 64 characters long by default.
28+
Formats a normalized statement, truncating it if it is > 64 characters long by default.
2929
3030
To configure the length to truncate the statement to by default, update the `statement_truncate_len`
3131
variable with `sys_config` table to a different value. Alternatively, to change it just for just

functions/list_add.sql

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- Copyright (c) 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 list_add;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='root'@'localhost' FUNCTION list_add (
21+
in_list TEXT,
22+
in_add_value TEXT
23+
)
24+
RETURNS TEXT
25+
COMMENT '
26+
Description
27+
-----------
28+
29+
Takes a list, and a value to add to the list, and returns the resulting list.
30+
31+
Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.
32+
33+
Parameters
34+
-----------
35+
36+
in_list (TEXT):
37+
The comma separated list to add a value to
38+
39+
in_add_value (TEXT):
40+
The value to add to the input list
41+
42+
Returns
43+
-----------
44+
45+
TEXT
46+
47+
Example
48+
--------
49+
50+
mysql> select @@sql_mode;
51+
+-----------------------------------------------------------------------------------+
52+
| @@sql_mode |
53+
+-----------------------------------------------------------------------------------+
54+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
55+
+-----------------------------------------------------------------------------------+
56+
1 row in set (0.00 sec)
57+
58+
mysql> set sql_mode = sys.list_add(@@sql_mode, ''ANSI_QUOTES'');
59+
Query OK, 0 rows affected (0.06 sec)
60+
61+
mysql> select @@sql_mode;
62+
+-----------------------------------------------------------------------------------------------+
63+
| @@sql_mode |
64+
+-----------------------------------------------------------------------------------------------+
65+
| ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
66+
+-----------------------------------------------------------------------------------------------+
67+
1 row in set (0.00 sec)
68+
69+
'
70+
SQL SECURITY INVOKER
71+
DETERMINISTIC
72+
CONTAINS SQL
73+
BEGIN
74+
75+
IF (in_add_value IS NULL) THEN
76+
SIGNAL SQLSTATE '02200'
77+
SET MESSAGE_TEXT = 'Function sys.list_add: in_add_value input variable should not be NULL',
78+
MYSQL_ERRNO = 1138;
79+
END IF;
80+
81+
IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN
82+
-- return the new value as a single value list
83+
RETURN in_add_value;
84+
END IF;
85+
86+
RETURN (SELECT CONCAT(TRIM(BOTH ',' FROM TRIM(in_list)), ',', in_add_value));
87+
88+
END$$
89+
90+
DELIMITER ;

functions/list_drop.sql

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
-- Copyright (c) 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 list_drop;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='root'@'localhost' FUNCTION list_drop (
21+
in_list TEXT,
22+
in_drop_value TEXT
23+
)
24+
RETURNS TEXT
25+
COMMENT '
26+
Description
27+
-----------
28+
29+
Takes a list, and a value to attempt to remove from the list, and returns the resulting list.
30+
31+
Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.
32+
33+
Parameters
34+
-----------
35+
36+
in_list (TEXT):
37+
The comma separated list to drop a value from
38+
39+
in_drop_value (TEXT):
40+
The value to drop from the input list
41+
42+
Returns
43+
-----------
44+
45+
TEXT
46+
47+
Example
48+
--------
49+
50+
mysql> select @@sql_mode;
51+
+-----------------------------------------------------------------------------------------------+
52+
| @@sql_mode |
53+
+-----------------------------------------------------------------------------------------------+
54+
| ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
55+
+-----------------------------------------------------------------------------------------------+
56+
1 row in set (0.00 sec)
57+
58+
mysql> set sql_mode = sys.list_drop(@@sql_mode, ''ONLY_FULL_GROUP_BY'');
59+
Query OK, 0 rows affected (0.03 sec)
60+
61+
mysql> select @@sql_mode;
62+
+----------------------------------------------------------------------------+
63+
| @@sql_mode |
64+
+----------------------------------------------------------------------------+
65+
| ANSI_QUOTES,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
66+
+----------------------------------------------------------------------------+
67+
1 row in set (0.00 sec)
68+
69+
'
70+
SQL SECURITY INVOKER
71+
DETERMINISTIC
72+
CONTAINS SQL
73+
BEGIN
74+
75+
IF (in_drop_value IS NULL) THEN
76+
SIGNAL SQLSTATE '02200'
77+
SET MESSAGE_TEXT = 'Function sys.list_drop: in_drop_value input variable should not be NULL',
78+
MYSQL_ERRNO = 1138;
79+
END IF;
80+
81+
IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN
82+
-- return the list as it was passed in
83+
RETURN in_list;
84+
END IF;
85+
86+
-- ensure that leading / trailing commas are remove, support values with either spaces or not between commas
87+
RETURN (SELECT TRIM(BOTH ',' FROM REPLACE(REPLACE(CONCAT(',', in_list), CONCAT(',', in_drop_value), ''), CONCAT(', ', in_drop_value), '')));
88+
89+
END$$
90+
91+
DELIMITER ;

0 commit comments

Comments
 (0)