In the LR code below, how do I catch this reported error: Error: UNIQUE constraint failed: Team.Name
Code example from SQLiteDataBase:
Var db As New SQLiteDatabase
db.DatabaseFile = New FolderItem("Employees.sqlite")
Try
db.Connect
db.SQLExecute("BEGIN TRANSACTION;")
db.SQLExecute ("INSERT INTO Employees (Name,Job,YearJoined) VALUES " _
+ "('Dr.Strangelove','Advisor',1962);")
db.CommitTransaction
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
db.RollbackTransaction
End Try
Thank you Sasha for your answer, but I do not think so. I do not understand what your answer is for. I declared the Name field as UNIQUE. That is all I have to do.
I forget to say that the error was done in purpose to verify the Exception will be trapped and this is not the case.
Read the text in Bold. This is what error.Message returns.
The error appears in the debugger (ErrorCode and ErrorMessage), but cannot be reached in the Code Editor by If db.ErrorCode or db.ErrorMessage (they do not exist there).
Nobody use the UNIQUE CONSTRAINT in its data base ?
Strange.
Sometimes ago I wanted to ask Xojoto remove API 1 from 2020r1 (or r2 or ). It will never been updated (as they said), so releasing it alone, removing it from the current version will lead to less confusion and lower the footprint (for download, in RAM, etc.).
But (read another conversation), that thing is not possible until a full API2 rewrite, so we have to live with this kind of possible error (and searching all the time how do I write this in API 2 ??? until the human memory will recall the new way, in some months).
The Web framework has not been updated to API 2 yet. If you are trying this in a web project, you will need to stick with all API 1 functions.
Actually, API 2 database functions will work in a Web project. I was thinking about UI controls. Sorry for the noise.
The SQLExecute was changed to ExecuteSQL on that doc page on 4 Feb 2020. So if you copied the above code from that page, it had to have been prior to that date.
I don’t understand your complaint about this, though I find no Team table mentioned anywhere.
Emile, here is a project that demonstrates what you’re trying to accomplish, using what Sascha hinted at in extracting the relevant information from the error message (IndexOf is not really useful in this case - I used Split).
Note that when running in the IDE (debug mode), any exceptions will cause it to break to the debugger. You have to click the Resume button to see how it will work/look in a built app. This may be why you think it’s not catching this error. Or you can use “#Pragma BreakOnExceptions False” like I did in the third button.
At first run, your example looks (behave) like another, API 1, project where I implemented this in a batch import button: I added a counter and after 5 duplicates, I report them and stop the import process (around 600 Records).
Compared (more or less) to my code, the important line is:
#Pragma BreakOnExceptions False
and the Split line (I took that information differently in API 1 code).
In short, this API 2 code is far complex than the API 1 code I wrote last week.
Am I wrong to test running in the IDE ?
(until the project if the project is far from completion ?)
(Error above: I cannot compile, so I cannot test differently.)