0

I can open a SQLiteDatabase in two ways:

SQLiteDatabase.openDatabase()
SQLiteOpenHelper.getWritableDatabase ()

It seems that there is no difference between two approaches except more control when using SQLiteDatabase.openDatabase()

Q1- why duplication?

Q2- how can i benefit from that from the perspective of Software Design

1
  • You'll prolly have better luck on programmers.stackexchange.com SO is more for specific questions about a program you are working on. Commented May 8, 2012 at 23:38

2 Answers 2

2

Creating your own class which extends SQLiteOpenHelper allows you to remove a lot of SQLite db code from your main code. You override the onCreate(...) and onUpdate(...) methods to allow it to automatically create the database when your app is first run and to update the database in future upgrades of your app.

It's also useful as you can add methods to your extended SQLiteOpenHelper to do all of the 'boiler-plate' tasks (queries, insertions, deletions etc). Effectively, your main code never needs a reference to a database - it can simply call methods on your extended SQLiteOpenHelper class.

Sign up to request clarification or add additional context in comments.

Comments

0

SQLiteDatabase offers lower level access and control, while, as mentioned above, SQLiteOpenHelper takes care of a lot of boilerplate code, and you should generally prefer it. One situation where you need to use SQLiteDatabase is when you want to open a database (often pre-populated) on external storage -- with SQLiteOpenHelper you cannot specify the DB file location, it defaults to creating one in your app's private directory (under org.myapp/databases).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.