SQLite query is not returning true value
I entered the following code for comparing the records w开发者_运维知识库ith the database records. It is executing but it shows already exists for every entering record (it may be an old or new record.)
boolean ifExisting() {
//Cursor c = db.rawQuery("SELECT * FROM sharelist WHERE category='"+str1+"'",null);
Cursor c = db.rawQuery("SELECT * FROM sharelist WHERE" + "category" + "=" + category,null);
Integer a=new Integer(c.getCount());
Log.e("getcount",a.toString());
if(c.getCount()>-1)
{ return false;}
else{
return true;
}
please help me.
put a space after WHERE:
"SELECT * FROM sharelist WHERE " + "category" + "=" + category,null
That should work.
Possible issues:
- Your WHERE-clause is concatenating the word
category
with the wordWHERE
. - Does the
Integer
function do any kind of rationalisation of the value passed to it, which might affect what gets assigned toa
? - You display
a
, but testc.getCount()
- are these two values actually the same? (see point 2). Also, isc.getCount()
still valid on the second call to it? - There's a
}
missing somewhere - is the function actually following the path you think it is?
精彩评论