How to format the WHERE clause and '?' in a SQLite query?

advertisements

I'm trying to use the built in SQLite functions and I'm not sure how to format a query. How do I format the WHERE clause and the ? that can go in there:

column [] = {"name"};
selectionArg [] = {"john};
Select name from mytable where id = "john"

db.query(mytable, column, id = ?, selectionArg, null,null,null);

I'm not to where I can test it, but I'm trying to get it right the first time. I'm not sure if the ? needs to be "?" or if it is id = + "?" and so forth. I can't seem to find any examples of the format.


For the query :

select name from mytable where id = "john"

use

(SQliteDatabase) db.query(
    "mytable" /* table */,
    new String[] { "name" } /* columns */,
    "id = ?" /* where or selection */,
    new String[] { "john" } /* selectionArgs i.e. value to replace ? */,
    null /* groupBy */,
    null /* having */,
    null /* orderBy */
);