In a mysql subclass, I have a method that updates a record
mAssignReplacement(Id_user as string, id_main as string) returns boolean
Var q As String
q = "UPDATE remplacement SET id_user_assigned = ? WHERE id_horaire_base = ? "
// note in a prepared statement you DO NOT put in the quotes
Var stmt As MySQLPreparedStatement
stmt = MySQLPreparedStatement(Self.Prepare(q))
// have to tell Mysql what types the items being bound are so it does the right thing
stmt.BindType(0, MySQLPreparedStatement.MYSQL_TYPE_STRING)
stmt.Bind(0, id_user)
stmt.BindType(1, MySQLPreparedStatement.MYSQL_TYPE_STRING)
stmt.Bind(1, id_main)
Public Sub AssignReplacement(db As MySQLCommunityServer, id_user As String, id_main As String)
Var q As String = "UPDATE remplacement SET id_user_assigned = ? WHERE id_horaire_base = ? ;"
If db.Connect Then
db.ExecuteSQL(q, id_user, id_main) // It may fail, catch the error at the caller level
Else
Raise New DatabaseException("Couldn't connect", -1) // failed, raise some exception with a message too
End If
// All done without errors, return
End Sub
//****** Now use it somewhere *****
Try
AssignReplacement(mydb, "user123", "horaire12")
Catch e As DatabaseException // it'll reach here if it fails
MessageBox "Replacement failed : " + e.Message
End
If you don’t want to use the exception idea others have suggested, consider simply returning the error message. If there is not error, return an empty string. The caller can then detect if there is an error an deal with that/show the user. If there is no error, the empty string will indicate that.