node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

TINYINT(1) vs BIT(1)

Open chrisveness opened this issue 8 years ago • 6 comments

I believe common ways of storing booleans in MySQL are with TINYINT(1) or BIT(1).

When I run queries on TINYINT(1), I get 1 or 0 as expected, but on BIT(1) I seem to get <Buffer 01> or <Buffer 00>. Is this by design?

chrisveness avatar Jul 21 '16 16:07 chrisveness

The buffer is returned when field character set is 'binary'. Can you post console.log(fields) for your response?

sidorares avatar Jul 21 '16 23:07 sidorares

For the BIT(1) field, it is

[ { catalog: 'def',
    schema: 'koa-sample-sandbox',
    name: 'Approved',
    orgName: 'Approved',
    table: 'Member',
    orgTable: 'Member',
    characterSet: 63,
    columnLength: 1,
    columnType: 16,
    flags: 32,
    decimals: 0 } ]

If I change the database schema to TINYINT(1), it is then

[ { catalog: 'def',
    schema: 'koa-sample-sandbox',
    name: 'Approved',
    orgName: 'Approved',
    table: 'Member',
    orgTable: 'Member',
    characterSet: 63,
    columnLength: 1,
    columnType: 1,
    flags: 0,
    decimals: 0 } ]

chrisveness avatar Jul 22 '16 14:07 chrisveness

It falls into this default case: https://github.com/sidorares/node-mysql2/blob/aff0b1c8eca5c63566786c72d645224d5a914170/lib/compile_text_parser.js#L144

Maybe worth adding BIT type to read it as number

sidorares avatar Jul 22 '16 22:07 sidorares

Sounds like that would make sense. Could it go together in the same case group with the other integer types?

Is this user comment of any relevance? dev.mysql.com/doc/refman/5.7/en/bit-type.html#comment-listing.

chrisveness avatar Jul 26 '16 11:07 chrisveness

I guess it's better to actually try and see what's sent over the wire. I'll try to do that

sidorares avatar Jul 26 '16 12:07 sidorares

Is there any progress on this?

DJFriar avatar Aug 31 '22 04:08 DJFriar