您好,我正在通过单击按钮将我的数据库与服务器同步以获取任何增量值。下面是检查所有值并在数据丢失时插入的代码,但从 android 的角度来看,是否有任何优化的技术来进行同步
//new fields
public void updatenewfileds(ArrayList<String> s) {
ArrayList<String> da = new ArrayList<String>();
try {
String manu = "select MANUFACTURERID from ManufacturerDesc";
Cursor cc = mDb.rawQuery(manu,null);
Log.d("Cursor count", "Count =" + cc.getCount());
if (cc != null && cc.getCount() > 0) {
if (cc.moveToFirst());
do {
da.add(cc.getString(cc.getColumnIndex("MANUFACTURERID")));
System.out.println("here got all alreday avilable ids"+ cc.getString(cc.getColumnIndex("MANUFACTURERID")));
} while (cc.moveToNext());
cc.close();
} else {
cc.close();
}
// need to add only missing data
for(int i = 0; i<da.size(); i++){
boolean flag = false;
System.out.println(flag);
for(int j=0; j<i; j++){
if(da.get(i).equals(s.get(i*2))){
flag = true;
break;
}
}
if(flag == false){
String sql = "insert into ManufacturerDesc values('"+ s.get(i*2)+"','"+ s.get(i*2+1)+"');";
System.out.println("item inserted into db"+ s.get(i*2) +"******" + s.get(i*2+1) );
mDb.execSQL(sql);
}
}
} catch (SQLException mSQLException) {
Log.e(TAG, "getTestData >>" + mSQLException.toString());
throw mSQLException;
}
}