如何检查SQLite中为Android的表行是否存在 [英] how to check whether row exists or not in a table of sqlite for android
问题描述
我要检查的SQLite表的行是否在数据库中存在或not..If行存在我应该叫一类,否则另一个class.To得到这个功能,我使用
I want to check whether a row of the sqlite table exists in database or not..If row exists i should call a class otherwise another class.To get this functionality i am using
public boolean Exists(int position) {
SQLiteDatabase db = (placeData).getReadableDatabase();
Cursor cursor = db.rawQuery("select * from pages where bbookid ='"+ position +"'", null);
boolean exists = (cursor.getColumnName(position)) != null;
Log.i("logs","fads");
if(exists=true)
{
getDataAndPopulate();
}
else
{
Log.i("qefw","cursors");
new LoadAllProducts().execute();
}
cursor.close();
return exists;
}
但使用这种code中的行重新插入..Could有人建议我接近的功能的方法。
but using this code the rows are reinserting ..Could anyone suggest me the way to approach the functionality
推荐答案
您平等检查失败,因为这个前pression被评估为真正
:
Your equality check is failing because this expression is evaluating to true
:
if(exists=true)
当你有一个等号,这意味着的分配的。您正在分配真正
到存在
,而不是比较存在
到真正
。分配的结果是值到存在
被分配(真正
)。
When you have a single equals sign, it means assignment. You are assigning true
to exists
, instead of comparing exists
to true
. The result of the assignment is the value to which exists
was assigned (true
).
尝试适当平等的操盘手:
Try the proper equality operator instead:
if (exists == true)
请参阅此相关的帖子再看看这个问题。
See this related post for another look at this issue.
这篇关于如何检查SQLite中为Android的表行是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!