Permalink
Browse files

better way to split up bigint's

Signed-off-by: Zach Aller <zachaller@hotmail.com>
  • Loading branch information...
1 parent 7ebf2e0 commit dd34afe07ba0101f6c83863402112263bec737b9 @zachaller committed Aug 9, 2012
Showing with 27 additions and 8 deletions.
  1. +23 −7 src/data-type.coffee
  2. +4 −1 test/integration/parameterised-statements-test.coffee
View
30 src/data-type.coffee
@@ -130,6 +130,27 @@ TYPE =
0x3E:
type: 'FLT8'
name: 'Float'
+ declaration: (parameter) ->
+ 'float'
+ writeParameterData: (buffer, parameter) ->
+ # ParamMetaData (TYPE_INFO)
+ buffer.writeUInt8(typeByName.FloatN.id)
+ buffer.writeUInt8(8)
+
+ # ParamLenData
+ if parameter.value?
+ buffer.writeUInt8(8)
+ bigNumber = parameter.value;
+ high32bits = 0;
+ for i in [63..31]
+ if(bigNumber - Math.pow(2, i) < 0)
+ else
+ bigNumber -= Math.pow(2, i);
+ high32bits += Math.pow(2, i - 32);
+ buffer.writeUInt32LE(bigNumber)
+ buffer.writeUInt32LE(high32bits)
+ else
+ buffer.writeUInt8(0)
0x7A:
type: 'MONEY4'
name: 'SmallMoney'
@@ -148,13 +169,8 @@ TYPE =
buffer.writeUInt8(8)
bigNumber = parameter.value;
high32bits = 0;
- for i in [63..31]
- if(bigNumber - Math.pow(2, i) < 0)
- else
- bigNumber -= Math.pow(2, i);
- high32bits += Math.pow(2, i - 32);
- buffer.writeUInt32LE(bigNumber)
- buffer.writeUInt32LE(high32bits)
+ buffer.writeUInt32LE(bigNumber%4294967296)
+ buffer.writeUInt32LE(Math.floor(bigNumber/4294967296))
else
buffer.writeUInt8(0)
View
5 test/integration/parameterised-statements-test.coffee
@@ -46,10 +46,13 @@ exports.int = (test) ->
execSql(test, TYPES.Int, 8)
exports.bigint = (test) ->
- execSql(test, TYPES.BigInt, 5294967296)
+ execSql(test, TYPES.BigInt, 67553994410557440)
exports.bigintsmall = (test) ->
execSql(test, TYPES.BigInt, 8)
+
+# exports.bigintsmall = (test) ->
+# execSql(test, TYPES.Float, 8.5)
exports.intZero = (test) ->
execSql(test, TYPES.Int, 0)

0 comments on commit dd34afe

Please sign in to comment.