mardi 30 décembre 2014

Android delete query database

i trying to delete query database in my app but i have a little problem. so, in delete code i have 4 case :



  1. database empty -> MESSAGE TOAST DATABASE EMPTY

  2. txtfield empty -> MESSAGE TOAST TXTFIELD EMPTY

  3. words in txtfield not found in DB -> MESSAGE TOAST word no found

  4. deleted OK -> DELETE QUERY + TOAST NOTIFICATION


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();
}
}

Aucun commentaire:

Enregistrer un commentaire