【问题标题】:Reset the AutoIncrement sequence number in Xamarin/sqlite-net-pcl Nuget pkg重置 Xamarin/sqlite-net-pcl Nuget 包中的自动增量序列号
【发布时间】:2018-03-22 05:06:05
【问题描述】:

当我清理我的表时,我还希望重置自动增量 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。)

任何帮助将不胜感激。 谢谢!

【问题讨论】:

    标签: c# xamarin.forms sqlite-net


    【解决方案1】:

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

    因为示例使用了“table”,所以我这样做了:

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

    我需要的是:

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

    所以...索引不是按“表”名称存储的,而是按“对象”存储的 类名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 2023-03-19
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      相关资源
      最近更新 更多