[MDEV-10479] Hexadecimal literals on X' value ' form not working in numeric context, gives warning Created: 2016-08-01  Updated: 2016-09-05  Resolved: 2016-09-05

Status: Closed
Project: MariaDB Server
Component/s: Documentation
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Karl Levik Assignee: Ian Gilfillan
Resolution: Fixed Votes: 0
Labels: None


 Description   

According to this page: https://mariadb.com/kb/en/mariadb/hexadecimal-literals/

The result from:

SELECT x'0a'+0;

and:

SELECT X'0a'+0;

should be equivalent of:

SELECT 0x0a+0;

However, I get 0 for the two former queries and 10 for the latter:

MariaDB [(none)]> SELECT x'0a'+0;
+---------+
| x'0a'+0 |
+---------+
|       0 |
+---------+
1 row in set, 1 warning (0.00 sec)
 
MariaDB [(none)]> show warnings;
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '\x0A' |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)

(This is also inconsistent with the results for these queries in MySQL.)



 Comments   
Comment by Elena Stepanova [ 2016-08-04 ]

Thanks for the report.

MySQL (5.5, 5.6, 5.7) returns 10 for all variants.

Comment by Alexander Barkov [ 2016-08-05 ]

The syntax X'hhhh' stands for the SQL Standard <binary string literal> and must always behave as a string in all contexts.

The syntax 0xhhhh stands for MySQL/MariaDB extension for hex hybrids which behave as a string or as a number depending on context.

This behavior difference is expected.

Binary string literals were fixed under terms on this bug report:

MDEV-4489 Replication of big5, cp932, gbk, sjis strings makes wrong values on slave

Comment by Alexander Barkov [ 2016-08-05 ]

Ian, can you please make sure that the difference between binary strings and hex hybrids is properly documented and close the issue as "Not a bug"?

Example:

MariaDB [test]> SELECT 0x31+0, X'31'+0;
+--------+---------+
| 0x31+0 | X'31'+0 |
+--------+---------+
|     49 |       1 |
+--------+---------+

0x31 is treated as a number 0x31, because it's used in a numeric context.
X'31' is treated as a sting '1', because it is a binary string literal in all contexts.

Note, MySQL returns 49 in both columns, which is wrong.

Thanks.

Comment by Ian Gilfillan [ 2016-09-05 ]

Clarified in the documentation

Comment by Elena Stepanova [ 2016-09-05 ]

Re--opening for a moment to modify 'Resolution' field – technically, it was a bug (documentation problem) which has been fixed now.

Generated at Thu Feb 08 07:42:31 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.