0

Is it possible to use some kind of ddl script in SQLiteHelper to create database?

1 Answer 1

1

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.

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

3 Comments

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?
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.
You don't have to convert your scripts to java strings by typing them out manually. I knew that (= Thanks for response.

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.