0
我使用ActiveAndroid作爲ORM。 我想用特定的值初始化我的數據庫表。只有一次,我不希望內容被複制。如何用特定值初始化數據庫activeandroid
或者是否有解決方案在安裝時執行sql腳本。
我在文檔中搜索,但我沒有找到它。 謝謝。
我使用ActiveAndroid作爲ORM。 我想用特定的值初始化我的數據庫表。只有一次,我不希望內容被複制。如何用特定值初始化數據庫activeandroid
或者是否有解決方案在安裝時執行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();
}
現在新的數據將插入到表中,只有當他們沒有在表中存在,也不會重複。
在其他解決方案中,您可能會使用預填充的數據庫並在您的應用程序中使用它。
看到我更新的answ! – 2014-11-22 15:36:08
我不是那個意思, – TheGreenGoblen 2014-11-22 15:40:17
那麼,你的意思是什麼? – 2014-11-22 15:41:05