Forum

Thread tagged as: Api, Add-on-development, Field-Types

mySQL BIT integration into API

I am currently retrofitting Perch into an already existing web application to give some nice CMS capabilities. I nearly have it there, but have hit a stumbling block in that one of the database columns is in the format BIT, and all that returns in the misunderstood character symbol. Now, if I write straight SQL and pass through BIN, this resolves the issue rather nicely, but not sure if there is a way to do similar within Perch, and if not, what would be a recommended alternative (other than changing the datatype)?

Thank you, Dan

Dan Duke

Dan Duke 1 points

  • 6 years ago

A little laborious, but what I have done so far is copied the below into my apps class, and making modifications there. I will then also have to do the same for insert and other selects etc. public function find($id){ ... }

Due to the repetitive nature of what I am doing, I wonder if there is an easier way to do this still.

Note: To future proof my work, I am able to do things like this, so it will still cater for future added fields to this table if it needs to $sql = 'SELECT *,BIN(IsActive+0) FROM ' . $this->table . ' WHERE ' . $this->pk . '='. $this->db->pdb($id) .' LIMIT 1';

Drew McLellan

Drew McLellan 2638 points
Perch Support

Bit fields behave differently across different MySQL sub versions, so Perch doesn't ever make use of them. They just wouldn't work reliably in all the different environments we have to support.

As such, I don't really have a suggestion as to the best way to proceed.