jeudi 1 octobre 2015

SQLite DB select method with different types in where clause

I have the following code that works and gets a record from a database.

public Audit getAudit(SQLiteDatabase db, String projectId, String date,String type, int category) {
    String[] columns = { "user_id", "submitted", "answers" };
    String[] whereArgs = new String[]{projectId, date, type};

    Cursor c = db.query("AUDITS", columns, "project_id = ? AND date = ? AND type = ?",whereArgs, null, null, null);
    if (c != null)
    {
        Audit audit = new Audit(projectId, type, category, c.getString(c.getColumnIndex("user_id")), date, c.getInt(c.getColumnIndex("submitted")), c.getString(c.getColumnIndex("user_id")));
        return  audit;
    }
    return null;
}

But now I want to add another column to the Where clause, and this column holds an integer and not a string. So I can not add it to whereArgs array which holds strings. Is there a way that I can still use this method with mixing types or do I need to just do a raw query??

Aucun commentaire:

Enregistrer un commentaire