sri
sri

Reputation: 31

SQLite query is not returning true value

I entered the following code for comparing the records with 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.

Upvotes: 0

Views: 92

Answers (2)

Eight-Bit Guru
Eight-Bit Guru

Reputation: 9961

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?

Upvotes: 0

Aliostad
Aliostad

Reputation: 81660

put a space after WHERE:

 "SELECT * FROM  sharelist  WHERE "  + "category" + "=" + category,null

That should work.

Upvotes: 2

Related Questions