@@ -31,7 +31,7 @@ function compile (fields, options, config) {
31
31
var i = 0 ;
32
32
var lvalue = '' ;
33
33
34
- result . push ( '(function() { return function TextRow(packet, fields, options) {' ) ;
34
+ result . push ( '(function() { return function TextRow(packet, fields, options, CharsetToEncoding ) {' ) ;
35
35
if ( options . rowsAsArray ) {
36
36
result . push ( ' var result = new Array(' + fields . length + ')' ) ;
37
37
}
@@ -74,10 +74,10 @@ function compile (fields, options, config) {
74
74
} else {
75
75
lvalue = ' this[' + srcEscape ( fields [ i ] . name ) + ']' ;
76
76
}
77
- var encoding = CharsetToEncoding [ fields [ i ] . characterSet ] ;
78
- var readCode = readCodeFor ( fields [ i ] . columnType , fields [ i ] . characterSet , encoding , config , options ) ;
77
+ var encodingExpr = ' CharsetToEncoding[fields[' + i + ' ].characterSet]' ;
78
+ var readCode = readCodeFor ( fields [ i ] . columnType , fields [ i ] . characterSet , encodingExpr , config , options ) ;
79
79
if ( typeof options . typeCast === 'function' ) {
80
- result . push ( lvalue + ' = options.typeCast(wrap(fields[' + i + '], ' + srcEscape ( typeNames [ fields [ i ] . columnType ] ) + ', packet, " ' + encoding + '" ), function() { return ' + readCode + ';})' ) ;
80
+ result . push ( lvalue + ' = options.typeCast(wrap(fields[' + i + '], ' + srcEscape ( typeNames [ fields [ i ] . columnType ] ) + ', packet, ' + encodingExpr + '), function() { return ' + readCode + ';})' ) ;
81
81
} else if ( options . typeCast === false ) {
82
82
result . push ( lvalue + ' = packet.readLengthCodedBuffer();' ) ;
83
83
} else {
@@ -100,7 +100,7 @@ function compile (fields, options, config) {
100
100
return vm . runInThisContext ( src ) ;
101
101
}
102
102
103
- function readCodeFor ( type , charset , encoding , config , options ) {
103
+ function readCodeFor ( type , charset , encodingExpr , config , options ) {
104
104
var supportBigNumbers = options . supportBigNumbers || config . supportBigNumbers ;
105
105
var bigNumberStrings = options . bigNumberStrings || config . bigNumberStrings ;
106
106
@@ -143,12 +143,12 @@ function readCodeFor (type, charset, encoding, config, options) {
143
143
case Types . GEOMETRY :
144
144
return 'packet.parseGeometryValue()' ;
145
145
case Types . JSON :
146
- return 'JSON.parse(packet.readLengthCodedString(" ' + encoding + '" ))' ;
146
+ return 'JSON.parse(packet.readLengthCodedString(' + encodingExpr + '))' ;
147
147
default :
148
148
if ( charset == Charsets . BINARY ) {
149
149
return 'packet.readLengthCodedBuffer()' ;
150
150
} else {
151
- return 'packet.readLengthCodedString(" ' + encoding + '" )' ;
151
+ return 'packet.readLengthCodedString(' + encodingExpr + ')' ;
152
152
}
153
153
}
154
154
}
0 commit comments