Why use SQLiteOpenHelper over SQLiteDatabase?

前端 未结 4 579
时光说笑
时光说笑 2020-12-29 18:48

In my activity I have for example

SQLiteDatabase db = openOrCreateDatabase(Preferences.DB_NAME, Context.MODE_PRIVATE, null);
db.execSQL(\"CREATE TABLE IF NOT         


        
4条回答
  •  天涯浪人
    2020-12-29 19:27

    SQLiteOpenHelper provides utilities to simplify the tasks of creating and initialising the database if it's not already created and converting the contents of the database when your application is upgrading and the database schema changes.

    If you have a very simple database schema, then it doesn't really get you much, but for anything complicated it's a definite help. It makes sure that all the fiddly edge conditions are covered so that you don't have to, such as putting transactions in all the right places to avoid database corruption.

提交回复
热议问题