My son would like to have something like a timer to verify homeworks, and asked me to do it for iOS.
To complete the app, I need a dB, but I would like not to connect with external dB, like MySQL, to have an app that can be used without wifi/ internet.
Is there a way to do it in Xojo?
Is any dB included? I dont think so.
My data will include few tables with few fields each, a very simple dB.
Thanks for help!
Yes you can create your own iOSSQLiteDatabase in an iOS app.
Make sure to initialise the Database in the App.Open event or whenever it is needed for the first time.
[code]Protected Function CreateDB(filename As Text, DeleteDB As Boolean = False) as Boolean
Dim appSupport As Xojo.IO.FolderItem = xojo.io.SpecialFolder.ApplicationSupport
if appSupport is nil or appSupport.Exists = False then
appSupport.CreateAsFolder
end if
Dim dbFile As xojo.io.FolderItem = xojo.IO.SpecialFolder.ApplicationSupport.Child(filename)
If dbFile <> Nil And dbFile.Exists Then
If Not deleteDB Then
Try
db = New iOSSQLiteDatabase
db.DatabaseFile = dbFile
'db.EncryptionKey = Strings.DBEncryption
If db.Connect Then
Return CreateDBTables
End If
Catch e As iOSSQLiteException
End Try
End If
dbFile.Delete
End If
Db = New iOSSQLiteDatabase
Db.DatabaseFile = dbFile
Try
'db.EncryptionKey = Strings.DBEncryption
If Db.CreateDatabaseFile Then
mdbConnected = True
Return CreateDBTables
Else
mdbConnected = False
Return False
End If
Catch e As iOSSQLiteException
End Try
End Function
[/code]
And for creating tables:
[code]Private Function CreateDBTables() as Boolean
Dim tables() As Text
tables.Append “CREATE TABLE IF NOT EXISTS cache (ID INTEGER NOT NULL, url TEXT, data TEXT, maxDate TIMESTAMP, lastAccess TIMESTAMP, PRIMARY KEY(ID));”
For each sql as text in tables
Try
DB.SQLExecute(sql)
Catch e As iOSSQLiteException
Return False
End Try
In my iOS apps I keep everything in a global module in memory, and periodically save it all to a JSON file. When the app launches it will load this file into memory if it exists. This may be easier for a small database.