Browse files

Add support for Money/SmallMoney input parameters

  • Loading branch information...
1 parent b690784 commit 5938f7794116c72f31e550a319d9b578fd40e140 @patriksimek patriksimek committed Apr 1, 2014
View
2 README.md
@@ -20,7 +20,7 @@ Current version: 0.1.5
- Added support for TDS 7.4
- Added request cancelation
-- Added support for UDT, TVP, Time, Date, DateTime2 and DateTimeOffset, Numeric, Decimal data types
+- Added support for UDT, TVP, Time, Date, DateTime2, DateTimeOffset, Numeric, Decimal, SmallMoney and Money data types
- Added option to choose whether to pass/receive times in UTC or local time (`useUTC`)
- Binary, VarBinary and Image are now supported as input parameters
- Binary, VarBinary and Image types are now returned as Buffer (was Array)
View
28 src/data-type.coffee
@@ -119,6 +119,19 @@ TYPE =
0x3C:
type: 'MONEY'
name: 'Money'
+ declaration: (parameter) ->
+ "money"
+ writeTypeInfo: (buffer, parameter) ->
+ # ParamMetaData (TYPE_INFO)
+ buffer.writeUInt8 typeByName.MoneyN.id
+ buffer.writeUInt8 8
+ writeParameterData: (buffer, parameter) ->
+ # ParamLenData (TYPE_VARBYTE)
+ if parameter.value?
+ buffer.writeUInt8 8
+ buffer.writeMoney parameter.value * 10000
+ else
+ buffer.writeUInt8 0
0x3D:
type: 'DATETIME'
name: 'DateTime'
@@ -293,6 +306,19 @@ TYPE =
0x7A:
type: 'MONEY4'
name: 'SmallMoney'
+ declaration: (parameter) ->
+ "smallmoney"
+ writeTypeInfo: (buffer, parameter) ->
+ # ParamMetaData (TYPE_INFO)
+ buffer.writeUInt8 typeByName.MoneyN.id
+ buffer.writeUInt8 4
+ writeParameterData: (buffer, parameter) ->
+ # ParamLenData (TYPE_VARBYTE)
+ if parameter.value?
+ buffer.writeUInt8 4
+ buffer.writeInt32LE parameter.value * 10000
+ else
+ buffer.writeUInt8 0
0x7F:
type: 'INT8'
name: 'BigInt'
@@ -841,8 +867,6 @@ TYPE =
# Types not (yet) supported
###
- DECIMALTYPE: 0x37 # Decimal (legacy support)
- NUMERICTYPE: 0x3F # Numeric (legacy support)
CHARTYPE: 0x2F # Char (legacy support)
VARCHARTYPE: 0x27 # VarChar (legacy support)
BINARYTYPE: 0x2D # Binary (legacy support)
View
4 src/tracking-buffer/writable-tracking-buffer.coffee
@@ -199,5 +199,9 @@ class WritableTrackingBuffer
@makeRoomFor(length)
value.copy(@buffer, @position)
@position += length
+
+ writeMoney: (value) ->
+ @writeInt32LE Math.floor(value * SHIFT_RIGHT_32)
+ @writeInt32LE value & -1
module.exports = WritableTrackingBuffer
View
6 test/integration/parameterised-statements-test.coffee
@@ -79,6 +79,12 @@ exports.decimal = (test) ->
exports.decimalLargeValue = (test) ->
execSql(test, TYPES.Decimal, 5.555555555555553333, null, {precision: 19, scale: 18})
+exports.smallMoney = (test) ->
+ execSql(test, TYPES.SmallMoney, 9842.4566)
+
+exports.money = (test) ->
+ execSql(test, TYPES.Money, 956455842.4566)
+
exports.uniqueIdentifierN = (test) ->
execSql(test, TYPES.UniqueIdentifierN, '01234567-89AB-CDEF-0123-456789ABCDEF')

0 comments on commit 5938f77

Please sign in to comment.