In the continuing effort to try to crack the code for using a SQLite database in an iOS app, I am now trying to add a new record to a database. The EEiOS example does not include a way to add or delete data, and I don’t see anything directly in the documentation. Is it even possible?
[quote]A forum message dating back to Dec 14, 2014 shows this:
I am trying to insert a database record like this:[/quote]
[quote]Dim rec As New DatabaseRecord
rec.Column(“name”).ToText = “Carrots”
rec.Column(“description”).ToText = “The chopped ones please…”
app.db.InsertRecord(“grocery”,rec)
The database is a Sqlite database.
The errormessage in the debugger is “Can’t find a type with this name” and refers to DatabaseRecord. Do I have to use app.db.SQLExecute(sql) instead to achieve an insert?
Answered by Bob Keeney See post in context
@Jacco Slok The errormessage in the debugger is “Can’t find a type with this name” and refers to DatabaseRecord. Do I have to use app.db.SQLExecute(sql) instead to achieve an insert?
Correct. There is no class based way of inserting data yet.[/quote]
So, I guess you need to use the app.db.SQLExecute(sql) statement for doing this, but I can’t find any reference for this syntax.
I tried using this code but it throws an exception that the database is not loaded:
[code] Dim dbFile As FolderItem
dbFile = SpecialFolder.Documents.Child(“KTM6.sqlite”)
App.KTM6 = New SQLiteDatabase
App.KTM6.DatabaseFile = dbFile
If dbFile.Exists Then
App.KTM6 = New SQLiteDatabase
App.KTM6.DatabaseFile = dbFile
end if
Dim sql as Text
SQL= “INSERT INTO Questions SET Question = ?1, Answer = ?2”
App.KTM6.SQLExecute(sql, txtQuestion.Text, txtAnswer.Text)[/code]
This code does not seem to work either:
App.KTM6.SQLExecute("INSERT INTO Persons (Name, Age) VALUES ('john', 22)")
App.KTM6.SQLExecute("COMMIT")
I was wondering what the correct syntax is for adding a record to a sqlite database, or if anyone knows of an example project I can look at?
Any help would be greatly appreciated.