EDIT: Problem is resolved.
[text]For anyone else having this issue, you must update to Xcode 4.6. Using Xcode 4.3 with the newer Corona Simulator breaks LuaSQLite3.[/text]
Hey everyone,
In my app I use a local SQLite3 database to store values. In Corona Simulator (build 2013.1025), everything works flawlessly. However, once the app is built for iOS Simulator 6.0, using a SELECT statement to retrieve a value returns nil.
Here is the relevant code:
assets.lua[code]module(…, package.seeall)
– Require necessary SQLite3 dependencies
require “sqlite3”
– If file does not exist, it will be created
local path = system.pathForFile( “data.db”, system.DocumentsDirectory )
local db = sqlite3.open( path )
function DBLoad()
– Create the tables if they do not already exist.
(…)
local tablesetup6 = [[CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, selected TINYINT);]]
db:exec( tablesetup6 )
(…) tablesetup6 = nil
(…)
–
– rowNumber returns 0 if there are no rows
if(rowNumber == 0) then
– If there are no rows, start putting the values in. Else, do nothing.
print(“Rows do not exist. Creating rows.”)
local tablefill = [[
BEGIN TRANSACTION;
(…)
INSERT INTO test(selected) VALUES (1);
INSERT INTO test(selected) VALUES (1);
INSERT INTO test(selected) VALUES (1);
END TRANSACTION; ]]
db:exec( tablefill )
tablefill = nil
else
print(“Rows already exist.”)
end
end
function DBQuery(sqlString)
print(sqlString)
if(string.find(sqlString, “SELECT”) ~= nil) then
for row in db:urows(sqlString) do
print(row)
return row
end
else
db:exec(sqlString)
end[/code]
menu.luacode
– Page destroying function
elseif(pageNum == 3) then
assets.DBQuery(“UPDATE test SET selected=” … coverflow.selected[1] … " WHERE id=1;")
assets.DBQuery(“UPDATE test SET selected=” … coverflow.selected[2] … " WHERE id=2;")
assets.DBQuery(“UPDATE test SET selected=” … coverflow.selected[3] … " WHERE id=3;")
–
– Page creating function
–
– IN CORONA SIMULATOR, VALUE RETURNS 1.
– IN iOS SIMULATOR 6.0, VALUE RETURNS NIL.
elseif(pageNum == 3) then
coverflow.selected[1] = assets.DBQuery(“SELECT selected FROM test WHERE id=1;”)
coverflow.selected[2] = assets.DBQuery(“SELECT selected FROM test WHERE id=2;”)
coverflow.selected[3] = assets.DBQuery(“SELECT selected FROM test WHERE id=3;”)[/code]
Any help would be greatly appreciated! [import]uid: 3027 topic_id: 35756 reply_id: 335756[/import]