Subject Re: [firebird-support] Default value
Author Marcello Fontolan
Helen, thank you for your allways perfect answer!

Helen Borrie escreveu:

> At 11:10 PM 26/02/2004 -0300, you wrote:
> > Hi,
> >
> > I have create the domain above and use it on all fields that
> >represents a money VALUE.
> > If I insert a new record using IBExpert (for example), the default
> >value is stored on NULL values but inserting from Delphi a NULL value is
> >stored.
> > Does I'm doing something wrong?
> >
> > CREATE DOMAIN VALOR AS
> > NUMERIC(15,2)
> > DEFAULT 0
>
> Delphi doesn't know about the server defaults. If you are just using the
> regular TQuery for your inserts and updates, Delphi includes the
> column in
> its update or insert query and passes NULL. Server defaults never
> override
> passed parameters, even if they are null.
>
> If you want Delphi to pass the default value, you have to tell it what to
> pass. Otherwise, somehow, you need to exclude that column from the
> INSERT
> or UPDATE statement that is passed. It's really easier to tell Delphi
> what
> the default is and write it to the parameter in the BeforePost event.
>
> Alternatively (and it is my preferred way to deal with ALL defaults),
> write
> a Before Insert trigger to apply a value if NULL is passed:
>
> create trigger bi_the_table for the_table
> active before insert position 0
> as
> begin
> if (ThisColumn is NULL) then
> new.ThisColumn = 0; /* or whatever default you want */
> end
>
> Triggers are much better for this than DEFAULT values on domains, etc.,
> since you can make them work under any condition, including updates if
> you
> want. (DEFAULT only works on inserts).
>
> /heLen
>
>
> *Yahoo! Groups Sponsor*
> ADVERTISEMENT
>
>
> ------------------------------------------------------------------------
> *Yahoo! Groups Links*
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/firebird-support/
>
> * To unsubscribe from this group, send an email to:
> firebird-support-unsubscribe@yahoogroups.com
> <mailto:firebird-support-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>

--

..::
Marcello Fontolan
marcello@...
::..