Skip to content

Commit

Permalink
Merge pull request #86 from jaimeadf/fix/charset
Browse files Browse the repository at this point in the history
fix: Add charset to cast binary and json data correctly
  • Loading branch information
thelindat authored Feb 18, 2022
2 parents 0c76206 + 8611cc0 commit 82f0382
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions patches/mysql2+2.3.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/utils/typeCast.ts
Original file line number Diff line number Diff line change
@@ -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[];
};
Expand All @@ -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();
Expand Down

0 comments on commit 82f0382

Please sign in to comment.