我试图删除我的应用程序中的查询数据库,但我有一点问题。 所以,在删除代码中我有4个案例:
我的问题是3°情况,我使用外部方法来验证db中是否存在单词! 这是代码:
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();
}
}
答案 0 :(得分:3)
在函数trovato(String n)中,您总是返回false。
应该是:
return find;
的Intead
return false;