gpt4 book ai didi

mysql - 为什么 MariaDB-10.2.8 UNHEX() 返回 NULL?

转载 作者:行者123 更新时间:2023-11-29 10:37:26 27 4
gpt4 key购买 nike

我有一个适用于 MySQL(最新版本)的 SQL 脚本。我在 Linux 计算机上从源代码构建了 MariaDB-10.2.8 的副本,并启动并运行了数据库。但是,我的 SQL 脚本失败了,因为 MariaDB 从 UNHEX() 调用中返回 NULL,而它不应该返回 NULL。

该调用会生成特定格式的 20 字节随机二进制字符串(它是 BitTorrent 节点 ID)。我将一些必需的字节与一些随机字节连接起来,其中某些字节被限制为特定的值范围。它们被构造为 40 个字符的十六进制字符串,然后我通过 UNHEX() 运行该字符串。

SQL 是:

    unhex( concat( '414C2',
hex( 8 + round( rand() * 7 ) ),
substr( sha( uuid( ) ), 6, 33 ),
hex( 2 + round( rand( ) ) * 8 ) ) )

如果去掉 UNHEX() 函数,您将得到一个 40 个字符的十六进制字符串:

MariaDB [bt]> select concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8));
+-----------------------------------------------------------------------------------------+
| concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8)) |
+-----------------------------------------------------------------------------------------+
| 414c29115056f1bd332d4e2e3eb5edd3fc90c0a2 |
+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

但是如果你UNHEX()它:

MariaDB [bt]> select unhex(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8)));
+------------------------------------------------------------------------------------------------+
| unhex(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8))) |
+------------------------------------------------------------------------------------------------+
| NULL |
+------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

相比之下,MySQL 实例上的相同命令:

mysql> select unhex(upper(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8))));
+-------------------------------------------------------------------------------------------------------+
| unhex(upper(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8)))) |
+-------------------------------------------------------------------------------------------------------+
| AL*w??
???r?%?? |
+-------------------------------------------------------------------------------------------------------+
1 row in set (0.02 sec)

40 个字符的十六进制字符串的 UNHEX()(其中所有字节均可打印)在 MariaDB 上运行正常:

MariaDB [bt]> select unhex('4142434445464748494a4b4c4d4e4f5051525354');
+---------------------------------------------------+
| unhex('4142434445464748494a4b4c4d4e4f5051525354') |
+---------------------------------------------------+
| ABCDEFGHIJKLMNOPQRST |
+---------------------------------------------------+
1 row in set (0.00 sec)

知道为什么随机十六进制字符串不起作用吗?

最佳答案

看起来像一个错误。我们已为此提交了一份报告: https://jira.mariadb.org/browse/MDEV-13793

关于mysql - 为什么 MariaDB-10.2.8 UNHEX() 返回 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46167808/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com