This mode can be used to disable warnings for functions whose use is
strongly discouraged because of inherent limitations in the functionality
they provide. But the use of which can be needed for backwards compatibility
with legacy applications, and which cannot easily be replaced by the user.
Currently used for weak encryption functions ENCODE()/DECODE(), to help
users who need these functions to access existing data encoded with this
non-standard algorithm.
Signed-off-by: Kristian Nielsen <knielsen(a)knielsen-hq.org>
---
mysql-test/main/func_str.result | 4 ++++
mysql-test/main/func_str.test | 2 ++
mysql-test/main/mysqld--help.result | 2 +-
mysql-test/suite/sys_vars/r/old_mode_basic.result | 4 ++--
.../sys_vars/r/sysvars_server_notembedded.result | 2 +-
mysql-test/suite/sys_vars/t/old_mode_basic.test | 2 +-
sql/item_strfunc.cc | 11 ++++++++++-
sql/sql_class.h | 1 +
sql/sys_vars.cc | 3 ++-
9 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result
index 8c09d19cc44..725ce2b7c46 100644
--- a/mysql-test/main/func_str.result
+++ b/mysql-test/main/func_str.result
@@ -323,6 +323,10 @@ decode(encode("abcdef","monty"),"monty")="abcdef"
Warnings:
Warning 1287 'encode' is deprecated and will be removed in a future release
Warning 1287 'decode' is deprecated and will be removed in a future release
+SET STATEMENT old_mode= 'COMPAT_DISCOURAGED'
+ FOR select decode(encode("abcdef","monty"),"monty")="abcdef";
+decode(encode("abcdef","monty"),"monty")="abcdef"
+1
select quote('\'\"\\test');
quote('\'\"\\test')
'\'"\\test'
diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test
index feb3057ec41..e4b572a7f3f 100644
--- a/mysql-test/main/func_str.test
+++ b/mysql-test/main/func_str.test
@@ -142,6 +142,8 @@ select least(1,2,3) | greatest(16,32,8), least(5,4)*1,greatest(-1.0,1.0)*1,least
select decode(encode(repeat("a",100000),"monty"),"monty")=repeat("a",100000);
--enable_view_protocol
select decode(encode("abcdef","monty"),"monty")="abcdef";
+SET STATEMENT old_mode= 'COMPAT_DISCOURAGED'
+ FOR select decode(encode("abcdef","monty"),"monty")="abcdef";
select quote('\'\"\\test');
select quote(concat('abc\'', '\\cba'));
diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result
index 6dc8543f225..0d5d2daade5 100644
--- a/mysql-test/main/mysqld--help.result
+++ b/mysql-test/main/mysqld--help.result
@@ -706,7 +706,7 @@ The following specify which files/extra groups are read (specified before remain
NO_DUP_KEY_WARNINGS_WITH_IGNORE, NO_PROGRESS_INFO,
ZERO_DATE_TIME_CAST, UTF8_IS_UTF8MB3,
IGNORE_INDEX_ONLY_FOR_JOIN, COMPAT_5_1_CHECKSUM,
- LOCK_ALTER_TABLE_COPY
+ LOCK_ALTER_TABLE_COPY, COMPAT_DISCOURAGED
--old-passwords Use old password encryption method (needed for 4.0 and
older clients)
--old-style-user-limits
diff --git a/mysql-test/suite/sys_vars/r/old_mode_basic.result b/mysql-test/suite/sys_vars/r/old_mode_basic.result
index 7701bc6bbfa..3032a82581b 100644
--- a/mysql-test/suite/sys_vars/r/old_mode_basic.result
+++ b/mysql-test/suite/sys_vars/r/old_mode_basic.result
@@ -132,8 +132,8 @@ Warning 1287 'ZERO_DATE_TIME_CAST' is deprecated and will be removed in a future
SELECT @@global.old_mode;
@@global.old_mode
ZERO_DATE_TIME_CAST
-SET @@global.old_mode = 128;
-ERROR 42000: Variable 'old_mode' can't be set to the value of '128'
+SET @@global.old_mode = 256;
+ERROR 42000: Variable 'old_mode' can't be set to the value of '256'
SELECT @@global.old_mode;
@@global.old_mode
ZERO_DATE_TIME_CAST
diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
index 0f4c54bb217..a48dd2dafe1 100644
--- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
+++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
@@ -2459,7 +2459,7 @@ VARIABLE_COMMENT Used to emulate old behavior from earlier MariaDB or MySQL vers
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
-ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,LOCK_ALTER_TABLE_COPY
+ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,LOCK_ALTER_TABLE_COPY,COMPAT_DISCOURAGED
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME OLD_PASSWORDS
diff --git a/mysql-test/suite/sys_vars/t/old_mode_basic.test b/mysql-test/suite/sys_vars/t/old_mode_basic.test
index cb18796729e..c3fc4c57189 100644
--- a/mysql-test/suite/sys_vars/t/old_mode_basic.test
+++ b/mysql-test/suite/sys_vars/t/old_mode_basic.test
@@ -172,7 +172,7 @@ SET @@global.old_mode = 4;
SELECT @@global.old_mode;
--Error ER_WRONG_VALUE_FOR_VAR
-SET @@global.old_mode = 128;
+SET @@global.old_mode = 256;
SELECT @@global.old_mode;
# use of decimal values
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 4b96271c331..339430a2794 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2720,7 +2720,16 @@ bool Item_func_encode::seed()
hash_password(rand_nr, key->ptr(), key->length());
sql_crypt.init(rand_nr);
- warn_deprecated<1103>(current_thd, func_name_cstring().str);
+ if (!(current_thd->variables.old_behavior & OLD_MODE_COMPAT_DISCOURAGED))
+ {
+ /*
+ This function should not be removed despite the deprecation warning.
+ That would cause problems for users who can then no longer access
+ columns in their database that might have been inserted as
+ ENCODE(str,pass_str).
+ */
+ warn_deprecated<1103>(current_thd, func_name_cstring().str);
+ }
return FALSE;
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 28c2831cfee..ff730ec2297 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -203,6 +203,7 @@ enum enum_binlog_row_image {
#define OLD_MODE_IGNORE_INDEX_ONLY_FOR_JOIN (1 << 4)
#define OLD_MODE_COMPAT_5_1_CHECKSUM (1 << 5)
#define OLD_MODE_LOCK_ALTER_TABLE_COPY (1 << 6)
+#define OLD_MODE_COMPAT_DISCOURAGED (1 << 7)
#define OLD_MODE_DEFAULT_VALUE OLD_MODE_UTF8_IS_UTF8MB3
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index e25d293bbb7..18d08996aa8 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3863,12 +3863,13 @@ static const char *old_mode_names[]=
"IGNORE_INDEX_ONLY_FOR_JOIN", // deprecated since 11.3
"COMPAT_5_1_CHECKSUM", // deprecated since 11.3
"LOCK_ALTER_TABLE_COPY", // deprecated since 11.3
+ "COMPAT_DISCOURAGED",
0
};
void old_mode_deprecated_warnings(THD *thd, ulonglong v)
{
- v &= ~OLD_MODE_DEFAULT_VALUE;
+ v &= ~(OLD_MODE_DEFAULT_VALUE | OLD_MODE_COMPAT_DISCOURAGED);
for (uint i=0; old_mode_names[i]; i++)
if ((1ULL<<i) & v)
{
--
2.30.2