Hello I have a database in sqlite and it happens that I must add fields to a table that contains an id "integer primary key unique", the id can not be increased by other issues. The data that I add to the table I download from a webservice, now I need to know how to make a validation to show the user a "data already inserted" message.
In the webservice an admin enters data and in the android app a user downloads them through a button. The admin may enter a data one day, and another data another day, and in the app you should only download the "new data." Here I leave the code
listCreditos = Response.List_Creditos_All;//listCreditos es un list que guarda todos los registros obtenidos del webservice
//Despues se hace una consulta a la tabla sqlite
bd = con.getReadableDatabase();
tring query = "Select * from " + _inicio.TInicio + " where idusuario= '" + Request.IdUsuario + "'";
Cursor cursor = bd.rawQuery(query, null);
if (cursor.getCount() == 0)//si la tabla esta vacia insertara los datos sin problema
{
for (int i = 0; i < listCreditos.size(); i++)
{
inicio = listCreditos.get(i);
//se guardaran en un metodo ya establecido
con.creditos(inicio.getId(), inicio.getMonto(), inicio.getMontoActual(), inicio.getLocalidad(), inicio.getMunicipio(), inicio.getCP(), inicio.getEstado());
}
return true;
}
}
//si la tabla tiene 1 o mas registros
else if (cursor.getCount() >= 1) {
cursor.moveToFirst();
do {
//aqui guardo cada dato en el modelo de mi tabla
inicio = new Inicio(inicio);
inicio.setId(cursor.getInt(cursor.getColumnIndexOrThrow(_inicio.id)));
....//
)));
} while (cursor.moveToNext());
cursor.close();
Now how should I do a validation to save only those records that do not exist in my sqlite table. I hope you have given me to understand. Thanks