Dhugalmac
Dhugalmac

Reputation: 574

Android SQLite Database Use

I have found numerous web references on how to use a SQLite database.

But everything I have found has the DatabaseHelper - onCreate() routine creating a Data Table.

I want to create an Empty SQLite Database (No Tables) and then add tables later on an as-need basis.

  1. Is it REQUIRED that 1 data table be added in order to Create a Database?
  2. When I have tried to utilize the openOrCreateDatabase() function in my DatabaseHelper class, it comes up as un-resolved.

Your advice/suggestions would be greatly appreciated.
Thanks

Upvotes: 0

Views: 46

Answers (2)

droidpl
droidpl

Reputation: 5892

What you suggest is doable, but I don't get the point of not initialising your database with the default system.

In any case, keep in mind:

  1. The onCreate method is not called until you don't get an instance of SQLiteDatabase from your SQLiteOpenHelper.
  2. You can always create new tables or execute any kind of query in your database using SQLiteDatabase#exeSQL

So to your question:

Is it REQUIRED that 1 data table be added in order to Create a Database

No, your database will be created the first time you get a reference to a SQLiteDatabase, for example calling to getWritableDatabase.

When I have tried to utilize the openOrCreateDatabase() function in my DatabaseHelper class, it comes up as un-resolved.

This method is more for internal use from the context. Use the open helper which is the preferred and recommended method.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006594

Is it REQUIRED that 1 data table be added in order to Create a Database?

You should be able to have a SQLiteOpenHelper that does nothing in onCreate().

Or, use openOrCreateDatabase() on SQLiteDatabase.

When I have tried to utilize the openOrCreateDatabase() function in my DatabaseHelper class, it comes up as un-resolved.

That is a static method on SQLiteDatabase, not SQLiteOpenHelper.

Upvotes: 1

Related Questions