ndkcha
ndkcha

Reputation: 174

How to perform select query on integer field in SQLite, Android?

SQLiteDatabase database = this.getReadableDatabase();
        Cursor cursor = database.rawQuery(selectAll + DatabaseSchema.Vehicles.TABLE_NAME + " where " + DatabaseSchema.Vehicles.COLUMN_ID + "=" + id, null);
        cursor.moveToFirst();

Here, selectAll = "select * from ", and COLUMN_ID is has int datatype. This code returns an empty cursor everytime. Even though data is inserted in table. When I run query with only "select * from tablename". It gives me data.

Upvotes: 0

Views: 553

Answers (1)

Jorgesys
Jorgesys

Reputation: 126563

I think that your problem is when you are accesing with cursor.moveToFirst(); try this instead:

SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.rawQuery(selectAll + DatabaseSchema.Vehicles.TABLE_NAME + " where " + DatabaseSchema.Vehicles.COLUMN_ID + "=" + id, null);
if (cursor != null && cursor.moveToFirst()) {
    do {
    //Do your stuff!
    } while (cursor.moveToNext());
}
cursor.close();

Upvotes: 1

Related Questions