Reputation: 31
i trying to delete query database in my app but i have a little problem. so, in delete code i have 4 case :
My problem is 3° case, I use an external method to verify if words exists in db! this is code :
public boolean trovato(String n){
boolean find = false;
int k=0;
Cursor c=db.rawQuery("SELECT * from TABLE_NAME", null);
int count= c.getCount();
c.moveToFirst();
String[] nomi = new String[count];
while(c.moveToNext())
{
nomi[k]= c.getString(c.getColumnIndex("fname"));
if(nomi[k].equalsIgnoreCase(n)){
find = true;
break;
}else{
k++;
}
}
return false;
}
public void delete(View data){
EditText delete=(EditText)findViewById(R.id.txtdel);
String delete2 = delete.toString();
Cursor c=db.rawQuery("SELECT * from TABLE_NAME", null);
int count= c.getCount();
if(count==0){
Toast.makeText(getApplicationContext(),"DATABASE VUOTO",Toast.LENGTH_LONG).show();
}
else if(delete.getText().toString().trim().length()==0){
Toast.makeText(getApplicationContext(),"STRINGA VUOTA, RIPROVA", Toast.LENGTH_LONG).show();
}else if(trovato(delete.toString())){
Toast.makeText(getApplicationContext(),"NON ESISTE !!!!",Toast.LENGTH_LONG).show();
}else{
db.execSQL("DELETE FROM TABLE_NAME WHERE fname='"+delete.getText()+"'");
Toast.makeText(getApplicationContext(),"DELETE OK",Toast.LENGTH_LONG).show();
}
}
Upvotes: 1
Views: 103
Reputation: 130
In the function trovato(String n) you are always returning false.
Should be:
return find;
Intead of
return false;
Upvotes: 3