2011-09-06 54 views
6

我需要将BOOL值插入到SQLite表中。如果您有任何想法或示例代码,请分享。SQLite插入布尔值

+1

可能重复http://stackoverflow.com/questions/843780/store-boolean-value-in-sqlite) –

+0

[在SQLite中存储布尔值]的可能副本(https://stackoverflow.com/questions/843780/store-boolean-value-in-sqlite) – Flimzy

回答

11

SQLite的可以识别BOOL作为一种类型,然而,它被存储作为由奥利查尔斯沃思理所当然提到的整数。

然而使用BOOL关键字仍然会工作:

CREATE TABLE YourTable(
    isBool BOOL NOT NULL DEFAULT 0, 
); 

INSERT INTO YourTable (isBool) VALUES (1); 
INSERT INTO YourTable (isBool) VALUES (4); 

SELECT * FROM YourTable; 

isBool  
---------- 
1   
4 

将仍然被添加到YourTable

[SQLite中存储布尔值(的