Subject Re: [IBO] Setting Master/Detail with TIBO Datasets
Author Helen Borrie
At 07:03 PM 16-09-02 +0000, you wrote:
>I have the scenario:
>2 TIBOQuery´s with a Master/Detail relationship.
>
>The first (master) is set to table COMPRAS with the structure above:
>ID INTEGER PK
>NUMERO INTEGER
>COD_FORNECEDOR INTEGER FK(FORNECEDORES)
>VALOR NUMERIC(10,2)
>
>The PK (ID) is a autoincrement field with a generator set into the
>before_insert trigger.
>
>The second (detail) is set to table ITENSCOMPRAS with the structure
>above:
>ID INTEGER PK
>ID_COMPRA INTEGER FK(COMPRAS)
>COD_PRODUTO INTEGER FK(PRODUTOS)
>QTD INTEGER
>PRECO NUMERIC(10,2)
>
>The PK (ID) is a autoincrement field with a generator set into the
>before_insert trigger.
>
>Why can i configure these two Datasets properties (KEYLINKS...) to
>the master/detail relation work whell.
>
>The biggest problem is: The detail table isn´t getting the value of
>the field ID of the table COMPRAS.
>I have set the propertie GeneratorLink of the table COMPRAS to get
>the value of the last value of the Generator, but it don´t work to
>the detail rows.

I see from your earlier question that you don't understand KeyLinks. The
ordinary use of KeyLinks is to indicate the unique key fields of your
dataset. In your example, the KeyLinks of your COMPRAS set would be ID and
for your ITENSCOMPRAS set it would be ID.

KeyLinks has another (different) use with a special kind of linking for a
lookup relationship but this usage is not relevant to your master-detail
problem.

With native IBO (TIB_Query) you use Mastersource and MasterLinks (or
MasterParamLinks) for your master-detail relationships.

However, with the TDatasource-compatible components (TIBOQuery) which you
are using, you have the same limitations that you have with the native
Delphi VCL components when doing M-D linking:

1. In the Detail set, set the Datasource property to the TDatasource that
points to the Master set.
2. If the fields that link the Detail to the Master do not have the same
name, you must use a parameter in the Detail query to perform that
link. Because this is the case in your example, you need the following SQL
statement for your Detail set:

SELECT ID,
ID_COMPRA,
COD_PRODUTO,
QTD,
PRECO
FROM ITENSCOMPRAS
WHERE ID_COMPRA = :ID

Helen