SQLitePreparedSQLStatement MIA

The docs suggest that there is a SQLitePreparedSQLStatement class. It doesn’t autocomplete and when I type it in manually it claims no such class exists.

Docs bug or Xojo bug?

It should be SQLitePreparedStatement. I’ll get that example code updated.

That gives me a type mismatch error. Expected SQLitePreparedStatement but got PreparedSQLStatement.

Hmmm this works here with no syntax error (although there are no rows in the returned record set)

[code] Dim db As New SQLiteDatabase
If Not db.Connect Then Return
db.sqlexecute( "create table Persons( age, name ) " )

Dim ps As SQLitePreparedStatement = db.Prepare(“SELECT * FROM Persons WHERE Name = ? AND Age >= ?”)

ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(1, SQLitePreparedStatement.SQLITE_INTEGER)

Dim rs As RecordSet = ps.SQLSelect(“john”, 20)
If rs <> Nil Then
While Not rs.EOF
MsgBox(“Name:” + rs.Field(“Name”).StringValue + " Age: " + rs.Field(“Age”).StringValue)
rs.MoveNext
Wend
Else
If db.Error Then MsgBox(db.ErrorMessage)
End If[/code]

On what line?

Anyway, I’ve updated the examples for SQLitePreparedStatement.

My bad. I was doing it with CubeSQL. It works with the sqlite database.

i wonder what is the command for cubesql??

[code] Dim ps As CubeSQLVM = db.Prepare(“select * From Residents Where ID = ? And Age >= ?”)

ps.BindText(1, “john”)
ps.BindInt(2, 20)

Dim rs As RecordSet = ps.VMSelect()[/code]

thanks peter

Peter, can i do a rs.edit and rs.update with the rs that is open through CubeSQLVM??

I’ve always built my sql rather than using .edit and .update. Give it a try and let us know :slight_smile:

in my application, i look through all the textarea, combobox and checkbox with same name as the field in the table and then either do an insert or edit. i read somewhere that insert and edit when used is already done the prepared statement.

my question is when should i use the VMSelect to create a recordset?? i think maybe just for reading the data into a listbox or combobox and NOT for edit and update.

I try doing edit and update on my application yesterday and nothing has been updated.

[quote=92782:@Peter Fargo][code] Dim ps As CubeSQLVM = db.Prepare(“select * From Residents Where ID = ? And Age >= ?”)

ps.BindText(1, “john”)
ps.BindInt(2, 20)

Dim rs As RecordSet = ps.VMSelect()[/code][/quote]
In case it’s not clear from Peter’s code snippet, cubeSQLVM is unlike other Xojo prepared statements in several regards:

• Its indexes are 1-based, not 0-based.
• There is not a separate call used to define the type of a parameter. A separate bind method is used for each type (e.g., BindText, BindInt, etc.).
• The prepared statement cannot be re-used; it must be “re-prepared” prior to each use.

Thanks for the clarification Peter.

I wasted the better part of a day on this one.

Prepare always returns SQLitePreparedStatement which is an interface.

you can cast it to SQLitePreparedStatement if you need, but normally you always work with the interface.

[quote=124589:@Peter Fargo]Thanks for the clarification Peter.

I wasted the better part of a day on this one.[/quote]
So did I … :stuck_out_tongue_winking_eye: