【问题标题】:hex literal too big in sqlitesqlite中的十六进制文字太大
【发布时间】:2020-06-26 14:50:20
【问题描述】:

所以我想将 msyql 查询转换为 sqlite,其中包含十六进制代码中的图像,当我在 sqlite 浏览器中运行相同的查询时,它给了我一个错误,正确的做法是什么。

Result: hex literal too big: 0x73616666726f6e2e6a7067
At line 1:
INSERT INTO `test` (`id`, `yeild`, `image`, `city`, `info`, `fertilizer`) VALUES
(9, 'Wheat', 0x77686561742e6a7067, 'Bangalore', 'Weather that is comfortable for humans is also good for wheat. Wheat needs 12\r\nto 15 inches (31 to 38 centimetres) of water to produce a')


CREATE TABLE IF NOT EXISTS `test` (
  `id` int(11) NOT NULL PRIMARY KEY,
  `yeild` varchar(40) NOT NULL,
  `image` blob NOT NULL,
  `city` varchar(50) NOT NULL,
  `info` varchar(60000) NOT NULL,
  `fertilizer` varchar(5000) NOT NULL);

【问题讨论】:

  • 你能分享一下表格的DDL吗? image 字段的数据类型是什么
  • 我使用过blob数据类型

标签: mysql django sqlite


【解决方案1】:
 INSERT INTO `test` (`id`, `yeild`, `image`, `city`, `info`, `fertilizer`) VALUES
(9, 'Wheat', '0x77686561742e6a7067', 'Bangalore', 'Weather that is comfortable for humans is also good for wheat. Wheat needs 12\r\nto 15 inches (31 to 38 centimetres) of water to produce a', 'My fertilizser');

您的十六进制值应该用引号引起来。 此外,您只传递了 5 个输入值,但该表有 6 个字段。

Demo

【讨论】:

  • 这不符合预期 - select typeof(image) from test 表明它被存储为文本,因为 sqlite 的输入非常灵活。
【解决方案2】:

你想插入一个 blob 字面量,而不是一个数字:

X'77686561742e6a7067'

来自the documentation

十六进制整数文字被解释为 64 位二进制补码整数,因此精度限制为十六位有效数字。

BLOB 字面量是包含十六进制数据并以单个“x”或“X”字符开头的字符串字面量。示例:X'53514C697465'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 2014-12-24
    • 2017-09-13
    • 2011-06-01
    • 2013-04-28
    • 2014-04-24
    相关资源
    最近更新 更多