sukh punjabi
sukh punjabi

Reputation: 69

SQlite query with two constraint

I have something like this. I want query to see if the date AND username matches the provided strings(parameters) and return the result. I tried the syntax below but it is giving me error. Thank you for your help

    public String getOneDayEvents(String date, String username) {
    String[] columns = new String[] { KEY_TITLE, KEY_DESCRIPTION,
            KEY_START_TIME, KEY_END_TIME };
    Cursor c = ourDataBase.query(DATABASE_TABLE_EVENTS, columns, KEY_DATE
            + " like ? " + KEY_REF + " like ?", new String[] {date,username}, null, null, null);
    String result = "";

    int iTitle = c.getColumnIndex(KEY_TITLE);
    int iDesc = c.getColumnIndex(KEY_DESCRIPTION);
    int istartTime = c.getColumnIndex(KEY_START_TIME);
    int iendTime = c.getColumnIndex(KEY_END_TIME);

}

Upvotes: 1

Views: 87

Answers (1)

mu is too short
mu is too short

Reputation: 434665

You need to join your conditions with AND:

Cursor c = ourDataBase.query(DATABASE_TABLE_EVENTS, columns, KEY_DATE
        + " like ? and " + KEY_REF + " like ?", new String[] {date,username}, null, null, null);
//-----------------^^^

Upvotes: 1

Related Questions