Hello there
I'm trying to do a bitwise operation over a text column that actually contains a string of zeros and ones without success. I hope someone could give me some help on this. Maybe i'm trying to do something impossible and i don't know...
Here the details:
I have a string with 1024 zeros and ones (a molecule fingerprint) stored in a table named 'identification' under the column 'value'. This column is TEXT type because some other identification formats (id_idformat) in the same table do not use this zeros-ones string.
Here the table description:
mysql> describe identification;
+-------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| id_state | int(11) | NO | MUL | NULL | |
| id_idformat | int(11) | NO | MUL | NULL | |
| value | text | NO | MUL | NULL | |
+-------------+---------+------+-----+---------+-------+
3 rows in set (0.04 sec)
My aim is to perform a bitwise AND comparison over that particular column for a specific id_idformat.
The query string is also another fingerprint of 1024 bits that in php i have under the variable $fp as a string.And this is the query that does not seem to work:
SELECT id_state, value FROM identification WHERE id_idformat = 5
AND BIT_COUNT(CONVERT(value,BINARY) & CONVERT($fp,BINARY)) = BIT_COUNT(CONVERT($fp,BINARY));
The result should be all the fingerprints in the table which share the same ONES that my query fingerprint. But this is not happening... and its returning all the table instead.
What am I doing wrong?? I guess the problem is the conversion from string to binary but i tried several types of conversion and it is still not working.
For example, with the b' ' conversion it works:
mysql> SELECT BIT_COUNT(b'0010100' & b'0011100') = BIT_COUNT(b'0011100');
+------------------------------------------------------------+
| BIT_COUNT(b'0010100' & b'0011100') = BIT_COUNT(b'0011100') |
+------------------------------------------------------------+
| 0 |
+------------------------------------------------------------+
1 row in set (0.08 sec)
mysql> SELECT BIT_COUNT(b'0010100' & b'0011100') = BIT_COUNT(b'0010100');
+------------------------------------------------------------+
| BIT_COUNT(b'0010100' & b'0011100') = BIT_COUNT(b'0010100') |
+------------------------------------------------------------+
| 1 |
+------------------------------------------------------------+
1 row in set (0.04 sec)
But i cannot do the b' ' command over the value field in the same query:
BIT_COUNT(b'value' & b'$fp') = BIT_COUNT(b'$fp')
This, of course, is wrong...
ARG i'm going crazy! I would really appreciate some help
Thank you very much!
DANIEL