Error connecting to SQLlite in iOS
JOHN PATTEN
johnpatten at me.com
Thu Apr 20 13:37:38 EDT 2017
Hi All,
I have a simple project that uses an sql lite database. It works fine in LiveCode, but when I test it in the iOS simulator, i get an error.
I have copied to the SQL.lite database to the “Copy Files” in the standalone settings. I have also added the SqLite and MySQL inclusions.
Here is the link to the project and db: Here is a link to the stack and sql db: https://www.dropbox.com/s/74rhx88dod6cs2k/CCSS%20App.zip?dl=0 <https://www.dropbox.com/s/74rhx88dod6cs2k/CCSS%20App.zip?dl=0>
Here is the script I am using.
local sDatabaseID
command databaseConnect
local tDatabasePath, tDatabaseID
put specialFolderPath("Documents") & "/ccssdb-ela.sqlite" into tDatabasePath
## Test if a database exists
if there is a file tDatabasePath then
answer "A database already exists" with "Okay"
end if
if there is a file tDatabasepath then
put revOpenDatabase("sqlite", tDatabasePath, , , , ) into tDatabaseID
setDatabaseID tDatabaseID
put cd fld "targetGrade" into tGrade
if tGrade is 10 then
put 9 into tGrade
end if
if tGrade is 12 then
put 11 into tGrade
end if
put revQueryDatabase(tDatabaseID,"SELECT * FROM ccss_data WHERE grade =:1","tGrade") into theCursor
if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
put the result into theError
if theError is empty then
set the dgData of group "ccss_data" to theDataGridArray
end if
revCloseCursor theCursor
revCloseDatabase tDatabaseID
else
Answer "Error connecting to the database:" && tDatabaseID & "."
end if
else
Answer "Having trouble locating database."
end if
end DatabaseConnect
command setDatabaseID pDatabaseID
put pDatabaseID into sDatabaseID
end setDatabaseID
function getDatabaseID
return sDatabaseID
end getDatabaseID
command ConvertSQLCursorToArray pCursor, @pOutArrayA
local i
local theFields
local theError
put revDatabaseColumnNames(pCursor) into theFields
if theFields begins with "revdberr," then
put item 2 to -1 of theFields into theError
end if
if theError is empty then
put 0 into i
repeat until revQueryIsAtEnd(pCursor)
add 1 to i
repeat for each item theField in theFields
put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA [i] [theField]
end repeat
revMoveToNextRecord pCursor
end repeat
end if
return theError
end ConvertSQLCursorToArray
Thank you!
More information about the use-livecode
mailing list