我刚刚从续集版本 4.32.1 迁移到版本 5.6.1。在此更新之前一切正常。现在,我几乎所有查询都在下面收到错误。
我的 MySQL 服务器版本是 5.7.25-0ubuntu0.16.04.2-log (Ubuntu(,查询中表中的数据库列都没有 JSON 数据类型。
这是引发错误的函数的主体。"accountIds"的值是数字数组。
let sqlQuery = `
SELECT ua.*, page.page_id
FROM user_instagram_fb_page_account ua
LEFT JOIN user_facebook_page page ON page.id = ua.user_fb_page_id
WHERE ua.user_account_ig_id IN($accountIds)
`;
return this._db.query(sqlQuery, {
bind: {
accountIds,
},
type: sequelize.QueryTypes.SELECT,
});
和错误:
{ Error: This version of MySQL doesn't yet support 'item type for JSON'
at Packet.asError (/Volumes/ZoomSphereDEV/projects/zoomsphere2-api/node_modules/mysql2/lib/packets/packet.js:684:17)
at Execute.execute (/Volumes/ZoomSphereDEV/projects/zoomsphere2-api/node_modules/mysql2/lib/commands/command.js:28:26)
at Connection.handlePacket (/Volumes/ZoomSphereDEV/projects/zoomsphere2-api/node_modules/mysql2/lib/connection.js:449:32)
at PacketParser.Connection.packetParser.p [as onPacket] (/Volumes/ZoomSphereDEV/projects/zoomsphere2-api/node_modules/mysql2/lib/connection.js:72:12)
at PacketParser.executeStart (/Volumes/ZoomSphereDEV/projects/zoomsphere2-api/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Volumes/ZoomSphereDEV/projects/zoomsphere2-api/node_modules/mysql2/lib/connection.js:79:25)
at Socket.emit (events.js:189:13)
at Socket.EventEmitter.emit (domain.js:441:20)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
code: 'ER_NOT_SUPPORTED_YET',
errno: 1235,
sqlState: '42000',
sqlMessage:
'This version of MySQL doesn't yet support 'item type for JSON'',
sql:
'SELECT ua.*, page.page_id FROM user_instagram_fb_page_account uan LEFT JOIN user_facebook_page page ON page.id = ua.user_fb_page_idn WHERE ua.user_account_ig_id IN(?)' },
你能帮帮我吗?
我也遇到了这个问题,但对于 mysql2 库,不是续集 - 我使用的是 JSON 字段。
这工作正常:
更新表集字段 = '{}' 其中 id = 1
Mysql2 抛出了我在尝试运行它时遇到的错误:
更新表集字段 = '{}'其中 id = 1 和字段 = '{"键": "值"}'
从 MySQL shell 运行此操作会产生有效的查询,但不会匹配任何行。
我必须这样做才能让它工作:
更新表集字段 = '{}'其中 id = 1 且字段 = CAST('{"键": "值"}' 作为 JSON(
也许续集不得不改变他们的解析器。 如果我是你,我会尝试将accountIds
转换为带引号的字符串并尝试这样做。
像这样:
return this._db.query(sqlQuery, {
bind: {
accountIds.map( (accountId) => {
return `'${accountId}'`
}).join(','),
},
type: sequelize.QueryTypes.SELECT,
});
根据文档 [1],我需要使用数组数据类型作为从"绑定"到"替换"的参数重写所有原始 SQL 查询。
所以这个解决方案有效:
const sqlQuery = `
SELECT ua.*, page.page_id
FROM user_instagram_fb_page_account ua
LEFT JOIN user_facebook_page page ON page.id = ua.user_fb_page_id
WHERE ua.user_account_ig_id IN(:accountIds)
`;
return this._db.query(sqlQuery, {
replacements: {
accountIds,
},
type: sequelize.QueryTypes.SELECT,
});
另一个有效的解决方案是使用模板文字:
const sqlQuery = `
SELECT ua.*, page.page_id
FROM user_instagram_fb_page_account ua
LEFT JOIN user_facebook_page page ON page.id = ua.user_fb_page_id
WHERE ua.user_account_ig_id IN(${accountIds})
`;
return this._db.query(sqlQuery, {
type: sequelize.QueryTypes.SELECT,
});
[1] http://docs.sequelizejs.com/manual/raw-queries.html