重置Xamarin / sqlite-net-pcl Nuget pkg中的AutoIncrement序列号

时间:2018-03-22 05:06:06

标签: c# xamarin.forms sqlite-net

当我清理我的桌子时,我还想重置自动增量rowid数字。我找到了几篇推荐此代码的帖子:

DeleteAll<mytable>();
Execute("update sqlite_sequence set seq = 0 where name = 'mytable';");

当我运行它时,我没有得到任何类型的错误,但是rowid没有被重置。我也尝试过:

Execute("delete from sqlite_sequence where name = 'mytable';");

......结果相同。是否有sqlite-net-pcl的怪癖使这不起作用?或者我错过了什么?

表定义如下所示:

public partial class mytable : IHasId
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    <other stuff deleted>
}

和IHasId是:

public interface IHasId
{
    int Id { get; set; }
}

(不要开枪打我,当我能吃芝士汉堡的时候我写回来了。当时我很开心......而且,不,桌子实际上并没有命名为mytable。)

非常感谢任何帮助。 谢谢!

1 个答案:

答案 0 :(得分:0)

我找到了!我很高兴地报告这是一个愚蠢的事情。在我们的其他(非常古老的,基于C ++的)数据库应用程序中,我们的表是复数,索引是单数。例如,“Customers”表包含具有名为“customer”的索引列的记录。所以本着这种精神,对于我的“客户”对象,我让数据库打开了一个名为“Custs.db3”的文件。

因为使用“table”的例子我这样做:

Execute("delete from sqlite_sequence where name = 'Custs';");

我需要的是:

Execute("delete from sqlite_sequence where name = 'Customer';");

所以...索引不是由“表”名称存储的,它们是由“对象”存储的 班级名称。