データベースからサーバーにレコードを送信してから削除したいと考えています。これは、サービスで送信および削除するための私のコードです。
DBAdapter db=new DBAdapter(this);
db.open();
Cursor cursor=db.getAllData();
if(cursor.moveToFirst())
{
do{
jObject = new JSONObject();
jObject.put("Imei", cursor.getString(1));
jObject.put("Lat", cursor.getString(2));
jObject.put("Long", cursor.getString(3));
jObject.put("Gpsdatetime", cursor.getString(4));
jObject.put("Speed", cursor.getString(5));
jObject.put("Altitude",cursor.getString(6));
jObject.put("Battery", cursor.getString(7));
//jArray.put(jObject);
String datatoServer = jObject.toString()+"\n";
Toast.makeText(getApplicationContext(),datatoServer, Toast.LENGTH_LONG).show();
HttpEntity entity;
HttpClient client = new DefaultHttpClient();
String url = "http://url";
HttpPost request = new HttpPost(url);
StringEntity se = new StringEntity(datatoServer);
se.setContentEncoding("UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
entity = se;
request.setEntity(entity);
HttpResponse response = client.execute(request);
entity = response.getEntity();
db.deleteContacts(1);
}while(cursor.moveToNext());
}//if
db.close();
削除機能と混同しています。データはサーバーに正しく送信されますが、最初の行のみが削除されます。
ここに私の DBHelper クラスの削除関数があります。これは、rowid をパラメーターとして受け取ります。
public boolean deleteContacts(long rowId)
{
return db.delete(DATABASE_TABLE, KEY_ROWID+"="+rowId, null)>0;
}