Subject Re: [IBO] Still little problems
Author Helen Borrie
At 05:42 PM 13/03/2003 +0100, you wrote:
>hello Helen,
>ok, I have spent the last three days printing the whole GSG and
>starting a very interesting off-line <g> reading. I think that now the
>concept of transactions is a bit more clear.
>As a result of this reading I have obtained a working form with a good
>aspect as well but I still have some small problems (not with
>transactions now <g>).
>The form works with only one table (no joins) and all the fields are
>required. This is enforced also in the database by means of the
>respective domains (they are all defined as NOT NULL). The REQUIRED
>check box in the TIB_Query.ColumnAttributes for all fields is grayed
>so, AFAIK, IBO should ignore the Required management and let the
>database throw an error if a null field is let in the row.

No, this is not how it works. If the column is NOT NULL in the table
definition, the Prepare method causes IBO to store this attribute in the
properties of the TIB_Column object. The "Field XXXX is a required field"
exception is not a database exception, but a local exception which is
thrown when IBO runs the procedure CheckRequiredFields during the
BeforePost event processing.

If you *want* the exception to occur after the Post has failed, or if you
want a null to be allowed for a non-nullable column so that BeforeUpdate
and BeforeInsert triggers can operate on it at the server, then make the
ColumnAttribute NOTREQUIRED to be true. This will cause
CheckRequiredFields to ignore this column.

>For this purpose I have written a simple TIB_Query.OnError handler
>containing this code:
>RaiseException := False;
>MessageDlg('There is an error'....
>but I have left for now TIB_Query.CheckRequired := True.

That's OK to leave CheckRequired True - it determines whether
CheckRequiredFields is called at all.

>Well, this handler is never fired when I leave a NULL field and I try
>to post, and another error message is shown (I suppose it is an IBO
>standard error message showing because CheckRequired := True).

Your OnError handler will not respond to exceptions raised by
CheckRequiredFields. It responds only to errors returned when Post
fails. At the time of the CheckRequiredFields exception, Post has not yet
been called.

>But now if I set CheckRequired := False, no errors pop up at all and
>the NULL field is written in the row, even if the field has the "NOT
>NULL" check in the domain.

This should not be the case. The NOT NULL constraint should cause an
exception when the row is posted; and the commit cannot proceed.

>What am I doing wrong (or forgetting) now?

Are you watching an IB_MonitorDialog, to see what values are going through
in your SQL?

Have you touched the BLANKISNULL attribute at all?

Is there any possibility that you have DEFAULT assigned for these columns
(these work only on inserts), or that you are handling NULL via triggers?

>Shouldn't an EIB_Error pop up in this case?

Yes, if NULL is not being handled by a trigger or a DEFAULT, you should get
an EIB_ISCError if Post fails. Post *should* fail if NULL is passed to a
non-nullable column. The EIB_ISCError is transformed into a structure
which you can read in the OnError event. Other errors don't trigger the
OnError event.