Page 1 of 1

FieldDefs.Required not correctly set

Posted: Thu 12 Feb 2009 10:01
by Roaster2
Hi,

I'm using this SQL statement to retrieve some records from a Firebird DB and to insert an 'empty' record for each CLIENT and LANGU:

Code: Select all

select * from pricelist
union
select client, langu, NULL, NULL, NULL, NULL, NULL, NULL from pricelist
The table PRICELIST is defined as:

Code: Select all

CREATE TABLE PRICELIST 
(
  CLIENT                    DCLNT NOT NULL,
  LANGU                    DLANGU NOT NULL,
  PRICELIST            DPRICELIST NOT NULL,
  TEXT             DPRICELISTDESC ,
  CREATED                DCREATED ,
  CREATED_BY          DCREATED_BY ,
  CHANGED                DCHANGED ,
  CHANGED_BY          DCHANGED_BY ,
 CONSTRAINT PK_PRICELIST PRIMARY KEY (CLIENT, LANGU, PRICELIST)
);
ClientDataSet.Fielddefs[0].Required is set to True. This is for the field CLIENT.
ClientDataSet.Fielddefs[1].Required is set to True, too, for field LANGU.
But ClientDataSet.Fielddefs[2].Required is set to False, although it is part of the primary key. Why this?
Using this SQL statement:

Code: Select all

select * from pricelist
union
select client, langu, pricelist, NULL, NULL, NULL, NULL, NULL from pricelist
works, this means ClientDataSet.Fielddefs[2].Required is set to true, however when performing a Dataset.Refresh, I get a key violation.

So how can I get the Required property correctly set to true?

Posted: Thu 12 Feb 2009 15:34
by Roaster2
Where does the IbDac units fetch the DB fields and decide whether it is a required one or not?

I've tried to debug my sample application but did not really find the lines where this happens.

Posted: Tue 17 Feb 2009 12:25
by Plash
IBDAC receives the information about which fields are required, from Firebird server. If an expression (like NULL) is used for a field, the server consider that this field is not required.

IBDAC get this information in the TGDSRecordSet.InternalInitFields procedure of the IBCClasses unit.

Posted: Wed 18 Feb 2009 19:11
by Roaster2
I've 'fixed' this by using this SQL statement

Code: Select all

select * from pricelist
union
select client, langu, cast('' as char(6)) pricelist, NULL, NULL, NULL, NULL from pricelist
This works well and the Requires property is set as well. Thanks for replying, Plash!