Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
071aece9
Commit
071aece9
authored
Nov 13, 2017
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-14376 Explicit CAST(CHAR(N)) erroneously escalates warnings to errors in STRICT_ALL_TABLES
parent
06117977
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
269 additions
and
4 deletions
+269
-4
mysql-test/r/cast.result
mysql-test/r/cast.result
+109
-0
mysql-test/t/cast.test
mysql-test/t/cast.test
+137
-0
sql/item_timefunc.cc
sql/item_timefunc.cc
+4
-1
sql/item_timefunc.h
sql/item_timefunc.h
+9
-2
sql/sql_type.cc
sql/sql_type.cc
+9
-1
sql/sql_type.h
sql/sql_type.h
+1
-0
No files found.
mysql-test/r/cast.result
View file @
071aece9
No preview for this file type
mysql-test/t/cast.test
View file @
071aece9
...
...
@@ -587,3 +587,140 @@ SHOW CREATE TABLE t1;
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
SET
sql_mode
=
DEFAULT
;
--
echo
#
--
echo
# MDEV-14376 Explicit CAST(CHAR(N)) erroneously escalates warnings to errors in STRICT_ALL_TABLES
--
echo
#
SET
sql_mode
=
STRICT_ALL_TABLES
;
SELECT
CAST
(
'xxx'
AS
CHAR
(
1
));
CREATE
OR
REPLACE
TABLE
t1
(
a
VARCHAR
(
1
));
INSERT
INTO
t1
VALUES
(
CAST
(
'xxx'
AS
CHAR
(
1
)));
DROP
TABLE
t1
;
CREATE
OR
REPLACE
TABLE
t1
(
a
VARCHAR
(
3
));
INSERT
INTO
t1
VALUES
(
'xxx'
);
UPDATE
t1
SET
a
=
CAST
(
a
AS
CHAR
(
1
));
DROP
TABLE
t1
;
DELIMITER
$$
;
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
latin1
;
SET
a
=
CAST
(
'xxx'
AS
CHAR
(
1
));
END
;
$$
DELIMITER
;
$$
DELIMITER
$$
;
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
latin1
;
SET
a
=
CAST
(
_latin1
'xxx'
AS
CHAR
(
1
)
CHARACTER
SET
latin1
);
END
;
$$
DELIMITER
;
$$
DELIMITER
$$
;
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
latin1
;
SET
a
=
CAST
(
_latin1
'xxx'
AS
CHAR
(
1
)
CHARACTER
SET
utf8
);
END
;
$$
DELIMITER
;
$$
DELIMITER
$$
;
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
utf8
;
SET
a
=
CAST
(
'xxx'
AS
CHAR
(
1
));
END
;
$$
DELIMITER
;
$$
DELIMITER
$$
;
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
utf8
;
SET
a
=
CAST
(
_latin1
'xxx'
AS
CHAR
(
1
)
CHARACTER
SET
latin1
);
END
;
$$
DELIMITER
;
$$
DELIMITER
$$
;
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
utf8
;
SET
a
=
CAST
(
_latin1
'xxx'
AS
CHAR
(
1
)
CHARACTER
SET
utf8
);
END
;
$$
DELIMITER
;
$$
--
echo
# Conversion problems still escalate warnings to errors (without right truncation)
DELIMITER
$$
;
--
error
ER_CANNOT_CONVERT_CHARACTER
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
utf8
;
SET
a
=
CAST
(
_utf8
0xD18F
AS
CHAR
(
1
)
CHARACTER
SET
latin1
);
END
;
$$
DELIMITER
;
$$
--
echo
# Conversion problems still escalate warnings to errors (with right truncation)
DELIMITER
$$
;
--
error
ER_CANNOT_CONVERT_CHARACTER
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
30
)
CHARACTER
SET
utf8
;
SET
a
=
CAST
(
_utf8
0xD18FD18F
AS
CHAR
(
1
)
CHARACTER
SET
latin1
);
END
;
$$
DELIMITER
;
$$
--
echo
# CAST(number AS CHAR) escalates warnings to errors on truncation
CREATE
OR
REPLACE
TABLE
t1
(
a
VARCHAR
(
10
));
--
error
ER_TRUNCATED_WRONG_VALUE
INSERT
INTO
t1
VALUES
(
CAST
(
123
AS
CHAR
(
1
)));
DROP
TABLE
t1
;
CREATE
OR
REPLACE
TABLE
t1
(
a
VARCHAR
(
10
));
INSERT
INTO
t1
VALUES
(
'1'
);
--
error
ER_TRUNCATED_WRONG_VALUE
UPDATE
t1
SET
a
=
CAST
(
123
AS
CHAR
(
1
));
DROP
TABLE
t1
;
DELIMITER
$$
;
--
error
ER_TRUNCATED_WRONG_VALUE
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
10
);
SET
a
=
CAST
(
123
AS
CHAR
(
1
));
END
;
$$
DELIMITER
;
$$
--
echo
# CAST(temporal AS CHAR) escalates warnings to errors on truncation
CREATE
OR
REPLACE
TABLE
t1
(
a
VARCHAR
(
10
));
--
error
ER_TRUNCATED_WRONG_VALUE
INSERT
INTO
t1
VALUES
(
CAST
(
TIME
'10:20:30'
AS
CHAR
(
1
)));
DROP
TABLE
t1
;
CREATE
OR
REPLACE
TABLE
t1
(
a
VARCHAR
(
10
));
INSERT
INTO
t1
VALUES
(
'1'
);
--
error
ER_TRUNCATED_WRONG_VALUE
UPDATE
t1
SET
a
=
CAST
(
TIME
'10:20:30'
AS
CHAR
(
1
));
DROP
TABLE
t1
;
DELIMITER
$$
;
--
error
ER_TRUNCATED_WRONG_VALUE
BEGIN
NOT
ATOMIC
DECLARE
a
VARCHAR
(
10
);
SET
a
=
CAST
(
TIME
'10:20:30'
AS
CHAR
(
1
));
END
;
$$
DELIMITER
;
$$
SET
sql_mode
=
DEFAULT
;
sql/item_timefunc.cc
View file @
071aece9
...
...
@@ -2434,6 +2434,8 @@ void Item_char_typecast::check_truncation_with_warn(String *src, uint dstlen)
THD
*
thd
=
current_thd
;
char
char_type
[
40
];
ErrConvString
err
(
src
);
bool
save_abort_on_warning
=
thd
->
abort_on_warning
;
thd
->
abort_on_warning
&=
!
m_suppress_warning_to_error_escalation
;
my_snprintf
(
char_type
,
sizeof
(
char_type
),
"%s(%lu)"
,
cast_cs
==
&
my_charset_bin
?
"BINARY"
:
"CHAR"
,
(
ulong
)
cast_length
);
...
...
@@ -2441,6 +2443,7 @@ void Item_char_typecast::check_truncation_with_warn(String *src, uint dstlen)
ER_TRUNCATED_WRONG_VALUE
,
ER_THD
(
thd
,
ER_TRUNCATED_WRONG_VALUE
),
char_type
,
err
.
ptr
());
thd
->
abort_on_warning
=
save_abort_on_warning
;
}
}
...
...
@@ -2551,7 +2554,7 @@ void Item_char_typecast::fix_length_and_dec_numeric()
}
void
Item_char_typecast
::
fix_length_and_dec_
str
()
void
Item_char_typecast
::
fix_length_and_dec_
generic
()
{
fix_length_and_dec_internal
(
from_cs
=
args
[
0
]
->
dynamic_result
()
?
0
:
...
...
sql/item_timefunc.h
View file @
071aece9
...
...
@@ -1089,6 +1089,7 @@ class Item_char_typecast :public Item_str_func
CHARSET_INFO
*
cast_cs
,
*
from_cs
;
bool
charset_conversion
;
String
tmp_value
;
bool
m_suppress_warning_to_error_escalation
;
bool
has_explicit_length
()
const
{
return
cast_length
!=
~
0U
;
}
String
*
reuse
(
String
*
src
,
uint32
length
);
String
*
copy
(
String
*
src
,
CHARSET_INFO
*
cs
);
...
...
@@ -1097,14 +1098,20 @@ class Item_char_typecast :public Item_str_func
void
fix_length_and_dec_internal
(
CHARSET_INFO
*
fromcs
);
public:
Item_char_typecast
(
THD
*
thd
,
Item
*
a
,
uint
length_arg
,
CHARSET_INFO
*
cs_arg
)
:
Item_str_func
(
thd
,
a
),
cast_length
(
length_arg
),
cast_cs
(
cs_arg
)
{}
Item_str_func
(
thd
,
a
),
cast_length
(
length_arg
),
cast_cs
(
cs_arg
),
m_suppress_warning_to_error_escalation
(
false
)
{}
enum
Functype
functype
()
const
{
return
CHAR_TYPECAST_FUNC
;
}
bool
eq
(
const
Item
*
item
,
bool
binary_cmp
)
const
;
const
char
*
func_name
()
const
{
return
"cast_as_char"
;
}
CHARSET_INFO
*
cast_charset
()
const
{
return
cast_cs
;
}
String
*
val_str
(
String
*
a
);
void
fix_length_and_dec_generic
();
void
fix_length_and_dec_numeric
();
void
fix_length_and_dec_str
();
void
fix_length_and_dec_str
()
{
fix_length_and_dec_generic
();
m_suppress_warning_to_error_escalation
=
true
;
}
void
fix_length_and_dec
()
{
args
[
0
]
->
type_handler
()
->
Item_char_typecast_fix_length_and_dec
(
this
);
...
...
sql/sql_type.cc
View file @
071aece9
...
...
@@ -4339,7 +4339,7 @@ bool Type_handler::
bool
Type_handler
::
Item_char_typecast_fix_length_and_dec
(
Item_char_typecast
*
item
)
const
{
item
->
fix_length_and_dec_
str
();
item
->
fix_length_and_dec_
generic
();
return
false
;
}
...
...
@@ -4352,6 +4352,14 @@ bool Type_handler_numeric::
}
bool
Type_handler_string_result
::
Item_char_typecast_fix_length_and_dec
(
Item_char_typecast
*
item
)
const
{
item
->
fix_length_and_dec_str
();
return
false
;
}
bool
Type_handler
::
Item_time_typecast_fix_length_and_dec
(
Item_time_typecast
*
item
)
const
{
...
...
sql/sql_type.h
View file @
071aece9
...
...
@@ -1717,6 +1717,7 @@ class Type_handler_string_result: public Type_handler
MYSQL_TIME
*
,
ulonglong
fuzzydate
)
const
;
bool
Item_func_between_fix_length_and_dec
(
Item_func_between
*
func
)
const
;
longlong
Item_func_between_val_int
(
Item_func_between
*
func
)
const
;
bool
Item_char_typecast_fix_length_and_dec
(
Item_char_typecast
*
)
const
;
cmp_item
*
make_cmp_item
(
THD
*
thd
,
CHARSET_INFO
*
cs
)
const
;
in_vector
*
make_in_vector
(
THD
*
,
const
Item_func_in
*
,
uint
nargs
)
const
;
bool
Item_func_in_fix_comparator_compatible_types
(
THD
*
thd
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment