您可以创建一个扩展并在方法DaoMaster
内运行查询的类:onCreate
public class CustomDaoMaster extends DaoMaster {
public CustomDaoMaster(SQLiteDatabase db) {
super(db);
}
public static class OpenHelper extends DaoMaster.OpenHelper {
public OpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
super(context, name, factory);
}
@Override
public void onCreate(SQLiteDatabase db) {
super.onCreate(db);
db.execSQL("INSERT INTO myTable VALUES('foo')");
db.execSQL("INSERT INTO myTable VALUES('bar')");
}
}
}
因此,在您的Application
课程中,您将使用此类的一个实例:
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
CustomDaoMaster.OpenHelper helper = new CustomDaoMaster.OpenHelper(this, "Images-bd", null);
SQLiteDatabase db = helper.getWritableDatabase();
CustomDaoMaster daoMaster = new CustomDaoMaster(db);
DaoSession daoSession = daoMaster.newSession();
}
}