In android I have a cursor where it looks for the data in the database and perfectly returns the data but ..
How do I insert a second cursor into the first one?
to pull data from a second table
My code
try {
StringBuilder sbQuery = new StringBuilder();
sbQuery.append("select * from contatos");
//
Cursor cursor = db.rawQuery(sbQuery.toString(), null);
//
while (cursor.moveToNext()) {
HMAux_Contatos hmAux = new HMAux_Contatos();
hmAux.put(
HMAux_Contatos.ID,
cursor.getString(cursor.getColumnIndex("id_contato")))
;
hmAux.put(
HMAux_Contatos.NOME,
cursor.getString(cursor.getColumnIndex("nome")))
;
StringBuilder sbQuery2 = new StringBuilder();
sbQuery.append("select * from contatos_numeros where id_contato = "+hmAux.get(HMAux_Contatos.ID)+" and principal = '1' ");
Cursor cursor2 = db.rawQuery(sbQuery2.toString(), null);
hmAux.put(
HMAux_Contatos.DESCRICAO,
cursor2.getString(cursor2.getColumnIndex("descricao")))
;
hmAux.put(
HMAux_Contatos.NUMERO,
cursor2.getString(cursor2.getColumnIndex("numero")))
;
cursor2.close();
cursor2 = null;
//
dados.add(hmAux);
}
cursor.close();
cursor = null;
} catch (Exception e) {
Log.d("#Erro Do Servidor", String.valueOf(e));
}
Without the second cursor, it works perfect but obviously the data is missing parts since the other data is in a second table