微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

12.30sqlite判断表、字段是否存在

1.判断表名是否存在:

select * from sqlite_master


sqlite_master 的表结构如下:

type|name|tbl_name|rootpage|sql

示范查询结果;

=============
type>>table
name>>android_Metadata
tbl_name>>android_Metadata
rootpage>>3
sql>>CREATE TABLE android_Metadata (locale TEXT)
=============
type>>table
name>>TalkVO
tbl_name>>TalkVO
rootpage>>4
sql>>CREATE TABLE TalkVO (content text,videoPath text,img text,name text,issend BLOB,isPlaying integer,uid integer,_id integer PRIMARY KEY)

2.判断字段是否存在

PRAGMA table_info([TalkVO])

必须 大写,结构如下:

cid |name | type |notnull |dflt_value |pk

示范查询结果;

PRAGMA table_info([TalkVO]) ============= cid>>0 name>>content type>>text notnull>>0 dflt_value>>null pk>>0 ============= cid>>1 1name>>videoPath type>>text notnull>>0 dflt_value>>null pk>>0 ============= cid>>2 name>>img type>>text notnull>>0 dflt_value>>null pk>>0 ============= cid>>3 name>>name type>>text notnull>>0 dflt_value>>null pk>>0 ============= cid>>4 name>>issend type>>BLOB notnull>>0 dflt_value>>null pk>>0 ============= cid>>5 name>>isPlaying type>>integer notnull>>0 dflt_value>>null pk>>0 ============= cid>>6 name>>uid type>>integer notnull>>0 dflt_value>>null pk>>0 ============= cid>>7 name>>_id type>>integer notnull>>0 dflt_value>>null pk>>1

原文地址:https://www.jb51.cc/sqlite/199971.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐