Кто-нибудь знает более эффективный способ вставки строки в sqlite?Я беспокоюсь о разделении функций.Должен ли я хранить значения в XML или JSON?Если у вас есть какие-либо предложения, я хотел бы знать.
мой массив значений
private static final String[] inShopCategories =
{"Babies;5;@drawable/ic_launcher",
"Fruit / Vegetables;3;@drawable/ic_launcher",
"Meat / Fisth;2;@drawable/ic_launcher"};
и мой код:
public void onCreate(SQLiteDatabase db){
//create table
db.execSQL(cShopCateg);
//insert default shopping categories with InsertHelper
InsertHelper ih = new InsertHelper(db, tShopCateg);
final int nameCol = ih.getColumnIndex(KEY_NAME);
final int priorityCol = ih.getColumnIndex(KEY_PRIORITY);
final int iconCol = ih.getColumnIndex(KEY_ICON);
for(int i=-1,l=inShopCategories.length; ++i<l;){
ih.prepareForInsert();
String[] s = inShopCategories[i].split(";");
ih.bind(nameCol, s[0]);
ih.bind(priorityCol, s[1]);
ih.bind(iconCol, s[2]);
ih.execute();
}
}