-1

I've done my homework; I know all the ways to query an SQLite db from an Activity.

The problem is that all the examples ASSUME that i want to "load" data from the db onto the FIRST Activity screen.

But when my app's FIRST Activity is loaded I DON'T WANT TO GET ANY DATA FROM THE DB; i just want to:

(1) Check if the db file has already been created (if the setup routines have already run).

(2) If the db exists, load the SECOND Activity (with ContentProvider/Loaders, etc.) so the user can start adding data.

OR

(2) If the db DOESN'T exist, WHILE STILL IN THE FIRST ACTIVITY run the setup routines (create the db/tables from an *.sql file & INSERT the dummy data where needed)...then load the SECOND Activity (with ContentProvider/ Loaders, etc.) so the user can start adding data.

To me, the simple operation of creating the db/tables shouldn't require all the OVERHEAD of a ContentProvider and a bunch of Cursors and Loaders.

Is there anybody who could point me to a SIMPLE solution? Thanks!

8
  • Just in case: the reason why i don't want to bring in a pre-made db file is that i want the db to be created with the SAME ENGINE VERSION as the Android device the app is being installed on. Commented Jan 12, 2013 at 2:07
  • stackoverflow.com/questions/9109438/… Commented Jan 12, 2013 at 3:02
  • To Yaqub: thank you; the post in your link answered nearly all of my questions! I have one question left: is it possible/wise to create a database from an sql script file (*.sql)? Commented Jan 12, 2013 at 4:18
  • Yes, why not. You need to store it somewhere like in assests. You need to read this script and run it. Now whenever you need to call the database, you need to create the database first if its not exist. Commented Jan 12, 2013 at 4:32
  • @YaqubAhmad The question is: can i run the *.sql file in one call, or do i have to feed it line-by-line to the class? Commented Jan 12, 2013 at 5:57

1 Answer 1

0

Yaqub's link was helpful...

...what i did was create public static final String arrays in a DBConstants class containing the commands to create the Database on first run.

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

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.