Android如何用适当的投影编写查询? [英] Android how to write the query with a proper projection?
本文介绍了Android如何用适当的投影编写查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 TermTable 的 sqlite 表,其中包含 id、selected、term 和 type 列:
I have a sqlite table called TermTable with id, selected, term and type columns:
static final String TermTable = "Terms";
static final String ID = "id";
static final String Selected = "selected";
static final String Term = "term";
static final String Type = "type";
我创建的表如下:
private static final String TERM_TABLE_CREATE = "Create table " + TermTable +
"(" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
Selected + " VARCHAR(5) ," +
Term + " VARCHAR(20) ," +
Type + " VARCHAR(10))";
selected"列获取字符串true"或false".
现在我想查询并获取将字符串作为 term 获取的游标如果它的 selected 列为真,则返回 id 和 type 列:
The column "selected" gets the strings "true" or "false".
Now I want to query and get the cursor which gets a string as a term and if its selected column is true, returns the columns id and type:
public Cursor getFavoriteValues(String term)
{
String from[] = { "id", "type" };
String where = ???
String whereArgs[] = ???
Cursor cursor = db.query(WordsDB.TermTable, from, where, whereArgs, null, null, null, null);
return cursor;
}
这个查询属性是如何定义的?
How are this query attributes defined?
推荐答案
public Cursor getTermValues(String term)
{
String from[] = { "id", "Type" };
String where = WordsDB.Selected + "=? AND " + WordsDB.Term + "=?";
String whereArgs[] = new String[]{ "true", term };
return db.query(WordsDB.TermTable, from, where, whereArgs, null, null, null, null);
}
这篇关于Android如何用适当的投影编写查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文