2014-11-22 24 views

回答

1

我認爲你可以檢查你的表,如果它是空的,然後插入你的數據。你可以有幾個表,並應做同樣爲每一個

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(); 
} 

現在新的數據將插入到表中,只有當他們沒有在表中存在,也不會重複。

在其他解決方案中,您可能會使用預填充的數據庫並在您的應用程序中使用它。

+0

看到我更新的answ! – 2014-11-22 15:36:08

+0

我不是那個意思, – TheGreenGoblen 2014-11-22 15:40:17

+0

那麼,你的意思是什麼? – 2014-11-22 15:41:05