I have a table, with a trigger on it wich prevents certain deletes.
A Delphi program tries to delete a record, but the trigger prevents it from being deleted. However, my delphi progam doesn't show the record anymore, unless i do a refresh. Is there an OTHER way (so without me doing a refresh) to keep on seeing that record ?
(Anyone who can point a browser to this site can probably
register as an expert too...)
Anyway for my real answer:
I do not know that database server you use but normally
your "Delete from ..." SQL will generate some sort of
error message when you execute it. (Although common sense suggests that you should receive an error message whenever the
delete fails...)
You should execute the SQL by hand and see what happens if
the trigger prevents the delete. If there is no error, you
have a problem at the server side (IMHO)
If there is an error, then you can catch that error in your code
and you bnever have to refresh in the first place.
Good Luck,
(And please, please please use the TSQL component,)
0
Be seen. Boost your question’s priority for more expert views and faster solutions
if a trigger does a rollback of the transaction, there is no real error occuring. It's just part of the business rules, that you can't delete a specific record. In MS SQLServer, Stored procedures can return a kind of status level, but triggers cannot. So i keep on looking for a solution ...
Jeez... almost to simple to warrant an answer, but here goes anyway...
If the trigger causes a rollback (failed delete) then INSIDE the trigger issue a RAISERROR statement that you can capture with Delphi to indicate that yes, the delete was *attempted* but it failed due to a business rule conflict. When you issue the RAISEERROR statement try and use an error code that is not normally in use by MS SQL Server but is meaningful in the context of your application/business rules.
When Delphi recieves anything other than a successful completion code (0) back from the server it assumes there was a failure of that operation (be it Update, Delete or Insert) and WILL NOT remove that record from the result set on the client side.
The apps I'm working with do this on a regular basis, it's part of standard SQL knowledge in regard to client/server architecture :P
Good luck with your project
Pegasus
0
jvh042097Author Commented:
Sorry, but i also came to this so simple answer to my "stupid" question. Thanks alot anyway !!!
It was not a "stupid" question at all, just one that I assumed everyone was familiar with how to handle. Bad assumption on my part. Anyways, glad to see everything is working ok.
On to the next bug! :)
Pegasus
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.