question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BIT type is defined incorrectly

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sidorarescommented, Nov 22, 2022

hm, you are right. There is no switch case for Types.BIT and it uses default which is “string, unless charset is binary”. I got distracted by select b\'1\' as val' query where server actually returns a string - '\x01'

When you do select * from test_table on your example results are coming with BIT in field type, BINARY as charset and a bunch of data packets with 2 bytes [1, bit value] in the main payload ( 1 for length as payload is still transmitted as “length coded string”

I guess adding following 2 lines should improve the way BIT results are returned:

    case Types.BIT:
      return 'packet.readBuffer(2)[1]';

note that this is potentially a breaking change, but since we are in the process of releasing 3.0.0 might be a good time to add it

All reference this in mysqljs/mysql as currently BIT is returned as 1 length Buffer in that driver as well

0reactions
sidorarescommented, Nov 23, 2022

oh, and based on https://github.com/mysqljs/mysql/issues/2559#issuecomment-1324363650 BIT can be actually 1 to 8 bytes wide, so my code is completely incorrect

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error trying to define a 1024-bit (128 Byte) Bit Field
I thought that if I defined a large-enough variable, the massive bitfield needed for my application could then be defined because the bitfield ......
Read more >
Incorrect bit field definitions #26 - adafruit/Adafruit_APDS9960
Hello, The Adafruit APDS_9960 library is unable to configures some sensor register incorrectly as some bit fields are incorrectly defined.
Read more >
SQL Server Bit Data Type
This is a data type that allows only two possible values "True" or "False". Definitely, if a variable or column can only have...
Read more >
How to Handle the Incompatible Types Error in Java - Rollbar
The Java incompatible types error happens when a value assigned to a variable or returned by a method is incompatible with the one...
Read more >
CWE-1335: Incorrect Bitwise Shift of Integer (4.9) - MITRE
An integer value is specified to be shifted by a negative amount or an amount greater than or equal to the number of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found