Sqlite判断字段存在

判断表存在的方法很简单,网上很多:

SELECT COUNT(*) FROM sqlite_master where type='table' and name='%s'" % tname;

 

那么判断字段是否存在, 或者说如何判断表的版本是否最新就只需要:

select * from sqlite_master where tbl_name='tblContactList';

 

sqlite_master 的表结构如下:

type   |name    |tbl_name    |rootpage   |sql

 

最后一个sql就是创建tblContactList表的sql语句, 所以只要判断这个sql语句是否和你的创建语句一样就可以知道该表是不是你最新的版本.

你可能感兴趣的:(Sqlite判断字段存在)