简体   繁体   English

在sqlite中删除第一行后如何重新排列表?

[英]How to rearrange table after deleting first row in sqlite?

I have 1 table in sqlite, I am inserting values to that table. 我在sqlite中有1个表,正在向该表中插入值。 when the insertion row id greater than 100 I want to delete first inserted record and insert new record at 100th location, I am deleted 1st record but 2nd record in 2nd place but i want rearrange the record after deleting first row. 当插入行ID大于100时,我想删除第一个插入的记录并在第100个位置插入新记录,我删除了第一个记录,但第二个记录在第二个位置,但是我想在删除第一行后重新排列记录。 How can I do it? 我该怎么做?

My table name is: Products 我的表格名称是:产品

My table contains productName,productId,... 我的表包含productName,productId,...

My DatabaseName is: HalalGauge.sqlite 我的数据库名称是:HalalGauge.sqlite

you need to use this methods for rearranging 您需要使用此方法进行重新排列

- (void)tableView:(UITableView *)tableView
         commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
         forRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)tableView:(UITableView *)tableView
         moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
         toIndexPath:(NSIndexPath *)toIndexPath;

Add your new row as productId 101. DELETE FROM PRODUCTS WHERE productId = 1 UPDATE PRODUCTS set productId = (productId-1) 将新行添加为productId101。在productId = 1的产品中删除UPDATE PRODUCTS set productId =(productId-1)

I wouldn't call this a nice solution as it updates every row but if you only have 100 rows it will be ok. 我不会将其称为一个不错的解决方案,因为它会更新每一行,但是如果您只有100行,那就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM