Default values for a field

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
pwatel
Posts: 39
Joined: Wed 11 Feb 2009 09:42

Default values for a field

Post by pwatel » Mon 23 Mar 2009 14:56

hello to all
I have a field in a table let us say for argument sake it is an integer field
PAGENUMBER INTEGER DEFAULT 0 NOT NULL
When I insert a record and do not put a value there I get an error message
the field PAGENUMBER needs a value (Which defies the purpose of a default doesnt it?)
The dataset component
a) is not smart enough to provide a value ?? which is strange
b) I need to set up a special something which I overlooked
I just do a SELECT * FROM at run time no special fields definitions
to get around it I have to create an AfterInsert event and shove there the defaults which is less than optimal
Any Ideas on that guys ?
thanks
PW

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 24 Mar 2009 08:20

There are two ways to solve the problem:

1. Set the RequiredFileds option of TIBCQuery to False. In this case the error message is not shown, and field in the database is filled with the 0 value. But user sees an empty value in the grid after he posts the record.
You can set RefreshOptions.roAfterInsert to True to get an actual value from the database after insertion, or (for Firebird 2.0 and higher) set the DMLRefresh property to True.

2. Set the DefaultValues option of TIBCQuery to True. In this case IBDAC reads the default values from the database, and fills the DefaultExpression property of TField. When a record is inserted, value from the DefaultExpression property is assigned to the field.

pwatel
Posts: 39
Joined: Wed 11 Feb 2009 09:42

Default values for a field

Post by pwatel » Tue 24 Mar 2009 11:02

thanks it works
I should have looked more carefully at the options...I am a rookie with your components...
but what I do not get is the option DefaultValues of a TIBCQuery is set to false by default, I am sure you have a reason...
regards
PW

Post Reply