2010-01-05 85 views
0

UPDATE我在学说提出了错误这个http://www.doctrine-project.org/jira/browse/DC-400PHP - Doctrine ORM无法正确处理bit(1)类型?

我有以下Doctrine模式:

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

我已经创造了这个数据库和表。然后,我有下面的PHP代码:

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

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

显然,我的尝试是保存在bitty列的位值0

但是运行此PHP代码,我得到以下奇怪的结果后:

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) 

那些箱子是0x01字符,即学说的值设置为1,不是0

不过,我可以将0直接从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) 

发生了什么事?这是教义中的错误吗?

回答

2

说明文档中没有说Bit是合法类型的东西。

1

学说确实知道位类型 - 至少如果您使用MySQL并从现有表生成Doctrine模型。 我试图读取几个列并转储结果对象。基本上返回的位值是\ 0或\ 1,而不是0和1,如我所料。