删除行并恢复ROWID自动增量 [英] Delete row and restore rowId autoincrement

查看:179
本文介绍了删除行并恢复ROWID自动增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于一个SQL数据库中的行删除的问题。
我的方法使用的ID从onItemClick监听器来识别点击的对象,但只要一个项目被删除,这些ID的不要了,因为他们没有在数据库中的ID行匹配工作。下面就来澄清我的意思是一个例子:

I have a question concerning the deletion of a row in a sql database. My methods use the id from a onItemClick listener to identify the clicked object but as soon as one item is deleted, these id's don't work anymore because they don't match the id row in the database. Here's an example to clarify what I mean:

在的ListView的Andr​​oid

ListView in Android


  • 项目1(ID 0)

  • 项目2(ID 1)

  • 项目3(ID 2)

数据库(ID获取与+1修正投其所好)

Database (id gets corrected with +1 to match up)


  • 项目1(ID 1)

  • 项目2(ID 2)

  • 项目3(ID 3)

删除之后

的ListView


  • 项目1(ID 0)

  • 项目3(ID 1)

数据库


  • 项目1(ID 1)

  • 项目3(ID 3)

当的项目3现在点击,在与该ID 2的数据库中的条目被选择,但现在不导致异常存在

When the Item 3 is clicked now, the entry in the database with the id 2 is chosen but it doesn't exist anymore which causes an exception

我正在寻找一种方法来恢复数据库自动增量ID列

I'm looking for a way to restore the databases autoincrementing id column to


  • 项目1(ID 1)

  • 项目3(ID 2)

编辑:经过一番研究,我不得不得出结论,这是不可能做到这一点。我会尽力找到像一个唯一的标识符,与被请求对象的当前ROWID一起存储在一个单独的表。

After some research I have to conclude that it is not possible to do that. I'll try to find something like an unique identifier which is stored in a separate table along with the current rowid of the requested object.

推荐答案

您必须把ID在你的变量对象,当你点击一个列表项,你必须找到对象的ID并删除它。

You have to put the id's in your variable object and when you click a listitem, you have to find the object's id and delete it.

这个完整的教程。使用翻译器郎

这篇关于删除行并恢复ROWID自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆