diff --git a/src/data-types/bigint.ts b/src/data-types/bigint.ts index c57ead905..cf28bbf2c 100644 --- a/src/data-types/bigint.ts +++ b/src/data-types/bigint.ts @@ -34,7 +34,7 @@ const BigInt: DataType = { } const buffer = new WritableTrackingBuffer(8); - buffer.writeInt64LE(Number(parameter.value)); + buffer.writeBigInt64LE(typeof parameter.value === 'bigint' ? parameter.value : globalThis.BigInt(parameter.value)); yield buffer.data; }, diff --git a/test/unit/int-data-type.js b/test/unit/int-data-type.js index a31ffbc38..676af8edf 100644 --- a/test/unit/int-data-type.js +++ b/test/unit/int-data-type.js @@ -1,5 +1,5 @@ const { assert } = require('chai'); -const { typeByName: { Int, SmallInt, TinyInt } } = require('../../src/data-type'); +const { typeByName: { Int, SmallInt, TinyInt, BigInt } } = require('../../src/data-type'); describe('integer-data-types', function() { describe('int data type test', function() { @@ -46,4 +46,18 @@ describe('integer-data-types', function() { }); }); }); + + describe('big int data type test', function() { + const params = [ + { param: { value: 9223372036854775807n }, expected: 9223372036854775807n }, + { param: { value: -9223372036854775808n }, expected: -9223372036854775808n } + ]; + + params.forEach(function(item) { + it('test valid parameter values', function() { + const buffer = Buffer.concat([...BigInt.generateParameterData(item.param, {})]); + assert.equal(buffer.readBigInt64LE(0), item.expected); + }); + }); + }); });