I need to insert BOOL
value into SQLite table. If you have any thoughts, or sample code please share.
Asked
Active
Viewed 1.9k times
6

Hemang
- 26,840
- 19
- 119
- 186

LightNight
- 1,616
- 6
- 30
- 59
-
1possible duplicate of [Store boolean value in SQLite](http://stackoverflow.com/questions/843780/store-boolean-value-in-sqlite) – Oliver Charlesworth Sep 06 '11 at 08:12
-
Possible duplicate of [Store boolean value in SQLite](https://stackoverflow.com/questions/843780/store-boolean-value-in-sqlite) – Jonathan Hall Jun 19 '17 at 20:27
2 Answers
18
From http://www.sqlite.org/datatype3.html:
SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

Oliver Charlesworth
- 267,707
- 33
- 569
- 680
10
SQLite can recognize the BOOL as a type, however it is stored as an integer rightfully mentioned by Oli Charlesworth.
However using the BOOL keyword would still work:
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
4 would still be added to YourTable

apouche
- 9,703
- 6
- 40
- 45