From 4f6147073953c3cfea2f77ac532c724e4f54d329 Mon Sep 17 00:00:00 2001 From: Gabriel Novotny Date: Fri, 19 May 2017 14:46:44 +0200 Subject: [PATCH 1/2] mysql parser will use column charset as encoding when parsing strings --- lib/common.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/common.js b/lib/common.js index fe56492..ad870c3 100644 --- a/lib/common.js +++ b/lib/common.js @@ -419,6 +419,11 @@ exports.readMysqlValue = function(parser, column, columnSchema, tableMap, emitte }else if(defPrefix === 'varbin'){ result = parser.parseBuffer(size); }else{ + if(column.charset !== null) { + // Javascript UTF8 always allows up to 4 bytes per character + column.charset = column.charset === 'utf8mb4' ? 'utf8' : column.charset; + parser._encoding = column.charset; + } result = parser.parseString(size); } break; From 4a81875f4ba2cba99263ec65eacc9d800f0f8e7a Mon Sep 17 00:00:00 2001 From: Gabriel Novotny Date: Sat, 2 Mar 2019 19:28:55 +0100 Subject: [PATCH 2/2] important fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b937d7c..f3e9662 100644 --- a/index.js +++ b/index.js @@ -187,7 +187,7 @@ ZongJi.prototype._executeCtrlCallbacks = function() { var tableInfoQueryTemplate = 'SELECT ' + 'COLUMN_NAME, COLLATION_NAME, CHARACTER_SET_NAME, ' + 'COLUMN_COMMENT, COLUMN_TYPE ' + - 'FROM information_schema.columns ' + "WHERE table_schema='%s' AND table_name='%s'"; + 'FROM information_schema.columns ' + "WHERE table_schema='%s' AND table_name='%s' ORDER BY ORDINAL_POSITION ASC"; ZongJi.prototype._fetchTableInfo = function(tableMapEvent, next) { var self = this;