Subject Re: [IBO] Exception "multiple records inserted"
Author Helen Borrie
At 12:04 PM 5/01/2005 +0000, you wrote:

>I'm not sure how an exception handler can solve the problem. After
>exception handling control is returned to the statement that follows
>the TRY/EXCEPT block. In other words IBO's code after RAISE staement
>never gets executed. So swallowing the exception can prevent the error
>message but won't ensure propert execution of the Post process.

This is not a database exception. You catch the exception and swallow
it...meaning, you don't raise it!

IBO throws this exception *after* Post.


>Despite the above I did follow your advice to swallow the exception.
>However, although there's no longer an error message, the transaction
>remains open and the new data is invisible, until I exit
>the application.

Look, somewhere in your code, you must call Commit.


>This is probably because the code that takes care of propely commiting
>the transaction is after the RAISE statement and so doesn't get to do
>its job.

Don't raise it!! You only raise it if you want *the exception* to be
handled outside. In this case, you want to handle it by catching it and
ignoring it, so that your procedure can continue.

>I tried to call the dataset's Commit in the handler, but that only
>resulted in a duplicate insert (which also was only visible after
>exiting the application).

You shouldn't be using the handler to call commit. You should use it to
swallow the exception.

I also tried to call the transaction's
>Commit, but that only resulted in another exception (token unknown
>"where").

Install a monitor and watch what is happening. This exception means you
are posting another statement, which is not what you want to do.

Don't call commit in the handler!! Use the handler to swallow the exception

One more thing I tried is provide OnError event handler and set
RaiseException to FALSE, but the handler doesn't even get called.

OnError is for database exceptions. This is no database exception, so
OnError doesn't get called. It's also not an *error*. It's a notification
- basically it is saying "Inserts normally return only one row
affected. This one returned more than one. What do you want to do?"

Write the block like this
begin
....
with myStatement do
try
Post;
except
on E:E_Multiple_Records_Inserted do
begin
// Gulp! Exception swallowed.
end;
end;
// Program control passes to here.
// if you want to commit here, do so.
// if not, the row stays posted and awaits the commit if/when it happens.
...
end;

Note: If the transaction was set to AutoCommit, then the Post call will
have already committed the transaction.

Helen