deprecate float parsing - closes #296

This commit is contained in:
brianc 2013-03-07 09:54:01 -06:00
parent 6415450634
commit f30158f7c4
3 changed files with 31 additions and 10 deletions

View File

@ -1,3 +1,5 @@
var deprecate = require('deprecate');
var parseBits = function(data, bits, offset, invert, callback) {
offset = offset || 0;
invert = invert || false;
@ -45,6 +47,12 @@ var parseBits = function(data, bits, offset, invert, callback) {
};
var parseFloatFromBits = function(data, precisionBits, exponentBits) {
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
'JavaScript has a hard time with floats and there is precision loss which can cause',
'unexpected, hard to trace, potentially bad bugs in your program',
'for more information see the following:',
'https://github.com/brianc/node-postgres/pull/271',
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
var bias = Math.pow(2, exponentBits - 1) - 1;
var sign = parseBits(data, 1);
var exponent = parseBits(data, exponentBits, 1);

View File

@ -1,3 +1,5 @@
var deprecate = require('deprecate');
var arrayParser = require(__dirname + "/arrayParser.js");
//parses PostgreSQL server formatted date strings into javascript date objects
@ -76,6 +78,12 @@ var parseIntegerArray = function(val) {
};
var parseFloatArray = function(val) {
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
'JavaScript has a hard time with floats and there is precision loss which can cause',
'unexpected, hard to trace, potentially bad bugs in your program',
'for more information see the following:',
'https://github.com/brianc/node-postgres/pull/271',
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
if(!val) { return null; }
var p = arrayParser.create(val, function(entry){
if(entry !== null) {
@ -162,24 +170,27 @@ var parseInteger = function(val) {
return parseInt(val, 10);
};
var parseFloatAndWarn = function(val) {
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
'JavaScript has a hard time with floats and there is precision loss which can cause',
'unexpected, hard to trace, potentially bad bugs in your program',
'for more information see the following:',
'https://github.com/brianc/node-postgres/pull/271',
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
return parseFloat(val);
};
var init = function(register) {
register(20, parseInteger);
register(21, parseInteger);
register(23, parseInteger);
register(26, parseInteger);
//TODO remove for v1.0
register(1700, function(val){
if(val.length > maxLen) {
console.warn(
'WARNING: value %s is longer than max supported numeric value in ' +
'javascript. Possible data loss', val);
}
return parseFloat(val);
});
register(1700, parseFloatAndWarn);
//TODO remove for v1.0
register(700, parseFloat);
register(700, parseFloatAndWarn);
//TODO remove for v1.0
register(701, parseFloat);
register(701, parseFloatAndWarn);
register(16, parseBool);
register(1082, parseDate); // date
register(1114, parseDate); // timestamp without timezone

View File

@ -7,6 +7,8 @@ var BufferList = require(__dirname+'/buffer-list')
var Connection = require(__dirname + '/../lib/connection');
require(__dirname + '/../lib').defaults.hideDeprecationWarnings = true;
Client = require(__dirname + '/../lib').Client;
process.on('uncaughtException', function(d) {