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

BIT data type not supported

Open randydu opened this issue 9 years ago • 1 comments

When using BIT(1) as storage type for boolean value, all values retrieved from node-mariasql are empty string ("") no matter what the real value is (1 or 0).

The fix is at binding.cc, we should check the field type ( field.type == MYSQL_TYPE_BIT ) and then:

if(fields[f].type == MYSQL_TYPE_BIT){
      field_value = Nan::New( *(const unsigned char*)(dbrow[f]) );
}

Of course the above fix only works for BIT length <=8, the maximum BIT length can be 64 ( up to 8 bytes ).

It works fine after the fix is applied, the value returned is 1 for true and 0 for false, otherwise to fetch the BIT(1) value, I have to cast it to integer at SQL level:

  SELECT CAST( BitField AS unsigned integer) AS BitFieldV FROM DEMO;

randydu avatar Oct 06 '16 21:10 randydu

I have faced the same issue with the column which I defined as bool. When I checked the column type it looks bit and mariasql says that the result is

""

(an empty string) even though the value is true

lacivert avatar Oct 17 '17 11:10 lacivert