android - Join tables in SQLiteQueryBuilder setTables -
now have following code:
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 '%"+inputtext+"%'", null, null, null, null, "20"); it working perfect. here code taking 1 table. how take data 3 tables related each other(entry main node, sense child of entry , gloss child of sense):
entry(id,ent_seq); sense(id,fk); gloss(id,fk,lang,value);
is possible settables? if is, please give suggestions how this.
i have done @anders8 said:
public cursor getjoinedinfo(string lookingfor) { log.d(log_tag, "db: looking info"); sqlitedatabase db=getreadabledatabase(); cursor cursor; string query; query="select " + " e.id," + " s.id," + " s.fk," + " g.id," + " g.fk," + " g.lang," + " g.lang" + " entry e" + " inner join sense s on e.id = s.fk" + " inner join gloss g on s.id = g.fk" + " g.value '%"+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; } it giving error:
08-09 22:26:16.632: e/androidruntime(9842): java.lang.illegalargumentexception: column '_id' not exist
what should do?
it's going this:
public cursor getjoinedinfo(string lookingfor) { log.d(tag, "db: looking info"); cursor cursor; string query; query="select " + " a.fieldname1," + " a.fieldname2," + " b.fieldname3," + " c.fieldname4" + " tablename1 a" + " inner join tablename2 b on a.somekeyina = b.somekeyinb" + " inner join tablename3 c on a.someotherkeyina = c.somekeyinc" + " a.fieldname ='" + lookingfor +"'"; log.d(tag, "db: query = \n" + query.replace(", ",",\n ")); cursor=db.rawquery(query,null); log.d(tag, "db: query complete"); return cursor; } obviously, build query need. ;)
Comments
Post a Comment