Permalink
Browse files

#147 - Out of bounds error on negative numeric/decimal input parameter

  • Loading branch information...
patriksimek committed Apr 16, 2014
1 parent e7d7b5b commit 7536f712d7b7e840b8e2ff4657758cebe123e87e
Showing with 11 additions and 5 deletions.
  1. +2 −2 package.json
  2. +3 −3 src/data-type.coffee
  3. +6 −0 test/integration/parameterised-statements-test.coffee
View
@@ -26,7 +26,7 @@
"url": "https://raw.github.com/pekim/tedious/master/LICENSE"
}
],
- "version": "0.2.2",
+ "version": "0.2.3",
"main": "./lib/tedious.js",
"repository": {
"type": "git",
@@ -36,11 +36,11 @@
"node": "0.6 || 0.7 || 0.8 || 0.9 || 0.10 || 0.11"
},
"dependencies": {
- "async": "0.2.10",
"iconv-lite": "0.2.7",
"sprintf": "0.1.1"
},
"devDependencies": {
+ "async": "0.2.10",
"coffee-script": "1.7.1",
"nodeunit": "0.8.4"
},
View
@@ -219,7 +219,7 @@ TYPE =
# ParamLenData (TYPE_VARBYTE)
if parameter.value?
sign = if parameter.value < 0 then 0 else 1
- value = parameter.value * Math.pow 10, parameter.scale
+ value = Math.abs parameter.value * Math.pow(10, parameter.scale)
if parameter.precision <= 9
buffer.writeUInt8 5
@@ -280,8 +280,8 @@ TYPE =
# ParamLenData (TYPE_VARBYTE)
if parameter.value?
sign = if parameter.value < 0 then 0 else 1
- value = parameter.value * Math.pow 10, parameter.scale
-
+ value = Math.abs parameter.value * Math.pow(10, parameter.scale)
+
if parameter.precision <= 9
buffer.writeUInt8 5
buffer.writeUInt8 sign
@@ -73,12 +73,18 @@ exports.numeric = (test) ->
exports.numericLargeValue = (test) ->
execSql(test, TYPES.Numeric, 5.555555555555553333, null, {precision: 19, scale: 18})
+exports.numericNegative = (test) ->
+ execSql(test, TYPES.Numeric, -5555.55, null, {precision: 6, scale: 2})
+
exports.decimal = (test) ->
execSql(test, TYPES.Decimal, 5555)
exports.decimalLargeValue = (test) ->
execSql(test, TYPES.Decimal, 5.555555555555553333, null, {precision: 19, scale: 18})
+exports.decimalNegative = (test) ->
+ execSql(test, TYPES.Decimal, -5555.55, null, {precision: 6, scale: 2})
+
exports.smallMoney = (test) ->
execSql(test, TYPES.SmallMoney, 9842.4566)

0 comments on commit 7536f71

Please sign in to comment.