检查如果列存在于Android的应用程序数据库 [英] Checking if a column exists in an application database in Android
问题描述
有没有在Android的一个很好的方法,如果一列存在于表中的应用程序数据库? (我知道有一个与此相似的问题已经,但似乎并没有任何是安卓专用。)
Is there a nice way in Android to see if a column exists in a table in the application database? (I know there are questions similar to this one already, but there don't seem to be any that are Android specific.)
推荐答案
cursor.getColumnIndex(字符串COLUMNNAME)
返回-1如果列不存在。所以,我基本上执行像SELECT * FROM XXX极限0,1,并使用光标以确定是否列,你正在寻找一个简单的查询,存在
cursor.getColumnIndex(String columnName)
returns -1 if, the column doesn't exist. So I would basically perform a simple query like "SELECT * FROM xxx LIMIT 0,1" and use the cursor to determine if the column, you are looking for, exists
或
您可以尝试查询栏选择theCol从xxx,并捕获异常
you can try to query the column "SELECT theCol FROM xxx" and catch an exception
这篇关于检查如果列存在于Android的应用程序数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!