我在删除sqlite数据库中的行时遇到了麻烦。
我要做的是获取我想要从远程数据库中删除的ID,然后使用它们删除SQLite数据库中的行。
但到目前为止还没有工作
这是我首先删除项目,然后根据需要插入项目。
// Method to Sync MySQL to SQLite DB
public void syncSQLiteMySQLDB() {
// Create AsycHttpClient object
AsyncHttpClient client = new AsyncHttpClient();
// Http Request Params Object
RequestParams params = new RequestParams();
// Show ProgressBar
prgDialog.show();
//Llamada HTTP a getdeletes.php
client.post("http://restaurantechinaimperial.com/mysqlsqlitesync/getDeletes.php", params, new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String response) {
deleteSQLite(response);
}
});
// Make Http call to getplatos.php
client.post("http://restaurantechinaimperial.com/mysqlsqlitesync/getplatos.php", params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
// Hide ProgressBar
prgDialog.hide();
// Update SQLite DB with response sent by getusers.php
updateSQLite(response);
}
// When error occured
@Override
public void onFailure(int statusCode, Throwable error, String content) {
// TODO Auto-generated method stub
// Hide ProgressBar
prgDialog.hide();
if (statusCode == 404) {
Toast.makeText(getApplicationContext(), "Recurso no encontrado", Toast.LENGTH_LONG).show();
} else if (statusCode == 500) {
Toast.makeText(getApplicationContext(), "Algo ha fallado en el servidor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Error Inesperado! [Razon mas probable: El dispositivo no esta conectado a Internet]",
Toast.LENGTH_LONG).show();
}
}
});
}
这是调用sqlitecontroller中的方法来删除的方法。
public void deleteSQLite(String response){
try {
// Extract JSON array from the response
JSONArray arr = new JSONArray(response);
System.out.println(arr.length());
// If no of array elements is not zero
if(arr.length() != 0){
// Loop through each array element, get JSON object which has deleteid
for (int i = 0; i < arr.length(); i++) {
// Get JSON object
JSONObject obj = (JSONObject) arr.get(i);
String id=obj.getString("Id");
controller.deletePlato(id);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是sqlitehelper上的delete方法
public void deletePlato(String deleteid){
SQLiteDatabase database = this.getWritableDatabase();
database.delete("platos", "platoId = 'deleteid'", null);
database.close();
}
有人可以帮忙吗?