Re: OO and relation "impedance mismatch"

From: Kenneth Downs <firstinit.lastname_at_lastnameplusfam.net>
Date: Tue, 05 Oct 2004 08:45:00 -0400
Message-ID: <d05ujc.652.ln_at_mercury.downsfam.net>


Troels Arvin wrote:

> On Mon, 04 Oct 2004 18:40:56 -0400, Kenneth Downs wrote:
> 
>> But if you use a trigger, you can do tell-me-everything-I-did-wrong.
> 
> I don't quite understand this: How can the trigger overcome fail-on-first
> error handling?

The trigger records each error that it finds, but instead of stopping it keeps going. So the more you have, the more that are recorded. It actually never raises an error in the strict sense, you might say it always "returns true".

> 
>> The
>> best I have so far come up with is to return a table of error codes and
>> descriptions with each save attempt.
> 
> This is exactly the kind of error handling I'm looking for.
> 

Here is an example of my current experimental form. My own approach is to generate these triggers out of a data dictionary, as otherwise it becomes hopelessly unmanageable. But anyway, for SQL Server, an example would be:

CREATE TRIGGER acrmcustcall_INSERT
ON acrmcustcall
FOR INSERT AS
begin

  • THIS OPENING gets a standard batch # for every single
  • transaction, which would kill any real high volume
  • system. It is here so I can work with it in experimental
  • mode and ponder a better way to do it. It does have the
  • nifty advantage of working well with nested triggers. set nocount on declare _at_trxNum int declare _at_trxMade int set _at_trxMade = 0 if (select count(*) from zuuxtrxnum where spid = _at__at_spid) = 0 begin set _at_trxMade = 1 insert into zuuxtrxnum (spid) values (_at__at_spid) end select _at_trxNum=skey from zuuxtrxnum where spid = @@spid

--

--

  • The basic idea here is to return error codes. The
  • conditional on _at_trxMade allows nested triggers to work
  • properly.
    --
    IF _at_trxMade > 0 BEGIN if (Select count(*) from zuuxtrxerr where skeytrx = _at_trxNum) > 0 begin SET NOCOUNT OFF SELECT errnum,errop,tabname,errpkey,errdsc FROM zuuxtrxerr WHERE skeytrx = _at_trxNum ROLLBACK TRANSACTION end delete from zuuxtrxnum where spid = _at__at_spid END END
-- 
Kenneth Downs
Use first initial plus last name at last name plus literal "fam.net" to
email me
Received on Tue Oct 05 2004 - 14:45:00 CEST

Original text of this message