tediousjs / tedious

Node TDS module for connecting to SQL Server databases.

Home Page:http://tediousjs.github.io/tedious/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unsupported type "BitN" from querying a BIT column

nippur72 opened this issue · comments

What am I doing wrong, I run the following simple request:

SELECT CAST(1 AS BIT) as result

but I get the following error from Node:

Error: Unhandled error. ('unsupported type "BitN"')
    at new NodeError (node:internal/errors:405:5)
    at Readable.emit (node:events:503:17)
    at Readable.emit (node:domain:488:12)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

Tedious: 16.4.1
Node: 20.7
Windows: 10

the only thing that isn't up to date is SQL SERVER 2008 R2, so I'm using the connection option tdsVersion: '7_3_B'.

Getting VARCHAR or INT columns does work, but with some other types (e.g. BITN or TINYINT) I get this strange error.

Hi @nippur72, Unfortunately, that I do not have a SQL SERVER 2008 R2 environment on hand, so it a bit hard of me to reproduce this case. Just to make sure that have you tried this query with the SQL Server Management Studio (SSMS) to see the behavior? Looks like that the 'unsupported type "BitN"' message may be thrown from the server side.

yes it does work in Management Studio, and also works if I cast it to integer:

SELECT CAST(CAST(1 AS BIT) AS INTEGER) as result

Working with strings and integers is also OK, the error occurs with Bit and TinyInt (so far, there might be others).

I'll try to setup a more recent version of SQL Server to see if that is the issue. It's a production database which is twenty years old now - running smoothly since the SQL Server 2000 times!

Thanks for confirming that. If possible, can you try this with a earlier version of NodeJS like Node 19 or 16. On tedious side, we have not yet include Node 20 into the test automation, so there could be behavior that have not been caught up.

There is a difference between SQL Server 2008 and how later SQL Server versions send bit type values. What I don't understand is where this error comes from exactly - there are no errors in tedious that would match the error message you posted, and the stack trace in your message does not help either.

sorry, I was able to track it down to an application exception thrown during the request.on("row",...) event. For some reason the stack trace reported it to be a NodeError but actually it's just an application error. Sorry for the noise.