Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert can use Buffer, but not work with Uint8Array #2528

Open
i18n-now opened this issue Mar 26, 2024 · 1 comment
Open

insert can use Buffer, but not work with Uint8Array #2528

i18n-now opened this issue Mar 26, 2024 · 1 comment
Labels

Comments

@i18n-now
Copy link

when use Uint8Array , will cause error (the hash column)


Error: insert ignore into `v` (`css`, `hash`, `idLi`, `js`) values (151, {"0":114,"1":108,"2":86,"3":55,"4":10,"5":74,"6":187,"7":109,"8":165,"9":203,"10":90,"11":226,"12":165,"13":144,"14":143,"15":33,
"16":98,"17":122,"18":116,"19":22,"20":231,"21":192,"22":78,"23":37,"24":13,"25":131,"26":169,"27":153,"28":129,"29":125,"30":136,"31":157}, X'01010101010101010101010101010101010101010101010101010101010
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101', 38) - Unknown column '0' in 'field list'
    at Packet.asError (/Volumes/d/i18n/node/s3dist/node_modules/.pnpm/[email protected]/node_modules/mysql2/lib/packets/packet.js:728:17)
    at Query.execute (/Volumes/d/i18n/node/s3dist/node_modules/.pnpm/[email protected]/node_modules/mysql2/lib/commands/command.js:29:26)
    at Connection.handlePacket (/Volumes/d/i18n/node/s3dist/node_modules/.pnpm/[email protected]/node_modules/mysql2/lib/connection.js:481:34)
    at PacketParser.onPacket (/Volumes/d/i18n/node/s3dist/node_modules/.pnpm/[email protected]/node_modules/mysql2/lib/connection.js:97:12)
    at PacketParser.executeStart (/Volumes/d/i18n/node/s3dist/node_modules/.pnpm/[email protected]/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.<anonymous> (/Volumes/d/i18n/node/s3dist/node_modules/.pnpm/[email protected]/node_modules/mysql2/lib/connection.js:104:25)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'ER_BAD_FIELD_ERROR',
  errno: 1054,
  sqlState: '42S22',
  sqlMessage: "Unknown column '0' in 'field list'",
  sql: "insert ignore into `v` (`css`, `hash`, `idLi`, `js`) values (151, `0` = 114, `1` = 108, `2` = 86, `3` = 55, `4` = 10, `5` = 74, `6` = 187, `7` = 109, `8` = 165, `9` = 203, `10` = 90, `11` = 226,
 `12` = 165, `13` = 144, `14` = 143, `15` = 33, `16` = 98, `17` = 122, `18` = 116, `19` = 22, `20` = 231, `21` = 192, `22` = 78, `23` = 37, `24` = 13, `25` = 131, `26` = 169, `27` = 153, `28` = 129, `29
` = 125, `30` = 136, `31` = 157, X'01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101', 38)"
}
@sidorares sidorares added the bug label Mar 26, 2024
@sidorares
Copy link
Owner

Hi @i18n-now , would you like to help fixing this issue? For execute() this would require extra case similar to isBuffer() here:

} else if (Buffer.isBuffer(value)) {
length = Packet.lengthCodedNumberLength(value.length) + value.length;
writer = Packet.prototype.writeLengthCodedBuffer;
}

For .query() the relevant code is here - https://github.com/mysqljs/sqlstring/blob/cd528556b4b6bcf300c3db515026935dedf7cfa1/lib/SqlString.js#L47-L49

If you decide to start with sqlstring fix I suggest starting discussion in the repo https://github.com/mysqljs/sqlstring/issues/new

What happens currently: the ArrayBuffer input is treated as object ( because type of arraybuffer is "object" ), the value is passed to SqlString.objectToValues(val, timeZone); and converted to list of (index, arraybuf value at index) pairs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants