How the SQLite database determines whether a table or field exists

Source: Internet
Author: User
Tags sqlite sqlite database

1. Determine if the table name exists:

SELECT * FROM Sqlite_master

The table structure of the Sqlite_master is as follows:

Type |name |tbl_name |rootpage |sql

Model query results;

=============
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 , _id integer PRIMARY KEY)

2. Determine whether the field exists

PRAGMA Table_info ([Talkvo])

Must be capitalized, structured as follows:

CID | name | Type | Notnull |  Dflt_value | Pk

Model query results;

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.