Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add BigInt parameterize support

Signed-off-by: Zach Aller <zachaller@hotmail.com>
  • Loading branch information...
commit 7ebf2e02e12d99bd3f73100fde0e051336e2abfa 1 parent 1c37071
@zachaller authored
View
21 src/data-type.coffee
@@ -136,7 +136,28 @@ TYPE =
0x7F:
type: 'INT8'
name: 'BigInt'
+ declaration: (parameter) ->
+ 'bigint'
+ writeParameterData: (buffer, parameter) ->
+ # ParamMetaData (TYPE_INFO)
+ buffer.writeUInt8(typeByName.IntN.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)
+
# Variable-length types
0x22:
type: 'IMAGE'
View
16 test/integration/parameterised-statements-test.coffee
@@ -44,6 +44,12 @@ exports.smallIntNull = (test) ->
exports.int = (test) ->
execSql(test, TYPES.Int, 8)
+
+exports.bigint = (test) ->
+ execSql(test, TYPES.BigInt, 5294967296)
+
+exports.bigintsmall = (test) ->
+ execSql(test, TYPES.BigInt, 8)
exports.intZero = (test) ->
execSql(test, TYPES.Int, 0)
@@ -118,6 +124,12 @@ exports.outputSmallIntNull = (test) ->
exports.outputInt = (test) ->
execSqlOutput(test, TYPES.Int, 3)
+
+exports.outputBigInt = (test) ->
+ execSqlOutput(test, TYPES.BigInt, 5294967296)
+
+exports.outputBigIntSmall = (test) ->
+ execSqlOutput(test, TYPES.BigInt, 8)
exports.outputIntNull = (test) ->
execSqlOutput(test, TYPES.Int, null)
@@ -209,6 +221,8 @@ execSql = (test, type, value) ->
if (value instanceof Date)
test.strictEqual(columns[0].value.getTime(), value.getTime())
+ else if (type == TYPES.BigInt)
+ test.strictEqual(columns[0].value, value.toString())
else
test.strictEqual(columns[0].value, value)
)
@@ -255,6 +269,8 @@ execSqlOutput = (test, type, value) ->
if (value instanceof Date)
test.strictEqual(returnValue.getTime(), value.getTime())
+ else if (type == TYPES.BigInt)
+ test.strictEqual(returnValue, value.toString())
else
test.strictEqual(returnValue, value)
Please sign in to comment.
Something went wrong with that request. Please try again.