开发者

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:

  1. Your WHERE-clause is concatenating the word category with the word WHERE.
  2. Does the Integer function do any kind of rationalisation of the value passed to it, which might affect what gets assigned to a?
  3. You display a, but test c.getCount() - are these two values actually the same? (see point 2). Also, is c.getCount() still valid on the second call to it?
  4. There's a } missing somewhere - is the function actually following the path you think it is?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜