I have the code below (as an example) and I want to convert it to use PreparedStatement.
All I can say are:
a. I failed (and I cannot talk about the docuentation good or bad),
b. I spend my whole morning (today), but not only at searches here and there without reaching anything valuable.
Maybe I am loosing patience * with that, I come here for some help.
I do not ask the whole replacement of my code below; just a skeleton with only one Column, so I can elaborate the complete code alone (and continue 'cause I have far more to convert).
TIA,
Emile
[code]
// Dim a DatabaseRecord
Dim DB_Row As New DatabaseRecord
// c. Phone-Mail
DB_Row.Column(“Phone”) = TF_Phone.Text
DB_Row.Column(“eMail”) = TF_Mail.Text
// d. Birth
DB_Row.Column(“Birth_Date”) = TF_Born_Date.Text
DB_Row.Column(“Birth_Place”) = TF_Born_Place.Text
// e. La photo
DB_Row.PictureColumn(“Photo_ID”) = cPhoto.Backdrop
// 2. Ajoute le DatabaseRecord
mSQLite.gAccueillants_DB.InsertRecord(“Accueillants”, DB_Row)
If mSQLite.gAccueillants_DB.Error Then
MsgBox “Impossible dajouter cette Fiche.” + EndOfLine + EndOfLine +_
"Erreur " + Str(mSQLite.gAccueillants_DB.ErrorCode) + ": " + mSQLite.gAccueillants_DB.ErrorMessage
Return
End If[/code]
Not xojo. I was searching a red fruit from a tree yesterday and found the worst web site I ever saw: the photos are first, then comes the forum (texts) entries without any clue (Index, name) to know what Photo goes to which text absolutely, totally useless. I found the Photo of the fruit I want, but not the comment; how could it be ?
Here’s a prepared statement I am currently using (its a method of a data class, hence the Me references):
[code]Dim sql As String
Dim ps As SQLitePreparedStatement
// Insert only if it’s not already in the database (ie - it doesnt have an ID)
If Me.ID < 1 Then
sql = “INSERT INTO playlist (”
sql = sql + "name, "
sql = sql + “sort_order”
sql = sql + “) VALUES (?, ?)”
@Phillip Zedalis - nice! That certainly removes the headaches. Emile still would probably like to understand how to create and use a prepared statement the hard way, though…
Emile, this is the first time I see code with DatabaseRecord and I think that’s why is hard for you to use PreparedStatements. I started learning Xojo and SQLite not long ago and always used the complete SQL Insert statement and I think that’s easier to change to PreparedStatements.
A partial skeleton from your code could be:
[code]Dim ps As SQLitePreparedStatement = mSQLite.gAccueillants_DB.Prepare(INSERT INTO Accueillants (Sexe,PNom,Nom) VALUES (?, ?, ?)")
And I guess that’s the point. We all reach that point where doing it the old, drawn out way, is tiring, mistake prone, etc and we’ve come up with ways to make database code easier/faster/better. “Better” is in the eye of the beholder. But in all cases I’d say you really need to know how Xojo works before trying the shortcuts.
And I use my own QueryDb, which does it all above and a bit more, for all database-types I use. (PostgreSQL, sqLite, MySQL)
Think everybody dealing with databases frequently in applications finds his way to work fast and robust. But, it’s very true, you should understand databases, preparedstatements etc. first in dept, before you should start abstracting things.