FieldDefs.Required not correctly set

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Roaster2
Posts: 51
Joined: Mon 13 Oct 2008 19:29

FieldDefs.Required not correctly set

Post by Roaster2 » Thu 12 Feb 2009 10:01

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?

Roaster2
Posts: 51
Joined: Mon 13 Oct 2008 19:29

Post by Roaster2 » Thu 12 Feb 2009 15:34

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.

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

Post by Plash » Tue 17 Feb 2009 12:25

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.

Roaster2
Posts: 51
Joined: Mon 13 Oct 2008 19:29

Post by Roaster2 » Wed 18 Feb 2009 19:11

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!

Post Reply