views:

186

answers:

2

UPDATE I have filed a bug in Doctrine about this http://www.doctrine-project.org/jira/browse/DC-400

I have the following Doctrine schema:

---
TestTable:
    columns:
        bitty: bit(1)

I have created the database and table for this. I then have the following PHP code:

$obj1 = new TestTable();
$obj1['bitty'] = b'0';
$obj1->save();

$obj2 = new TestTable();
$obj2['bitty'] = 0;
$obj2->save();

Clearly my attempt is to save the bit value 0 in the bitty column.

However after running this PHP code I get the following odd results:

mysql> select * from test_table;
+----+-------+
| id | bitty |
+----+-------+
|  1 |      | 
|  2 |      | 
+----+-------+
2 rows in set (0.00 sec)

mysql> select * from test_table where bitty = 1;
+----+-------+
| id | bitty |
+----+-------+
|  1 |      | 
|  2 |      | 
+---+-------+
2 rows in set (0.00 sec)

mysql> select * from test_table where bitty = 0;                
Empty set (0.00 sec)

Those boxes are the 0x01 character, i.e. Doctrine has set the value to 1, not 0.

However I can insert 0's into that table direct from MySQL:

mysql> insert into test_table values (4, b'0');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test_table where bitty = 0;
+----+-------+
| id | bitty |
+----+-------+
|  4 |       | 
+----+-------+
1 row in set (0.00 sec)

What's going on? Is this a bug in Doctrine?

+1  A: 

There is nothing in the doctrine documentation that says Bit is a legal type.

MindStalker
+1  A: 

Doctrine does know the bit type - at least if you're using MySQL and generate Doctrine models from the existing tables. I tried to read a few bit columns and dump the resulting objects. Basically the bit value returned is either \0 or \1, instead of 0 and 1 as I expected.

Karman Kertesz