1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#Get deafult engine value
--let $DEFAULT_ENGINE = `select @@global.default_storage_engine`
--disable_warnings
drop table if exists t1;
--enable_warnings
set names latin1;
#
# If it's BLOB or BINARY or VARBINARY, then output = input.
#
select hex(weight_string(0x010203));
#
# "AS CHAR ( int )" causes padding on the right. The pad
# character is always space, that is, 0x20 or 0x0020.
# The padding occurs before the conversion to a weight.
# The value of "int" is the number of characters, not the number of bytes.
#
select hex(weight_string('aa' as char(3)));
#
# The minimum value of 'int' is 1.
#
--error 1064
select hex(weight_string('a' as char(-1)));
--error 1064
select hex(weight_string('a' as char(0)));
select hex(weight_string('a' as char(1)));
#
# If 'int' is smaller than the length of 'string',
# truncation will occur with no warning.
#
select hex(weight_string('ab' as char(1)));
#
# If "AS CHAR ( int )" is omitted, there is no padding and no truncation.
#
select hex(weight_string('ab'));
#
# "AS BINARY ( int )" is like CHAR(int) but causes padding of 0x00
# so one doesn't have to use "CAST(string AS BINARY(int))".
#
select hex(weight_string('aa' as binary(3)));
select hex(weight_string(cast('aa' as binary(3))));
#
# If the result length is less than or equal to the
# maximum possible length for the VARBINARY data type,
# then the result data type is VARBINARY. Otherwise
# the result data type is BLOB.
#
create table t1 charset latin1 select weight_string('test') as w;
#Replace default engine value with static engine string
--replace_result $DEFAULT_ENGINE ENGINE
show create table t1;
drop table t1;
create table t1 charset latin1 select weight_string(repeat('t',66000)) as w;
#Replace default engine value with static engine string
--replace_result $DEFAULT_ENGINE ENGINE
show create table t1;
drop table t1;
#
# If input is NULL, then output is NULL.
#
select weight_string(NULL);
#
# WEIGHT_STRING and REVERSE will not be a new reserved word.
#
select 1 as weight_string, 2 as reverse;
#
# Check that collation derivation is copied from the argument
#
select coercibility(weight_string('test'));
select coercibility(weight_string('test' collate latin1_swedish_ci));
#
# Bug#33663 Character sets: weight_string function,
# varchar column, wrong result
#
create table t1 (s1 varchar(5)) charset latin1;
insert into t1 values ('a'),(null);
select hex(weight_string(s1)) from t1 order by s1;
drop table t1;
--echo #
--echo # BUG#11898467 - SERVER CRASHES ON SELECT HEX(WEIGHT_STRING(STR AS [CHAR|BINARY](N))) IF N IS BIG
--echo #
--source include/count_sessions.inc
SET GLOBAL max_allowed_packet=1024;
connect (con1,localhost,root,,);
SELECT HEX(WEIGHT_STRING('ab' AS CHAR(1000000)));
SELECT HEX(WEIGHT_STRING('ab' AS BINARY(1000000)));
connection default;
disconnect con1;
SET GLOBAL max_allowed_packet=default;
--echo #
--echo # BUG#21974321: WEIGHT_STRING RESULT IS WRONG IF USED IN A
--echo # VIEW (AS CHAR CLAUSE IS LOST)
--echo #
SET NAMES utf8;
SET collation_connection=utf16_unicode_ci;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin2 COLLATE latin2_czech_cs);
INSERT INTO t1 VALUES ('abcd');
INSERT INTO t1 VALUES ('dcba');
CREATE VIEW v1 AS SELECT WEIGHT_STRING(_latin1 'ab') AS b;
CREATE VIEW v5 AS SELECT WEIGHT_STRING(a AS BINARY(2)) AS b FROM t1;
CREATE VIEW v6 AS SELECT WEIGHT_STRING(a AS BINARY(6)) AS b FROM t1;
SHOW CREATE VIEW v1;
SHOW CREATE VIEW v5;
SHOW CREATE VIEW v6;
DROP VIEW v1;
DROP VIEW v5;
DROP VIEW v6;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10)) charset latin1;
INSERT INTO t1 VALUES ('abcd');
INSERT INTO t1 VALUES ('dcba');
CREATE VIEW v1 AS SELECT WEIGHT_STRING(_latin1 'ab') AS b;
CREATE VIEW v2 AS SELECT WEIGHT_STRING(a) AS b FROM t1;
CREATE VIEW v3 AS SELECT WEIGHT_STRING(a AS CHAR(2)) AS b FROM t1;
CREATE VIEW v4 AS SELECT WEIGHT_STRING(a AS CHAR(6)) AS b FROM t1;
CREATE VIEW v5 AS SELECT WEIGHT_STRING(a AS BINARY(2)) AS b FROM t1;
CREATE VIEW v6 AS SELECT WEIGHT_STRING(a AS BINARY(6)) AS b FROM t1;
SHOW CREATE VIEW v1;
SHOW CREATE VIEW v2;
SHOW CREATE VIEW v3;
SHOW CREATE VIEW v4;
SHOW CREATE VIEW v5;
SHOW CREATE VIEW v6;
SELECT HEX(b) FROM v1;
SELECT HEX(WEIGHT_STRING(_latin1 'ab'));
SELECT HEX(b) FROM v2;
SELECT HEX(b) FROM v3;
SELECT HEX(b) FROM v4;
SELECT HEX(b) FROM v5;
SELECT HEX(WEIGHT_STRING(a AS BINARY(2))) FROM t1;
SELECT HEX(b) FROM v6;
SELECT HEX(WEIGHT_STRING(a AS BINARY(6))) FROM t1;
DROP VIEW v1;
DROP VIEW v2;
DROP VIEW v3;
DROP VIEW v4;
DROP VIEW v5;
DROP VIEW v6;
DROP TABLE t1;
--echo #
--echo # BUG#27752619: ASSERTION FAILED: SRC WEIGHT_STRING IN
--echo # MY_STRNXFRM_UNICODE_FULL_BIN
--echo #
SELECT HEX(WEIGHT_STRING(JSON_UNQUOTE(JSON_SET('{}','$',''))));
--echo #
--echo # Bug #30898753: DISTINCT(HEX(WEIGHT_STRING(CH))) CUT RESULT OFF
--echo #
CREATE TABLE t1 ( ch VARCHAR(1) COLLATE latin2_czech_cs );
INSERT INTO t1 VALUES (0x4F);
SELECT DISTINCT HEX(WEIGHT_STRING(ch)) FROM t1;
DROP TABLE t1;
--echo #
--echo # Bug #32744772 REGRESSION: TRIM CRASHES IN STRING::LENGTH
--echo #
# Other tests in this file use latin1
SET NAMES DEFAULT;
--error ER_CANNOT_CONVERT_STRING
DO ltrim(weight_string(1));
--error ER_CANNOT_CONVERT_STRING
DO rtrim(weight_string(1));
SET NAMES latin1;
|