SQLite Update statement works in simulator. Not On device

I am not sure why, but i am trying to use the following SQLite statement to update a record in my database.

this works just fine on all the simulators. but when i compile to my Android Device (a motorola Xoom, with daily build 655) the update statement doesnt seem to work at all.

I am new to working with databases here is what I have:

1
2
3
local defaultValue  = [[UPDATE collection SET currentStage = ']] .. newStage .. [[' WHERE keyid = ']] .. rowCount .. [[';]]
 
db:exec( defaultValue ); 

You need to make sure you have the Copy piece of code at start of App launch to copy SQLlite DB from Resource directory to Documents directory --- having DB in Resource directory is Read-only on device ... in order to have INSERT / UPDATE / DELETE ... you need to have DB in Documents directory ---

If you do not need to copy ... you can have code to create table structure and data via code which will create DB in Documents directory.

Let me know if you have further questions or if this makes sense.

Thanks for the insight, it at least gives me something to look into.

I don't have a copy code in place to move my database file. however here is how I am initiating my database:

1
2
3
4
5
require "sqlite3"
  
local path = system.pathForFile("mydatabase.db", system.DocumentsDirectory)
 
db = sqlite3.open( path )

A couple of thoughts since you're creating TABLE and not copying DB:

1] Datatype of varchar (I do not think exists in SQLite) -- it will translate to TEXT datatype anyway

http://www.sqlite.org/datatype3.html

Try this:

1
2
3
local tablesetup = "CREATE TABLE tableCollection (keyid INTEGER PRIMARY KEY,currentStage INTEGER NOT NULL,stage1Pic TEXT)"
 
db:exec( tablesetup )
views:1898 update:2011/11/10 9:30:09
corona forums © 2003-2011