-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!

Quasaur
  • 1,335
  • 1
  • 10
  • 27
  • 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. – Quasaur Jan 12 '13 at 02:07
  • http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an-android-application/9109728#9109728 – Yaqub Ahmad Jan 12 '13 at 03: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)? – Quasaur Jan 12 '13 at 04: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. – Yaqub Ahmad Jan 12 '13 at 04: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? – Quasaur Jan 12 '13 at 05:57
  • You need to call each command separately using execSQL(). http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL%28java.lang.String%29 – Yaqub Ahmad Jan 12 '13 at 06:26
  • http://stackoverflow.com/questions/14273681/scripting-sqlite-database-creation – Yaqub Ahmad Jan 12 '13 at 06:31
  • Are you saying that, from the Android device, I can open a terminal and run the import command, sucking the *.sql file right into the db? – Quasaur Jan 12 '13 at 07:28

1 Answers1

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.

Quasaur
  • 1,335
  • 1
  • 10
  • 27