I want to return the value of sqlite insert. In my code when the insert operation fail return -1 (API sqlite said: "the row ID of the newly inserted row, or -1 if an error occurred"). The problem is that always the insercion fail I recive other value in my code.
//Function in my class DAtabase
public int insert(HashMap<String, String> queryValues,String table) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
long result = 0;
switch (table) {
case "Log":
values.put("relacion", queryValues.get("relacion"));
values.put("objetoPadre", queryValues.get("objetoPadre"));
values.put("objeto", queryValues.get("objeto"));
values.put("interaccion", queryValues.get("interaccion"));
values.put("tiempo", queryValues.get("tiempo"));
values.put("sincro", queryValues.get("sincro"));
result=database.insert("Log", null, values);
database.close();
System.out.println("Value:"result);
return (int) result;//result here is -1
case "Conf_spinner":
values.put("relacion",queryValues.get("relacion"));
values.put("interaccion",queryValues.get("interaccion"));
database.insert("Conf_spinner", null, values);
database.close();
System.out.println("Value:"result);//result here is -1
return (int) result;
default:
database.close();
return 1;
break;
}
}
This part of the code return -1 if the insercion fail or other value in other case.
Here is where i have problems
//Code of my android activiy
int value = myDatabase.insert(queryValues, "Conf_spinner");
if(value==-1) //value always set other number that isn't -1.
showMessaging();
else
Log.e("MyTag","FAIL INSERCION");
Tkans for the help
Aucun commentaire:
Enregistrer un commentaire