Sumit
Sumit

Reputation: 928

android sqlite query with multiple where

I am using sqlite in android where i am fetching result by passing multiple where clause, which gives me an error. Single where clause works fine for me problem is with multiple where clause. suggest me the changes or identify the mistake I am doing please

Error message with query

ERROR/AndroidRuntime(837): Caused by: android.database.sqlite.SQLiteException: 
no such column: Maharashtra:,while compiling: SELECT _id, r_shop FROM retailer 
WHERE r_state = Maharashtra AND r_city = Thane AND r_region = Checknaka

String selection = MySQLiteHelper.STATE + " = Maharashtra"  
                +" AND " + MySQLiteHelper.CITY + " = Thane"
                +" AND " + MySQLiteHelper.REGION + " = Checknaka";

        Cursor cursor = database.query(MySQLiteHelper.RETAILER_TABLE, 
                    new String[] {MySQLiteHelper.COLUMN_ID, MySQLiteHelper.SHOP }, selection, 
                    null, null, null, null);

Upvotes: 2

Views: 6903

Answers (1)

Nermeen
Nermeen

Reputation: 15973

String selection = MySQLiteHelper.STATE + " = 'Maharashtra'"  
            +" AND " + MySQLiteHelper.CITY + " = 'Thane'"
            +" AND " + MySQLiteHelper.REGION + " = 'Checknaka'";

    Cursor cursor = database.query(MySQLiteHelper.RETAILER_TABLE, 
                new String[] {MySQLiteHelper.COLUMN_ID, MySQLiteHelper.SHOP }, selection, 
                null, null, null, null);

May be the reason is that, you are refering to Strings without ''

Upvotes: 10

Related Questions