Home > Database > Mysql Tutorial > body text

sqlite数据库boolean类型的小小测试

WBOY
Release: 2016-06-07 16:21:37
Original
1330 people have browsed it

sqlite数据库中没有没有独的Boolean存储类,,Booean值以整数0(false)和1(true)存储, 经我段时间的实践, boolean 有三种状态, 0(false) 1(true) 和 null,如下图所示, 经过下列插入语句,测试,均可插入成功.而且, 可以通过 select * from stu where flag =数据库

   sqlite数据库中没有没有独的Boolean存储类,,Booean值以整数0(false)和1(true)存储, 经我段时间的实践, boolean 有三种状态, 0(false) 1(true) 和 null,如下图所示,

  经过下列插入语句,测试,均可插入成功.而且, 可以通过

  select * from stu where flag ="数据库"

  查询到name 为a9 的行.

  insert into stu (name,flag) values ('a1','true'); -- 0

  insert into stu (name,flag) values ('a2','ture'); -- 0

  insert into stu (name,flag) values ('a3',1); -- 1

  insert into stu (name,flag) values ('a4','null'); --0

  insert into stu (name,flag) values ('a5','1'); --1

  insert into stu (name,flag) values ('a6',null); -- 2

  insert into stu (name,flag) values ('a7','2'); --1

  insert into stu (name,flag) values ('a8',15); --1

  insert into stu (name,flag) values ('a9',"数据库"); --0

  导出数据库,可以发现,执行的sql语句是这样的,

  insert into [stu] values('a1', 0);

  insert into [stu] values('a2', 0);

  insert into [stu] values('a3', 1);

  insert into [stu] values('a4', 0);

  insert into [stu] values('a5', 1);

  insert into [stu] values('a6', null);

  insert into [stu] values('a7', 1);

  insert into [stu] values('a8', 1);

  insert into [stu] values('string', 0);

  insert into [stu] values('string2', 0);

  insert into stu (name,flag) values ('a9',0); --0

  如此, 猜想, sqlite 是采用了 字符型存储插入的boolean类型数据, 但是,取出的时候, 会将插入的字符型数据转换成int类型来使用.

  因此,可以得到下面的结论:

  -- 字符可转换为int类型的为 ture, 转换失败的为 false(0) ,int ,long double 等整形为 ture(1) , 布尔类型报错, null为 null

  ps: 尚未对其进行深入了解,目前是实践测试的结论,纯属猜测,如果有知情者,可告知.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template