现在我有以下代码:
SQLiteDatabase db=getReadableDatabase();
SQLiteQueryBuilder qb=new SQLiteQueryBuilder();
String[] sqlSelect={"0 _id","lang","value"};
String sqlTables="gloss";
qb.setTables(sqlTables);
Cursor c=db.query(GL_TABLE, sqlSelect, "value like '%"+inputText+"%'", null, null, null, null, "20");
它工作完美。这里这段代码只占用一张桌子。如何从相互关联的 3 个表中获取数据(entry 是主节点,sense 是 entry 的子节点,gloss 是 sense 的子节点):
条目(id,ent_seq);感觉(id,fk);光泽度(id,fk,lang,值);
是否可以使用 setTables 做到这一点?如果是,请给出一些建议如何做到这一点。
我已经按照@Anders8 所说的那样做了:
public Cursor getJoinedInfo(String lookingFor)
{
Log.d(LOG_TAG, "DB: looking up info");
SQLiteDatabase db=getReadableDatabase();
Cursor cursor;
String query;
query="SELECT " +
" e.id," +
" s.id," +
" s.fk," +
" g.id," +
" g.fk," +
" g.lang," +
" g.lang" +
" FROM entry e" +
" INNER JOIN sense s ON e.id = s.fk" +
" INNER JOIN gloss g ON s.id = g.fk" +
" WHERE g.value like '%"+lookingFor+"%'";
Log.d(LOG_TAG, "DB: query = \n" + query.replace(", ",",\n "));
cursor=db.rawQuery(query,null);
Log.d(LOG_TAG, "DB: query complete");
return cursor;
}
它给出了这个错误:
08-09 22:26:16.632: E/AndroidRuntime(9842): java.lang.IllegalArgumentException: 列 '_id' 不存在
我应该怎么办?