samedi 27 juin 2015

The sql query does not pass the arguments

I'm writing an android application and I need to search the data base, this is the method I use:

public Cursor getData(String table, String keyword, SQLiteDatabase db){

    String selection;
    Cursor cursor;

    switch (table){
        case "User":
            String [] projection = {id,name,phone};
            selection = "name LIKE ?";
            String [] selection_arg = {keyword};
            cursor = db.query("User",projection,selection,selection_arg,null,null,null);
            //cursor = db.rawQuery("select * from User" + " WHERE name"+
            //                        " LIKE %?%",selection_arg);

            break;
        //omitted
        default:
            return null;
    }
    return cursor;

The user put in the keyword

keyword = search_user.getText().toString();
Cursor cursor = dbHelper.getData(ShippingApplication.User.USER_TABLE,keyword,db);

The code does not work, when I debug, I see the mQuery of the db variable is: SQLiteQuery: SELECT userID, userName, phoneNumber FROM User WHERE userName LIKE ? It looks like the query does not pass the value of the keyword in to the sql command. Could someone tell me what's wrong?

Aucun commentaire:

Enregistrer un commentaire