Hi all. I created a simple database and I’m trying to find it that way.
In simulator is everything ok, but on phone the program stops the search without notice any error.
Text “Test is DONE” is not displayed in the console. But application further works.
What am I doing wrong ?
local path = system.pathForFile( "userdata.db", system.DocumentsDirectory ) local db = sqlite3.open( path ) if fileExist("userdata.db") then print ("database is open") flg = false sel = [[SELECT \* FROM test WHERE user\_id = ']]..t["user\_id"]..[[';]] for row in db:nrows(sel) do flg = true end print ("Test is DONE") end
local json = require("json") local path = system.pathForFile( "userdata.db", system.DocumentsDirectory ) local db = sqlite3.open( path ) if db then print ("database is open") flg = false sel = [[SELECT \* FROM test WHERE user\_id = ']]..t["user\_id"]..[[';]] for row in db:nrows(sel) do print( json.prettify( row ) ) flg = true end print ("Test is DONE") else print ("Database failed to open") end
How are you populating your database? This is an area were people run into problems. Your app has to initialize the database in system.DocumentsDirectory and pre-populate it with any values that you need. Some people will ship their app with a copy of the pre-populated database in system.ResourceDirectory, but since that’s a Read Only resource, you have to copy that database to system.DocumentsDirectory before you can use it.
local json = require("json") local path = system.pathForFile( "userdata.db", system.DocumentsDirectory ) local db = sqlite3.open( path ) if db then print ("database is open") flg = false sel = [[SELECT \* FROM test WHERE user\_id = ']]..t["user\_id"]..[[';]] for row in db:nrows(sel) do print( json.prettify( row ) ) flg = true end print ("Test is DONE") else print ("Database failed to open") end
How are you populating your database? This is an area were people run into problems. Your app has to initialize the database in system.DocumentsDirectory and pre-populate it with any values that you need. Some people will ship their app with a copy of the pre-populated database in system.ResourceDirectory, but since that’s a Read Only resource, you have to copy that database to system.DocumentsDirectory before you can use it.