summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authormalff/marcsql@weblab.(none) <>2006-11-16 09:03:47 -0700
committermalff/marcsql@weblab.(none) <>2006-11-16 09:03:47 -0700
commitccfbd686150ea2a8e738ff2ac8a762c602e8b9a4 (patch)
tree97166381743b2b830ba8d62a7acf0f37382a39ac /mysql-test
parent6b0e7f3e4e8a3275be18eb6f79f3e62ca3fe81a8 (diff)
downloadmariadb-git-ccfbd686150ea2a8e738ff2ac8a762c602e8b9a4.tar.gz
Bug#22684 (BENCHMARK, ENCODE, DECODE and FORMAT are not real functions)
Before this change, the functions BENCHMARK, ENCODE, DECODE and FORMAT could only accept a constant for some parameters. After this change, this restriction has been removed. An implication is that these functions can also be used in prepared statements. The change consist of changing the following classes: - Item_func_benchmark - Item_func_encode - Item_func_decode - Item_func_format to: - only accept Item* in the constructor, - and evaluate arguments during calls to val_xxx() which fits the general design of all the other functions. The 'TODO' items identified in item_create.cc during the work done for Bug 21114 are addressed by this fix, as a natural consequence of aligning the design. In the 'func_str' test, a single very long test line involving an explain extended select with many functions has been rewritten into multiple separate tests, to improve maintainability. The result of explain extended select decode(encode(...)) has changed, since the encode and decode functions now print all their parameters.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/func_str.result337
-rw-r--r--mysql-test/r/parser.result13
-rw-r--r--mysql-test/r/ps.result46
-rw-r--r--mysql-test/t/func_str.test109
-rw-r--r--mysql-test/t/parser.test15
-rw-r--r--mysql-test/t/ps.test35
6 files changed, 524 insertions, 31 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index d85d3eabe5e..9a4ae8c1e67 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -813,11 +813,231 @@ drop table t7;
select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2);
substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2) substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2)
1abcd;2abcd 3abcd;4abcd
-explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"),replace('aaaa','a','b'),insert('txs',2,1,'hi'),left(_latin2'a',1),right(_latin2'a',1),lcase(_latin2'a'),ucase(_latin2'a'),SUBSTR('abcdefg',3,2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),trim(_latin2' a '),ltrim(_latin2' a '),rtrim(_latin2' a '), decode(encode(repeat("a",100000),"monty"),"monty");
+explain extended select md5('hello');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select md5(_latin1'hello') AS `md5('hello')`,sha(_latin1'abc') AS `sha('abc')`,sha(_latin1'abc') AS `sha1('abc')`,soundex(_latin1'') AS `soundex('')`,(soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`,aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`,concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`,reverse(_latin1'abc') AS `reverse('abc')`,rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`,lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`,concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`,make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a',_latin2'b',_latin2'c')`,elt(2,1) AS `elt(2,1)`,locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`,format(130,10) AS `format(130,10)`,char(0) AS `char(0)`,conv(130,16,10) AS `conv(130,16,10)`,hex(130) AS `hex(130)`,cast(_latin1'HE' as char charset binary) AS `binary 'HE'`,export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y',_latin2'n',_latin2' ')`,field((_latin1'b' collate latin1_bin),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`,find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B',_latin1'a,b,c,d')`,collation(conv(130,16,10)) AS `collation(conv(130,16,10))`,coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`,length(_latin1'\n \r\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`,length(_latin1'hello') AS `length('hello')`,char(ascii(_latin1'h')) AS `char(ascii('h'))`,ord(_latin1'h') AS `ord('h')`,quote((1 / 0)) AS `quote(1/0)`,crc32(_latin1'123') AS `crc32("123")`,replace(_latin1'aaaa',_latin1'a',_latin1'b') AS `replace('aaaa','a','b')`,insert(_latin1'txs',2,1,_latin1'hi') AS `insert('txs',2,1,'hi')`,left(_latin2'a',1) AS `left(_latin2'a',1)`,right(_latin2'a',1) AS `right(_latin2'a',1)`,lcase(_latin2'a') AS `lcase(_latin2'a')`,ucase(_latin2'a') AS `ucase(_latin2'a')`,substr(_latin1'abcdefg',3,2) AS `SUBSTR('abcdefg',3,2)`,substring_index(_latin1'1abcd;2abcd;3abcd;4abcd',_latin1';',2) AS `substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2)`,trim(_latin2' a ') AS `trim(_latin2' a ')`,ltrim(_latin2' a ') AS `ltrim(_latin2' a ')`,rtrim(_latin2' a ') AS `rtrim(_latin2' a ')`,decode(encode(repeat(_latin1'a',100000))) AS `decode(encode(repeat("a",100000),"monty"),"monty")`
+Note 1003 select md5(_latin1'hello') AS `md5('hello')`
+explain extended select sha('abc');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select sha(_latin1'abc') AS `sha('abc')`
+explain extended select sha1('abc');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select sha(_latin1'abc') AS `sha1('abc')`
+explain extended select soundex('');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select soundex(_latin1'') AS `soundex('')`
+explain extended select 'mood' sounds like 'mud';
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select (soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`
+explain extended select aes_decrypt(aes_encrypt('abc','1'),'1');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`
+explain extended select concat('*',space(5),'*');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`
+explain extended select reverse('abc');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select reverse(_latin1'abc') AS `reverse('abc')`
+explain extended select rpad('a',4,'1');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`
+explain extended select lpad('a',4,'1');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`
+explain extended select concat_ws(',','',NULL,'a');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`
+explain extended select make_set(255,_latin2'a', _latin2'b', _latin2'c');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a', _latin2'b', _latin2'c')`
+explain extended select elt(2,1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select elt(2,1) AS `elt(2,1)`
+explain extended select locate("a","b",2);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`
+explain extended select format(130,10);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select format(130,10) AS `format(130,10)`
+explain extended select char(0);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select char(0) AS `char(0)`
+explain extended select conv(130,16,10);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select conv(130,16,10) AS `conv(130,16,10)`
+explain extended select hex(130);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select hex(130) AS `hex(130)`
+explain extended select binary 'HE';
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select cast(_latin1'HE' as char charset binary) AS `binary 'HE'`
+explain extended select export_set(255,_latin2'y', _latin2'n', _latin2' ');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y', _latin2'n', _latin2' ')`
+explain extended select FIELD('b' COLLATE latin1_bin,'A','B');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select field((_latin1'b' collate latin1_bin),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`
+explain extended select FIND_IN_SET(_latin1'B', _latin1'a,b,c,d');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B', _latin1'a,b,c,d')`
+explain extended select collation(conv(130,16,10));
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select collation(conv(130,16,10)) AS `collation(conv(130,16,10))`
+explain extended select coercibility(conv(130,16,10));
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`
+explain extended select length('\n\t\r\b\0\_\%\\');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select length(_latin1'\n \r\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`
+explain extended select bit_length('\n\t\r\b\0\_\%\\');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`
+explain extended select bit_length('\n\t\r\b\0\_\%\\');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`
+explain extended select concat('monty',' was here ','again');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`
+explain extended select length('hello');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select length(_latin1'hello') AS `length('hello')`
+explain extended select char(ascii('h'));
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select char(ascii(_latin1'h')) AS `char(ascii('h'))`
+explain extended select ord('h');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select ord(_latin1'h') AS `ord('h')`
+explain extended select quote(1/0);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select quote((1 / 0)) AS `quote(1/0)`
+explain extended select crc32("123");
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select crc32(_latin1'123') AS `crc32("123")`
+explain extended select replace('aaaa','a','b');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select replace(_latin1'aaaa',_latin1'a',_latin1'b') AS `replace('aaaa','a','b')`
+explain extended select insert('txs',2,1,'hi');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select insert(_latin1'txs',2,1,_latin1'hi') AS `insert('txs',2,1,'hi')`
+explain extended select left(_latin2'a',1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select left(_latin2'a',1) AS `left(_latin2'a',1)`
+explain extended select right(_latin2'a',1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select right(_latin2'a',1) AS `right(_latin2'a',1)`
+explain extended select lcase(_latin2'a');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select lcase(_latin2'a') AS `lcase(_latin2'a')`
+explain extended select ucase(_latin2'a');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select ucase(_latin2'a') AS `ucase(_latin2'a')`
+explain extended select SUBSTR('abcdefg',3,2);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select substr(_latin1'abcdefg',3,2) AS `SUBSTR('abcdefg',3,2)`
+explain extended select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select substring_index(_latin1'1abcd;2abcd;3abcd;4abcd',_latin1';',2) AS `substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2)`
+explain extended select trim(_latin2' a ');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select trim(_latin2' a ') AS `trim(_latin2' a ')`
+explain extended select ltrim(_latin2' a ');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select ltrim(_latin2' a ') AS `ltrim(_latin2' a ')`
+explain extended select rtrim(_latin2' a ');
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select rtrim(_latin2' a ') AS `rtrim(_latin2' a ')`
+explain extended select decode(encode(repeat("a",100000),"monty"),"monty");
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select decode(encode(repeat(_latin1'a',100000),_latin1'monty'),_latin1'monty') AS `decode(encode(repeat("a",100000),"monty"),"monty")`
SELECT lpad(12345, 5, "#");
lpad(12345, 5, "#")
12345
@@ -1148,4 +1368,117 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
DROP TABLE t1,t2;
+select encode(NULL, NULL);
+encode(NULL, NULL)
+NULL
+select encode("data", NULL);
+encode("data", NULL)
+NULL
+select encode(NULL, "password");
+encode(NULL, "password")
+NULL
+select decode(NULL, NULL);
+decode(NULL, NULL)
+NULL
+select decode("data", NULL);
+decode("data", NULL)
+NULL
+select decode(NULL, "password");
+decode(NULL, "password")
+NULL
+select format(NULL, NULL);
+format(NULL, NULL)
+NULL
+select format(pi(), NULL);
+format(pi(), NULL)
+NULL
+select format(NULL, 2);
+format(NULL, 2)
+NULL
+select benchmark(NULL, NULL);
+benchmark(NULL, NULL)
+NULL
+select benchmark(0, NULL);
+benchmark(0, NULL)
+0
+select benchmark(100, NULL);
+benchmark(100, NULL)
+0
+select benchmark(NULL, 1+1);
+benchmark(NULL, 1+1)
+NULL
+set @password="password";
+set @my_data="clear text to encode";
+select md5(encode(@my_data, "password"));
+md5(encode(@my_data, "password"))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, _utf8 "password"));
+md5(encode(@my_data, _utf8 "password"))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, binary "password"));
+md5(encode(@my_data, binary "password"))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, _latin1 "password"));
+md5(encode(@my_data, _latin1 "password"))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, _koi8r "password"));
+md5(encode(@my_data, _koi8r "password"))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, (select "password" from dual)));
+md5(encode(@my_data, (select "password" from dual)))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, concat("pass", "word")));
+md5(encode(@my_data, concat("pass", "word")))
+44320fd2b4a0ec92faa2da2122def917
+select md5(encode(@my_data, @password));
+md5(encode(@my_data, @password))
+44320fd2b4a0ec92faa2da2122def917
+set @my_data="binary encoded data";
+select md5(decode(@my_data, "password"));
+md5(decode(@my_data, "password"))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, _utf8 "password"));
+md5(decode(@my_data, _utf8 "password"))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, binary "password"));
+md5(decode(@my_data, binary "password"))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, _latin1 "password"));
+md5(decode(@my_data, _latin1 "password"))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, _koi8r "password"));
+md5(decode(@my_data, _koi8r "password"))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, (select "password" from dual)));
+md5(decode(@my_data, (select "password" from dual)))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, concat("pass", "word")));
+md5(decode(@my_data, concat("pass", "word")))
+5bea8c394368dbc03b76684483b7756b
+select md5(decode(@my_data, @password));
+md5(decode(@my_data, @password))
+5bea8c394368dbc03b76684483b7756b
+set @dec=5;
+select format(pi(), (1+1));
+format(pi(), (1+1))
+3.14
+select format(pi(), (select 3 from dual));
+format(pi(), (select 3 from dual))
+3.142
+select format(pi(), @dec);
+format(pi(), @dec)
+3.14159
+set @bench_count=10;
+select benchmark(10, pi());
+benchmark(10, pi())
+0
+select benchmark(5+5, pi());
+benchmark(5+5, pi())
+0
+select benchmark((select 10 from dual), pi());
+benchmark((select 10 from dual), pi())
+0
+select benchmark(@bench_count, pi());
+benchmark(@bench_count, pi())
+0
End of 5.0 tests
diff --git a/mysql-test/r/parser.result b/mysql-test/r/parser.result
index afd78561898..df446e01601 100644
--- a/mysql-test/r/parser.result
+++ b/mysql-test/r/parser.result
@@ -296,11 +296,6 @@ select atan();
ERROR 42000: Incorrect parameter count in the call to native function 'atan'
select atan2(1, 2, 3);
ERROR 42000: Incorrect parameter count in the call to native function 'atan2'
-select benchmark(10, 1+1);
-benchmark(10, 1+1)
-0
-select benchmark(5+5, 2);
-ERROR 42000: Incorrect parameters in the call to native function 'BENCHMARK'
select concat();
ERROR 42000: Incorrect parameter count in the call to native function 'concat'
select concat("foo");
@@ -310,11 +305,6 @@ select concat_ws();
ERROR 42000: Incorrect parameter count in the call to native function 'concat_ws'
select concat_ws("foo");
ERROR 42000: Incorrect parameter count in the call to native function 'concat_ws'
-set @pwd="my password";
-select encode("secret", @pwd);
-ERROR 42000: Incorrect parameters in the call to native function 'ENCODE'
-select decode("encoded-secret", @pwd);
-ERROR 42000: Incorrect parameters in the call to native function 'DECODE'
select encrypt();
ERROR 42000: Incorrect parameter count in the call to native function 'encrypt'
select encrypt(1, 2, 3);
@@ -339,9 +329,6 @@ select field();
ERROR 42000: Incorrect parameter count in the call to native function 'field'
select field("p1");
ERROR 42000: Incorrect parameter count in the call to native function 'field'
-set @dec=2;
-select format(pi(), @dec);
-ERROR 42000: Incorrect parameters in the call to native function 'FORMAT'
select from_unixtime();
ERROR 42000: Incorrect parameter count in the call to native function 'from_unixtime'
select from_unixtime(1, 2, 3);
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 617e289d30d..753fde8ccab 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -2391,3 +2391,49 @@ Level Code Message
Note 1051 Unknown table 't1'
Note 1051 Unknown table 't2'
deallocate prepare abc;
+set @my_password="password";
+set @my_data="clear text to encode";
+prepare stmt1 from 'select decode(encode(?, ?), ?)';
+execute stmt1 using @my_data, @my_password, @my_password;
+decode(encode(?, ?), ?)
+clear text to encode
+set @my_data="more text to encode";
+execute stmt1 using @my_data, @my_password, @my_password;
+decode(encode(?, ?), ?)
+more text to encode
+set @my_password="new password";
+execute stmt1 using @my_data, @my_password, @my_password;
+decode(encode(?, ?), ?)
+more text to encode
+deallocate prepare stmt1;
+set @to_format="123456789.123456789";
+set @dec=0;
+prepare stmt2 from 'select format(?, ?)';
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+123,456,789
+set @dec=4;
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+123,456,789.1235
+set @dec=6;
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+123,456,789.123457
+set @dec=2;
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+123,456,789.12
+set @to_format="100";
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+100.00
+set @to_format="1000000";
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+1,000,000.00
+set @to_format="10000";
+execute stmt2 using @to_format, @dec;
+format(?, ?)
+10,000.00
+deallocate prepare stmt2;
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index 45415882ac7..d4620e6059b 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -460,7 +460,51 @@ drop table t7;
select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2);
-explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"),replace('aaaa','a','b'),insert('txs',2,1,'hi'),left(_latin2'a',1),right(_latin2'a',1),lcase(_latin2'a'),ucase(_latin2'a'),SUBSTR('abcdefg',3,2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),trim(_latin2' a '),ltrim(_latin2' a '),rtrim(_latin2' a '), decode(encode(repeat("a",100000),"monty"),"monty");
+explain extended select md5('hello');
+explain extended select sha('abc');
+explain extended select sha1('abc');
+explain extended select soundex('');
+explain extended select 'mood' sounds like 'mud';
+explain extended select aes_decrypt(aes_encrypt('abc','1'),'1');
+explain extended select concat('*',space(5),'*');
+explain extended select reverse('abc');
+explain extended select rpad('a',4,'1');
+explain extended select lpad('a',4,'1');
+explain extended select concat_ws(',','',NULL,'a');
+explain extended select make_set(255,_latin2'a', _latin2'b', _latin2'c');
+explain extended select elt(2,1);
+explain extended select locate("a","b",2);
+explain extended select format(130,10);
+explain extended select char(0);
+explain extended select conv(130,16,10);
+explain extended select hex(130);
+explain extended select binary 'HE';
+explain extended select export_set(255,_latin2'y', _latin2'n', _latin2' ');
+explain extended select FIELD('b' COLLATE latin1_bin,'A','B');
+explain extended select FIND_IN_SET(_latin1'B', _latin1'a,b,c,d');
+explain extended select collation(conv(130,16,10));
+explain extended select coercibility(conv(130,16,10));
+explain extended select length('\n\t\r\b\0\_\%\\');
+explain extended select bit_length('\n\t\r\b\0\_\%\\');
+explain extended select bit_length('\n\t\r\b\0\_\%\\');
+explain extended select concat('monty',' was here ','again');
+explain extended select length('hello');
+explain extended select char(ascii('h'));
+explain extended select ord('h');
+explain extended select quote(1/0);
+explain extended select crc32("123");
+explain extended select replace('aaaa','a','b');
+explain extended select insert('txs',2,1,'hi');
+explain extended select left(_latin2'a',1);
+explain extended select right(_latin2'a',1);
+explain extended select lcase(_latin2'a');
+explain extended select ucase(_latin2'a');
+explain extended select SUBSTR('abcdefg',3,2);
+explain extended select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2);
+explain extended select trim(_latin2' a ');
+explain extended select ltrim(_latin2' a ');
+explain extended select rtrim(_latin2' a ');
+explain extended select decode(encode(repeat("a",100000),"monty"),"monty");
#
# lpad returns incorrect result (Bug #2182)
@@ -780,4 +824,67 @@ SELECT * FROM t1 INNER JOIN t2 ON code=id
DROP TABLE t1,t2;
+#
+# Bug#22684: The Functions ENCODE, DECODE and FORMAT are not real functions
+#
+
+select encode(NULL, NULL);
+select encode("data", NULL);
+select encode(NULL, "password");
+
+select decode(NULL, NULL);
+select decode("data", NULL);
+select decode(NULL, "password");
+
+select format(NULL, NULL);
+select format(pi(), NULL);
+select format(NULL, 2);
+
+select benchmark(NULL, NULL);
+select benchmark(0, NULL);
+select benchmark(100, NULL);
+select benchmark(NULL, 1+1);
+
+#
+# Please note:
+# 1) The collation of the password is irrelevant, the encryption uses
+# the binary representation of the string without charset/collation.
+# 2) These tests can not print the encoded text directly, because it's binary,
+# and doing this would cause problems with source control.
+# Instead, an md5() checksum is used, to verify the result indirectly.
+# 3) Each md5() result must be identical.
+# 4) The md5() result must never change, and must be stable across releases.
+#
+set @password="password";
+set @my_data="clear text to encode";
+select md5(encode(@my_data, "password"));
+select md5(encode(@my_data, _utf8 "password"));
+select md5(encode(@my_data, binary "password"));
+select md5(encode(@my_data, _latin1 "password"));
+select md5(encode(@my_data, _koi8r "password"));
+select md5(encode(@my_data, (select "password" from dual)));
+select md5(encode(@my_data, concat("pass", "word")));
+select md5(encode(@my_data, @password));
+
+set @my_data="binary encoded data";
+select md5(decode(@my_data, "password"));
+select md5(decode(@my_data, _utf8 "password"));
+select md5(decode(@my_data, binary "password"));
+select md5(decode(@my_data, _latin1 "password"));
+select md5(decode(@my_data, _koi8r "password"));
+select md5(decode(@my_data, (select "password" from dual)));
+select md5(decode(@my_data, concat("pass", "word")));
+select md5(decode(@my_data, @password));
+
+set @dec=5;
+select format(pi(), (1+1));
+select format(pi(), (select 3 from dual));
+select format(pi(), @dec);
+
+set @bench_count=10;
+select benchmark(10, pi());
+select benchmark(5+5, pi());
+select benchmark((select 10 from dual), pi());
+select benchmark(@bench_count, pi());
+
--echo End of 5.0 tests
diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test
index 11af7c691d8..39c8d8e2bf4 100644
--- a/mysql-test/t/parser.test
+++ b/mysql-test/t/parser.test
@@ -399,11 +399,6 @@ select atan();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select atan2(1, 2, 3);
-select benchmark(10, 1+1);
-
--- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
-select benchmark(5+5, 2);
-
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select concat();
select concat("foo");
@@ -413,12 +408,6 @@ select concat_ws();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select concat_ws("foo");
-set @pwd="my password";
--- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
-select encode("secret", @pwd);
--- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
-select decode("encoded-secret", @pwd);
-
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select encrypt();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
@@ -448,10 +437,6 @@ select field();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select field("p1");
-set @dec=2;
--- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
-select format(pi(), @dec);
-
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select from_unixtime();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index 1a19355406a..e5333fce538 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -2414,3 +2414,38 @@ execute abc;
drop table if exists t1, t2;
execute abc;
deallocate prepare abc;
+
+#
+# Bug#22684: The Functions ENCODE, DECODE and FORMAT are not real functions
+#
+
+set @my_password="password";
+set @my_data="clear text to encode";
+
+prepare stmt1 from 'select decode(encode(?, ?), ?)';
+execute stmt1 using @my_data, @my_password, @my_password;
+set @my_data="more text to encode";
+execute stmt1 using @my_data, @my_password, @my_password;
+set @my_password="new password";
+execute stmt1 using @my_data, @my_password, @my_password;
+deallocate prepare stmt1;
+
+set @to_format="123456789.123456789";
+set @dec=0;
+
+prepare stmt2 from 'select format(?, ?)';
+execute stmt2 using @to_format, @dec;
+set @dec=4;
+execute stmt2 using @to_format, @dec;
+set @dec=6;
+execute stmt2 using @to_format, @dec;
+set @dec=2;
+execute stmt2 using @to_format, @dec;
+set @to_format="100";
+execute stmt2 using @to_format, @dec;
+set @to_format="1000000";
+execute stmt2 using @to_format, @dec;
+set @to_format="10000";
+execute stmt2 using @to_format, @dec;
+deallocate prepare stmt2;
+