Is it possible to use some kind of ddl script in SQLiteHelper to create database?
1 Answer
Yes. I usually have a main DB class in my application that encapsulates an inner class that derives from SQLiteOpenHelper. In the onCreate, you get a SQLiteDatabase instance as a parameter. Call db.execSQL(String) with the appropriate script(s) to create your tables and populate them.
3 Comments
Orest
Well it sounds I still have to convert my ddl to string with my hands(I was hoping that there is something like runScript method). As I understood to upgrade I have to increment db version and in onUpgrade() method exec script which will include commands for deleting old tables, creating few new tables, and inserting some default data, am I right?
Rich
Yeah...that's correct. What format is your DDL in? You don't have to convert your scripts to java strings by typing them out manually. You can load your scripts to text and parse them in code.
Orest
You don't have to convert your scripts to java strings by typing them out manually. I knew that (= Thanks for response.