views:

88

answers:

1

I´m using Delphi 5 with SQL Server 2000 here.

I have created an ADOQuery on top of an updatable view with an INSTEAD OF DELETE trigger.

The updatable view is basically used for controlling soft deletes. It filters out records which are marked as deleted and it hides the controlling column as well.

It all works fine when I´m issuing direct DELETE commands to the database. I delete the record on the view and the underlying table gets updated, doing the soft delete as expected.

When I try to use the ADOQuery to delete a record, it bypasses the view and deletes the record directly on the underlying table, so the instead-of-delete trigger on the view is never fired.

I´m also using referential constraints and the delete is erroring out because of them, but I don´t know if this matters. This does not happen when issuing delete commands to the view.

Would any of you guys know how to work around this annoying behaviour?

+1  A: 

Notice that it's deleting directly from the main table instead? This is probably because it's detecting that it's a view and working with the underlying table itself. To prevent this, declare your view WITH VIEW_METADATA, see ALTER VIEW for more information.

Then the ADO library will treat the view as a table. Be aware that you could get unwanted side effects by tricking your DB library like this, such as in cases when the delete isn't actually performed or it does an update instead of a delete.

Emtucifor
you da man, good sir
Daniel Itaboraí