안드로이드 개발 질문/답변
(글 수 45,052)
android 에서 update 문에 대해서 문의 드립니다.
제가 날리고 싶은 쿼리는 다음과 같습니다.
아래와 같이 테이블 스키마와 데이터가 있다고 했을때
SEQ title ..... order
1 가나다 1
2 마바사 2
3 아자차 3
4 하하하 4
update "테이블 명" set order = order + 4 where order >= 3
이런 식입니다.
contentProvider 에서 제공하는 함수로 이 부분을 구현하려고 하니
select * from "테이블 명" where order >= 3 라는 쿼리를 수행한후 커서를 얻어와서
커서를 루프 돌면서 레코드한개씩 update 해야하는것 같은데,
코드상으로는 아래와 같습니다.
private void updateOrder(Context context, int startSeq, int incValue) {
ContentValues values;
// update 대상인 DATA 만 가져온다.
Cursor c = context.getContentResolver().query(
ListProvider.LIST_CONTENT_URI,
null,
ListDBHelper.KEY_LIST_ORDER + " >= " + startSeq,
null,
ListDBHelper.KEY_LIST_ORDER + " ASC"
);
if(c.moveToFirst())
do {
values = new ContentValues();
values.put(ListDBHelper.KEY_LIST_ORDER, c.getInt(ListDBHelper.LIST_ORDER_COLUMN));
context.getContentResolver().update(Uri.parse(ListProvider.LIST_CONTENT_URI + "/" + c.getInt(ListDBHelper.ID_COLUMN)), values, null, null);
values.clear();
} while (c.moveToNext());
c.close();
}이렇게 하니 너무 느리네요
좋은 방법이 없을까요??




row.put(...);
String[] whereArsg = new String[]{... 조건절...};
getWritableDatabase().update(tablename,row," id=?",wherearsg);