File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ const createColumns = function (metadata, arrayRowMode) {
176176}
177177
178178const valueCorrection = function ( value , metadata ) {
179- const type = getMssqlType ( metadata . type )
179+ const type = getMssqlType ( metadata . type , metadata . dataLength )
180180 if ( valueHandler . has ( type ) ) {
181181 return valueHandler . get ( type ) ( value )
182182 } else if ( ( metadata . type === tds . TYPES . UDT ) && ( value != null ) ) {
Original file line number Diff line number Diff line change @@ -162,6 +162,21 @@ module.exports = (sql, driver) => {
162162 done ( )
163163 } ) . catch ( done )
164164 } ,
165+ 'value handler for IntN types uses correct type' ( done ) {
166+ let bigIntCalls = 0
167+ let intCalls = 0
168+ let tinyIntCalls = 0
169+ sql . valueHandler . set ( sql . TYPES . BigInt , ( value ) => { bigIntCalls ++ ; return value } )
170+ sql . valueHandler . set ( sql . TYPES . Int , ( value ) => { intCalls ++ ; return value } )
171+ sql . valueHandler . set ( sql . TYPES . TinyInt , ( value ) => { tinyIntCalls ++ ; return value } )
172+ sql . query ( 'SELECT CAST(1 AS bigint) AS big, CAST(2 AS int) AS med, CAST(3 AS tinyint) AS tiny' ) . then ( ( result ) => {
173+ assert . strictEqual ( result . recordset . length , 1 )
174+ assert . strictEqual ( bigIntCalls , 1 , 'BigInt handler should be called once' )
175+ assert . strictEqual ( intCalls , 1 , 'Int handler should be called once' )
176+ assert . strictEqual ( tinyIntCalls , 1 , 'TinyInt handler should be called once' )
177+ done ( )
178+ } ) . catch ( done )
179+ } ,
165180 'bigint inputs' ( done ) {
166181 const req = new TestRequest ( )
167182 req . input ( 'bigintparam' , BigInt ( '4294967294' ) )
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ describe('msnodesqlv8', function () {
4646
4747 it ( 'config validation' , done => TESTS [ 'config validation' ] ( done ) )
4848 it ( 'value handler' , done => TESTS [ 'value handler' ] ( done ) )
49+ it ( 'value handler for IntN types uses correct type' , done => TESTS [ 'value handler for IntN types uses correct type' ] ( done ) )
4950 it ( 'bigint inputs' , done => TESTS [ 'bigint inputs' ] ( done ) )
5051 it ( 'stored procedure (exec)' , done => TESTS [ 'stored procedure' ] ( 'execute' , done ) )
5152 it ( 'stored procedure (batch)' , done => TESTS [ 'stored procedure' ] ( 'batch' , done ) )
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ describe('tedious', () => {
5353
5454 it ( 'config validation' , done => TESTS [ 'config validation' ] ( done ) )
5555 it ( 'value handler' , done => TESTS [ 'value handler' ] ( done ) )
56+ it ( 'value handler for IntN types uses correct type' , done => TESTS [ 'value handler for IntN types uses correct type' ] ( done ) )
5657 it ( 'bigint inputs' , done => TESTS [ 'bigint inputs' ] ( done ) )
5758 it ( 'stored procedure (exec)' , done => TESTS [ 'stored procedure' ] ( 'execute' , done ) )
5859 it ( 'stored procedure (batch)' , done => TESTS [ 'stored procedure' ] ( 'batch' , done ) )
You can’t perform that action at this time.
0 commit comments