Database.Error Is Lying to Me

I’ve never run into this before and I’m wondering if this is a bug.

[code]
Dim sql as String
Dim ps as SQLitePreparedStatement

sql = "UPDATE Table1 SET " + _
"title = ? " + _
“WHERE id = ?”

ps = db.Prepare( sql )

ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(0, SQLitePreparedStatement.SQLITE_INT64) // intentional error

ps.Bind(0, theTitle)
ps.Bind(1, theID)

ps.SqlExecute

If Not db.Error then // The error is detected here

// Do more code

End if

If Not db.Error then // The error is not detected here (False),
// but db.ErrorMessage still contains the error message.

// Do more code

Else

Dim d as new MessageDialog
Dim b as MessageDialogButton

d.icon=MessageDialog.GraphicCaution
d.Message = “Cannot complete procedure.”
d.Explanation = "SQL Error: " + db.ErrorMessage
b=d.ShowModalWithin( self )

End If[/code]

Xojo 2015 2.4 OS X 10.10.2

Thats not an error though
Logic error yes
But not a problem as far as the binding goes

I don’t think I understand.

The UPDATE does fail.

First check of db.Error:
Error = True
ErrorCode = 1
ErrorMessage = 2 parameters are being bound, but only 1 types were specified.

Second check of db.Error:
Error = False
ErrorCode = 1
ErrorMessage = 2 parameters are being bound, but only 1 types were specified.

Right
your set up code says “heres a query to run and its going to have SOME parameters”
Then you only specify ONE (since you bind to the 0th item multiple times)

Only when you try to execute does it take all that set up information & finally figure out “your set up says there should be 2 but you only gave me one”

Hence the very correct error message

I guess it’s not a big deal since this kind of error would be resolved before a release, but why doesn’t db.Error stay True? The SQLExecute failed. Or, shouldn’t the ErrorCode and ErrorMessage be cleared at least?

The error will be cleared at the next ‘transaction’. If you’re doing Rollback and Commit the error is cleared at that point. Otherwise the next time you do something, like Prepare a statement, sql select, etc, the error is cleared.