amorenew
amorenew

Reputation: 10906

why rawQuery is working and query isn't working?

I am using query for search but i don't understand why one code is work and another one not work ?!

this is working:

          String selectQuery = "SELECT  * FROM " + TABLE_Soras
                               +" WHERE "+KEY_SoraName+" LIKE '%"+soraName+"%'";
          Cursor cursor = db.rawQuery(selectQuery,null);

but this isn't get any result:

    Cursor cursor = db.query(TABLE_Soras, new String[]{
             KEY_SORA_NO, KEY_SoraName}, KEY_SoraName + "=?",
            new String[]{soraName}, null, null, null, null);*/

Upvotes: 0

Views: 125

Answers (3)

Pavlos
Pavlos

Reputation: 2181

Cursor cursor = your_database.query(MY_TABLE, new String[] {"first_column","second_column"},your_column + " LIKE '%"+your_criteria+"%'", null, null, null, null);

Try something like this and it will probably work!

Upvotes: 0

Simon Dorociak
Simon Dorociak

Reputation: 33515

Because in second case % is not appended into value and you didn't add LIKE clause into query. You need to use this:

KEY_SoraName + " like ?", new String[] {"%" +soraName + "%"} ...

Upvotes: 2

Sanket Shah
Sanket Shah

Reputation: 4382

Try this

Cursor cursor = db.query(TABLE_QuranSoras, new String[]{
             KEY_SORA_NO, KEY_SoraName}, KEY_SoraName+" LIKE '%"+soraName+"%'", null, null, null, null);

Upvotes: 0

Related Questions