From 86d5296fb04888b117831e4c9ba10489d3e2d392 Mon Sep 17 00:00:00 2001 From: brianc Date: Wed, 27 Oct 2010 00:15:58 -0500 Subject: [PATCH] parsing floats --- README.md | 3 +++ lib/client.js | 8 ++++---- test/unit/client/typed-query-results.js | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1e4c6b5c..4135c735 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,9 @@ the database first and then re-create the data as follows: - Typed result set support in client - simple queries - bound commands + - edge cases + - [numeric 'NaN' result](http://www.postgresql.org/docs/8.4/static/datatype-numeric.html) + - float Infinity, -Infinity - Error handling - disconnection, removal of listeners on errors - passing errors to callbacks? diff --git a/lib/client.js b/lib/client.js index 6f83d801..3535e3d6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -175,10 +175,10 @@ Client.dataTypeParser = { 20: parseInt, 21: parseInt, 23: parseInt, - 26: parseInt - // 1700: floatParser, - // 700: floatParser, - // 701: floatParser, + 26: parseInt, + 1700: parseFloat, + 700: parseFloat, + 701: parseFloat // 1083: timeParser, // 1266: timeParser, // 1114: dateParser, diff --git a/test/unit/client/typed-query-results.js b/test/unit/client/typed-query-results.js index f97987da..f77e7bf8 100644 --- a/test/unit/client/typed-query-results.js +++ b/test/unit/client/typed-query-results.js @@ -18,6 +18,9 @@ test('typed results', function() { testParses('smallInt / int2', 2, 4); testParses('bigint / int8', 3, 1234567890); testParses('oid', 4, 1234); + testParses('numeric', 5, 123.456); + testParses('real / float4', 6, 123.4567); + testParses('double', 7, 1234.5678); }); con.emit('rowDescription', { @@ -37,6 +40,15 @@ test('typed results', function() { },{ name: 'oid', dataTypeID: 26 + },{ + name: 'numeric', + dataTypeID: 1700 + },{ + name: 'real, float4', + dataTypeID: 700 + },{ + name: 'double precision, float8', + dataTypeID: 701 }] }); @@ -45,7 +57,10 @@ test('typed results', function() { '1394', //integer '4', //smallint '1234567890', //bigint (yes, i know, this isn't 8 bytes) - '1234' //oid + '1234', //oid + '123.456', //numeric + '123.4567', //real + '1234.5678' //double ]})); });