0

I'm using Sqlite with android to develop and app which can be customizable (for the dev) in the future. I have created a database with the data which is then to be used to create the database for the application. So if any changes need to be made in the future or I write an app for somebody else in the future then all I have to do is change this original database. The idea behind this is the dev's database will set up all the UI and everything to do with the app.

I am stuck on what to do next I have the database I need in the app as the dev fully populated. My idea was to create another DBHelper class and within that reference the original DBHelper class and query within the new DB Class. So this is the second DBHelper class that i'm trying to create a database from a previous database:

public class appDbHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "library.db"; //database name   
    Cursor all, tables, options, ui_type;
    SQLiteDatabase database;

    public appDbHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
        DBHandler databaseHelper = new DBHandler(context);
        database = databaseHelper.getReadableDatabase();
        all = database.rawQuery("SELECT * FROM config", null);
        tables = database.rawQuery("SELECT * FROM table_names", null);
        options = database.rawQuery("SELECT * FROM options", null);
        ui_type = database.rawQuery("SELECT * FROM ui_type", null);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        for(int i=0; i<tables.getCount(); i++){
            tables.moveToPosition(i+1);
            String sql = "";
            for(int j = 0; i < all.getCount(); j++){
                if (all.moveToFirst()) {
                    do{
                        sql = ", " + all.getString(2) + " " + all.getString(5).toUpperCase();
                    }
                    while (all.moveToNext());
                }
            } 
            Log.v("DatabaseSQL", sql);
            database.execSQL( "CREATE TABLE " + tables.getString(1) + "(_id INTEGER PRIMARY KEY AUTOINCREMENT"+sql+");");
        }
    }

But I have a feeling this is not the way to go about what I need to do. Any help will be greatly appreciated.

2
  • I am not sure if I understand everything right. You have an db you read to set up UI and stuff? If yes, why? Never heard that someone uses a database to customize an application... the second question: Whats the issue? You want to know how to have 2 databases open at the same time? I am a bit lost with your question... Commented Dec 21, 2010 at 10:40
  • Yes sort of, the original database is used to setup the database for the application which will store data for the app, this in turn depending on the data to be stored will show a different type of UI View. The question is am I going about this totally the wrong way? It's an app that may be used many times for many different applications but I only want one place where this is changed for the application, in my example it's the first config database. Commented Dec 21, 2010 at 10:44

1 Answer 1

1

I think you do it wrong and to complicated. You provide a database to read data from where you could easily just create some inserts and your configuration will be implemented.

Two solutions:

  1. From my own project: DatabaseAdapter.onCreate()

    There you should see the database setup and the filling of the database with data. The data itself are added with simple inserts which contains data based on constants. So a programmer can easily change the data by changing the constants.

    With that you don't have to handle 2 databases, you don't need to provide another database and read them.

  2. As android supports database locations you could also skip this all and just open an sqlite database file you provide in your res/raw or asset folder or anywhere on the sdcard.

I recommend to do one of the two ways mentioned above.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.