user834900
user834900

Reputation:

SQLiteDatabase Query in android

Am having a table card with colums id,name, content,status, date.

i want to take id,name,content condition is status <= cards.STATUS also have to sort it by date

How i have to do this. am doing like,

private Cursor c;

String[] cols = { id,name, content };
c = cardsDB.query(CARDS_TABLE_NAME, cols, "status <=" + Card.STATUS, null, null, null, "date desc");

if (c.moveToFirst()) {
            do {
                CardArray.add(new Card(c.getInt(0), c.getInt(1), c.getString(2)));
            } while (c.moveToNext());
        }
        c.close();

Upvotes: 1

Views: 120

Answers (1)

vikas
vikas

Reputation: 139

When you have the complicated query , its better to use raw query not query method.

This is an example of how to implement a raw query:

String query= "Select id,name ,content  from CARDS_TABLE_NAME Where status <= ? date desc";
Cursor c= database.rawQuery(query, new String[]{Card.STATUS});

Upvotes: 1

Related Questions