How to format the WHERE clause and '?' in a SQLite query?
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 */
);
You may not use quotes around the question marks
example:
db.query(
true,
"tablename",
new String[] {
"col1",
"col2"
},
"col1 = ?",
new String[]{ "value" },
null,
null,
null,
null
);
精彩评论