From 8611cc076276c7d36afbc0214aee17780f9326c5 Mon Sep 17 00:00:00 2001 From: Jaime Filho Date: Fri, 18 Feb 2022 19:12:46 -0300 Subject: [PATCH] fix: Add charset to cast binary and json data correctly --- patches/mysql2+2.3.3.patch | 12 ++++++++++++ src/utils/typeCast.ts | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/patches/mysql2+2.3.3.patch b/patches/mysql2+2.3.3.patch index aea880c..6685bbe 100644 --- a/patches/mysql2+2.3.3.patch +++ b/patches/mysql2+2.3.3.patch @@ -191,6 +191,18 @@ index c612f66..02dbe22 100644 case 'number': type = Types.DOUBLE; +diff --git a/node_modules/mysql2/lib/parsers/text_parser.js b/node_modules/mysql2/lib/parsers/text_parser.js +index 0af4a7a..bce66bc 100644 +--- a/node_modules/mysql2/lib/parsers/text_parser.js ++++ b/node_modules/mysql2/lib/parsers/text_parser.js +@@ -85,6 +85,7 @@ function compile(fields, options, config) { + db: field.schema, + table: field.table, + name: field.name, ++ charset: field.characterSet, + string: function() { + return _this.packet.readLengthCodedString(field.encoding); + }, diff --git a/node_modules/mysql2/promise.d.ts b/node_modules/mysql2/promise.d.ts index 6ab3d6f..64246e8 100644 --- a/node_modules/mysql2/promise.d.ts diff --git a/src/utils/typeCast.ts b/src/utils/typeCast.ts index 48029e7..0390d57 100644 --- a/src/utils/typeCast.ts +++ b/src/utils/typeCast.ts @@ -1,9 +1,12 @@ import { FieldPacket } from 'mysql2'; +const BINARY_CHARSET = 63; + type Field = { type: string; length: number; packet: FieldPacket; + charset: number; string: () => string; buffer: () => number[]; }; @@ -27,7 +30,7 @@ export const typeCast = (field: Field, next: () => void) => { case 'MEDIUM_BLOB': case 'LONG_BLOB': case 'BLOB': - if (field.packet?.charsetNr === 63) { + if (field.charset === BINARY_CHARSET) { return [...field.buffer()]; } return field.string();