diff --git a/lib/result.js b/lib/result.js index 7a953b2..d638305 100644 --- a/lib/result.js +++ b/lib/result.js @@ -9,6 +9,7 @@ var Result = function() { this.oid = null; this.rows = []; this.fields = []; + this._parsers = []; }; var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/; @@ -46,7 +47,7 @@ Result.prototype.parseRow = function(rowData) { var fieldType = field.dataTypeID; var parsedValue = null; if(rawValue !== null) { - parsedValue = types.getTypeParser(fieldType, field.format || 'text')(rawValue); + parsedValue = this._parsers[i](rawValue); } var fieldName = field.name; row[fieldName] = parsedValue; @@ -65,9 +66,12 @@ Result.prototype.addFields = function(fieldDescriptions) { //you need to reset the fields if(this.fields.length) { this.fields = []; + this._parsers = []; } for(var i = 0; i < fieldDescriptions.length; i++) { - this.fields.push(fieldDescriptions[i]); + var desc = fieldDescriptions[i]; + this.fields.push(desc); + this._parsers.push(types.getTypeParser(desc.dataTypeID, desc.format || 'text')); } };