开发者

How to reorder my primary key rows using Java/Android and SQLite DB?

I have a first activity where I create a database and insert some data. In my second activity I remove datas from my DB and the thing that I would like to know is how to reorder my row ID-s to be in consecutive order.

For example, my DB after deleting some rows looks lik开发者_开发问答e this: --------1-------------Question1-------------Answer1---------0 --------3-------------Question2-------------Answer2---------3 --------5-------------Question3-------------Answer3---------5

After exiting my activity, I want to look like this: --------1-------------Question1-------------Answer1---------0 --------2-------------Question2-------------Answer2---------3 --------3-------------Question3-------------Answer3---------5

Tried onDestroy() function using this

@Override

protected void onDestroy() {

  super.onDestroy();

  if (mDbHelper != null) {
      for(int i=0; i<mDbHelper.countRows(); i++){
          try{
              mDbHelper.updateDate(Integer.toString(i++), ggQuestions[i], ggAnswers[i], pozz++);
          }catch(Exception ex){}
      }

      mDbHelper.close();
  }

}

where mDbHelper is my Database, my primary key is String (that's why using integer to string) and my updateDate sql function looks like this:

  mDb.execSQL("UPDATE flagtable SET _id="+_superID+", answer='"+answ+"', position="+
              Integer.toString(pozz)+" WHERE question='"+quest+"'");

I get this error: Failure 19 primary key must be unique when executing UPDATE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜