no such table on android

Hi, can someone be kind to tell me why I get “Runtime Error no such table :ISO_data” on an android but it works in Corona simulator?

 if vvsData.type == “iso” then

 local path = system.pathForFile(“ISO_data.db”, system.DocumentsDirectory)
 local db = sqlite3.open( path )

  local tablesetup = [[CREATE TABLE IF NOT EXISTS ISO_data]]
   db:exec( tablesetup )
 
  for row in db:nrows(“SELECT radie FROM ISO_data WHERE diam == '”…vvsData.currentDiam…"’")
  do
  radie = row.radie
 end

 db:close()

I don’t know if you have more code than what you posted above, but, all you are doing is saying:

If the database doesn’t exist, create and empty database

then you immediately start reading from it.  You have not defined any columns in the database (i.e. radie).  You have not inserted any data into the table.  You likely have created this somehow in the simulator.   Posting some more code might be helpful.  But more importantly the full text of the error (copy/paste the text, don’t do a screen shot) can be helpful as well as information from the console log.  Please read:  to help us help you.

Rob

At first i populated my databases in my code just to see how it works. Now I use preloaded databases that I wrote over the existing ones in Sandbox\vvs\Documents and it works great in simulator but not on an android divice. As I’m using preloaded databases I cut out that part of the code and moved the db-files to root projekt folder and changed the path to system.ResourceDirectory.

Now it works fine on the android.

But as I try to learn of my mistakes I would be thankful for some hint on what I did wrong.

Sorry for my bad English

And I will Clean up the “CREATE TABLE IF NOT EXISTS ISO_data”

Orjan

Sounds like you’re part way there. 

You needed to (and did)

  • place the ‘pre-loaded’ DB file in your game directory before the build, so it gets copied over.

However, if you want to be able to write to it and make changes to the DB

  • One time ONLY when you app first runs - Copy it from the ‘ResourceDirectory’ to the ‘DocumuentsDirectory’. 
  • Open the DB from the ‘DocumentsDirectory’ and you should be good to go.

If you only need read-only access simply access the one in the ‘ResourceDirectory’.

Ok, Thanks!

I don’t know if you have more code than what you posted above, but, all you are doing is saying:

If the database doesn’t exist, create and empty database

then you immediately start reading from it.  You have not defined any columns in the database (i.e. radie).  You have not inserted any data into the table.  You likely have created this somehow in the simulator.   Posting some more code might be helpful.  But more importantly the full text of the error (copy/paste the text, don’t do a screen shot) can be helpful as well as information from the console log.  Please read:  to help us help you.

Rob

At first i populated my databases in my code just to see how it works. Now I use preloaded databases that I wrote over the existing ones in Sandbox\vvs\Documents and it works great in simulator but not on an android divice. As I’m using preloaded databases I cut out that part of the code and moved the db-files to root projekt folder and changed the path to system.ResourceDirectory.

Now it works fine on the android.

But as I try to learn of my mistakes I would be thankful for some hint on what I did wrong.

Sorry for my bad English

And I will Clean up the “CREATE TABLE IF NOT EXISTS ISO_data”

Orjan

Sounds like you’re part way there. 

You needed to (and did)

  • place the ‘pre-loaded’ DB file in your game directory before the build, so it gets copied over.

However, if you want to be able to write to it and make changes to the DB

  • One time ONLY when you app first runs - Copy it from the ‘ResourceDirectory’ to the ‘DocumuentsDirectory’. 
  • Open the DB from the ‘DocumentsDirectory’ and you should be good to go.

If you only need read-only access simply access the one in the ‘ResourceDirectory’.

Ok, Thanks!