I have the following method to fetch the bank records, and use them in a ListView
, Spinner
, etc:
public ArrayList<CRegistros> getRegistros() {
sqLiteDatabase = banco.getReadableDatabase();
ArrayList<CRegistros> arRegistros = new ArrayList<>();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT *, rg._id _id, cl.nome cliente, sl.nome solicitante " +
"FROM registros rg " +
"LEFT JOIN clientes cl ON cl.handle = rg.cliente " +
"LEFT JOIN solicitantes sl ON sl.handle = rg.solicitante " +
"ORDER BY data DESC, hora DESC, _id DESC", null);
if (cursor != null && cursor.moveToFirst()) {
do {
Integer _id = cursor.getInt(cursor.getColumnIndex("_id"));
Integer tipo = cursor.getInt(cursor.getColumnIndex("tipo"));
String data = cursor.getString(cursor.getColumnIndex("data"));
String horario = cursor.getString(cursor.getColumnIndex("hora"));
String historico = cursor.getString(cursor.getColumnIndex("historico"));
Integer veiculo = cursor.getInt(cursor.getColumnIndex("veiculo"));
Double km = cursor.getDouble(cursor.getColumnIndex("km"));
String cliente = cursor.getString(cursor.getColumnIndex("cliente"));
String solicitante = cursor.getString(cursor.getColumnIndex("solicitante"));
String finalizado = cursor.getString(cursor.getColumnIndex("finalizado"));
CRegistros registros = new CRegistros(_id, tipo, data, horario, historico, veiculo, km, cliente, solicitante, finalizado);
arRegistros.add(registros);
} while (cursor.moveToNext());
}
return arRegistros;
I need to pull only 1 record, so I can edit it, and I have _id
of the record for this search.
I would like to know if to search only 1 record, would it be all this process how do I generate this ArrayList
or would it have a "simpler, more efficient" way to do this?