What are the benefits of using an adapter, a wizard for creating or accessing the database?

advertisements

Currntly i am creating SQLite database in android using following code:

    SQLiteDatabase db;
try{
            SQLiteDatabase  dbe = SQLiteDatabase.openDatabase("/data/data/bangla.rana.fahim/databases/dictionary", null,0);
            dbe.close();
   }
            catch(SQLiteException e){

                db = openOrCreateDatabase("dictionary", MODE_PRIVATE, null);
                db.execSQL("CREATE TABLE IF NOT EXISTS LIST(wlist varchar,ex varchar);");
                db.close();
            }

And retrieving data using cursor like:

  Cursor cc = db.rawQuery(q, null);//q is the desired query.

But i have seen many example of using helper and adapters for the very same purpose. So, my question is what are the benefits of using them?


I guess you are referring to SQLiteOpenHelper, the documentation is pretty clear:

A helper class to manage database creation and version management.

You create a subclass implementing onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and optionally onOpen(SQLiteDatabase), and this class takes care of opening the database if it exists, creating it if it does not, and upgrading it as necessary. Transactions are used to make sure the database is always in a sensible state.

With this you don't have to manually create your database and take care of upgrading it. You just have to implement the two methods onCreate() and onUpgrade() with your database logic and android will make sure to call this methods when is needed. I don't know at what are you referring when you say adapter.