Hi all,
I'd like to use the INSERT IGNORE statement format with a table having a UNIQUE index on one of its fields.
Currently my code is something like:
where risp is a map that I use to give some feedback to the caller.
Now, when duplicating the value for the a-field, correctly the DB ignores the attempt to insert the duplicate, but I'd like to put in risp("err") code 1062 to give a feedback about the attempted duplicate.
Should I use a second statementi like SHOW WARNINGS soon after the insert? If yes, how do I read the returned Level/Code/Message fields?
Another way could be not to use the IGNORE clause and let the transaction fail, but I'd like to learn how to use the IGNORE clause anyway. TIA.
I'd like to use the INSERT IGNORE statement format with a table having a UNIQUE index on one of its fields.
Currently my code is something like:
B4X:
Dim sql1 As SQL = pool.GetConnection
sql1.BeginTransaction
Try
sql1.ExecNonQuery2($"INSERT IGNORE INTO xxxx (id,a,b,c,d,e)
VALUES (?,?,?,?,?,?);"$, _
Array As Object(Null, MData.Get("a"), MData.Get("b"),MData.Get("c"), _
MData.Get("d"), MData.Get("e")))
risp.Put("err",0)
sql1.TransactionSuccessful
Catch
risp.Put("err",-101)
risp.Put("errmsg", LastException.Message)
sql1.Rollback
End Try
sql1.Close
Now, when duplicating the value for the a-field, correctly the DB ignores the attempt to insert the duplicate, but I'd like to put in risp("err") code 1062 to give a feedback about the attempted duplicate.
Should I use a second statementi like SHOW WARNINGS soon after the insert? If yes, how do I read the returned Level/Code/Message fields?
Another way could be not to use the IGNORE clause and let the transaction fail, but I'd like to learn how to use the IGNORE clause anyway. TIA.