그래서 두 데이터베이스를 비교하려고합니다. 하나는 읽기 전용이고 다른 하나는 읽기 전용 만 추가하고 다른 하나는 삭제하는 것입니다 읽기 전용 데이터베이스에는 없습니다. 본질적으로 데이터 동기화.즉석에서 데이터를 비교하는 두 개의 데이터베이스 ... 구현에 대한 조언이 필요합니다.
이 시점에서 나는 데이터를 포함하는 두 개의 커서 (하나는 arraylist로 변환 함)와 각 키를 비교하는 데 사용되는 하나의 필드가 있습니다. 다음은 샘플입니다. 읽기 전용을 반복하면서 arraylist의 각 항목을 검색하는 대신 읽기 전용을 검색 할 때와 같이 반대쪽을 검색해야하는 것처럼 느껴집니다. 이 폼을보다 빠르고 안정적으로 만들기 위해 폼이나 커서를 비교해보고 싶습니다. 어떤 아이디어 나 제안?
ArrayList<String> addImg = new ArrayList<String>();
ArrayList<String> delImg = new ArrayList<String>();
image_store = m_db.getAllImages();
// this returns an arraylist of strings(can also change to return a cursor)
local_images = img_db.getAllImages();
image_store.moveToFirst();
while(!image_store.isAfterLast()) {
key = image_store.getString(image_store.getColumnIndexOrThrow("name"));
// check if stored locally, if not add it to array.
if(Arrays.binarySearch(local_images, key) == -1) {
addImg.add(image_store.getString(image_store.getColumnIndexOrThrow("name")));
} else {
delImg.add(key);
}
image_store.moveToNext();
}
if(!addImg.isEmpty()) {
// this will loop through and delete from a cursor generated on another query
addImages(addImg);
}
if(!delImg.isEmpty()) {
// this will loop through and delete from a cursor generated on another query
delImages(addImg);
}
제안 해 주셔서 감사합니다. 나는 각 칼럼에 대한 indecies가 확실하다. 나는이 질문을 안드로이드 특정 커서와 관련이 있으며이를 구현하는 가장 좋은 방법은 무엇일까요? 이미 작동중인 솔루션이 있지만 여러 임시 배열을 유지 관리해야합니다. – Du3