Subject | Re: [firebird-support] Default value |
---|---|
Author | Helen Borrie |
Post date | 2004-02-27T03:07:06Z |
At 11:10 PM 26/02/2004 -0300, you wrote:
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
> Hi,Delphi doesn't know about the server defaults. If you are just using the
>
> 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
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