我使用 ActiveAndroid 作为 ORM。我想用某些值初始化我的数据库表。只有一次,我不希望内容被复制。
或者是否有在安装时执行 sql 脚本的解决方案。
我在文档中搜索但我没有找到它。谢谢。
我使用 ActiveAndroid 作为 ORM。我想用某些值初始化我的数据库表。只有一次,我不希望内容被复制。
或者是否有在安装时执行 sql 脚本的解决方案。
我在文档中搜索但我没有找到它。谢谢。
我认为您可以检查您的表,如果它是空的,则将您的数据插入其中。你可以有几张桌子,每一张都应该做同样的事情
List <Category> categories = new Select()
.from(Category.class)
.where("your where clause here") // your where clause
.execute();
if (categories != null && categories.size() > 0 ) {
// data is inserted before
} else {
Category newCategory = new Category("category");
newCategory.save();
}
List <Item> items = new Select()
.from(Item.class)
.where("your where clause")
.execute();
if (items != null && items.size() > 0 ) {
// data is inserted before
} else {
Item item = new Item("item");
item.save();
}
现在,只有当新数据不存在于您的表中并且不会重复时,它们才会插入到表中。
在其他解决方案中,您可能会使用预填充的数据库并在您的应用程序中使用它。