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

BIT type is defined incorrectly

Open barkermn01 opened this issue 2 years ago • 0 comments

So I was looking at trying to fix the implementation of BIT as a Temporary fix till the new RFC system comes in however upon testing and reading, I remember one of the developers saying BIT is treated like TinyInt, and they are not in fact reading the code they have there own type defined in /lib/constants/types.js and this is set as Hex 0x10 however in creating a test case that console.log's the type in both binary_parser and text_parser i found it's providing a type of 253 in a hex that is 0xFD, which is listed as type // aka VARCHAR, VARBINARY,

Could this be that BIT has been changed from the C API-defined version and is now just classed as a VARBINARY with a length of 1?

The test I created to make sure it was using BIT, at first I tried to just use the query SELECT b'1' as val and that seemed to become a blob, so i made sure to test a BIT Column as you can see below.

const createConnection = require('../common.js').createConnection;
const assert = require('assert');

// enabled in initial config, disable in some tets
const c = createConnection({ rowsAsArray: true });
c.query('CREATE TABLE `test_table` (`bit_column` BIT);', (err) => {
    c.query("INSERT INTO `test_table` VALUE(b'1');", (err) => {
        c.query('select b\'1\' as val;', (err, rows) => {
            console.log(rows);
            c.query('DROP TABLE `test_table`;', err => {});
            assert.ifError(err);
            assert.equal(rows[0][0], 1);
        });
    });
})

the Debugging that identified that the Type is incorrect was I added console.log("text_parser type", type); on line 21 of text_parser.js

barkermn01 avatar Jul 25 '22 09:07 barkermn01