SQLite添加字段时,字段已存在问题,SQLite会报错,提示“字段重复”的问题
Caused by: android.database.sqlite.SQLiteException: duplicate column name: school(Sqlite code 1): , while compiling:
ALTER TABLE 'AA' ADD 'school' STRING(255);,(OS error - 2:No such file or directory)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
如何在添加字段时,能判断字段是否显示呢?
1、SQLite没有直接处理的函数或方法,要处理可能这样的思路:
A、创建一张新表AA,包含原表全部字段和要新增加的字段。
B、将原表的数据全部COPY到新表结构中。
C、删除原表
D、将新表的表名修改为原表的表名
2、要查询某个表或字段在SQLite中是否存在,可通过如下语句实现:
select * from sqlite_master where name='tablename' and sql like '%fieldname%';