2010-01-05 35 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,如我所料。