master detail problem

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
luis_augusto
Posts: 43
Joined: Fri 14 Oct 2005 13:45

master detail problem

Post by luis_augusto » Mon 27 Nov 2006 13:47

I have two tables:

MasterTable Orders x DetailTable Quotations
Supplier;Order (detailfields) x Winner;Order (masterfields) both non-primary keys

Order is Autoinc

During insert process, Order is null in both tables.
Supplier = 'Supplier 1'
and
Winner = 'Supplier 1';

Detail records are not available, but they should, since the relationship is stablished:

'Supplier 1' = 'Supplier 1'
null = null

How come?

Thanks.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Tue 28 Nov 2006 12:23

Please make sure that:
1. You use SDAC SQL Generator for generating the INSERT statement. If you use your own INSERT statement, you should take care about getting the IDENTITY value after insert.
2. The value of the TCustomMSDataSet.Options.QueryIdentity property is True both in master and detail TMSQuery components.
3. The value of the TCustomDADataSet.ParamCheck property is True both in master and detail TMSQuery components.

luis_augusto
Posts: 43
Joined: Fri 14 Oct 2005 13:45

master detail

Post by luis_augusto » Tue 28 Nov 2006 17:00

The problem is not that I am getting a null value on the identity field.

Orders.Order is, indeed, an Identity field on table orders, but my intention is to get all quotations for a given supplier, whose don´t have an order number (field Quotations.Order is null), yet.

After get them, I will generate an order number and then put it into the quotations's order field.

It seems that, when connecting orders and quotations through the order field, using an Identity field, the value passed to the query is interpreted as zero (not as null). I may be wrong, but the effect that I am experiencing the same (as if I had passed zero as order instead of null).

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Wed 29 Nov 2006 13:30

In such case SDAC SQL Generator generates the following query:
SELECT * FROM detail WHERE MasterID=:p1
When the NULL value is assigned to the 'p1' parameter, query becomes like the following:
SELECT * FROM detail WHERE MasterID=NULL
it is not the same as
SELECT * FROM detail WHERE MasterID IS NULL
So SDAC Master/Detail relationship doesn't support relations by NULL values.

luis_augusto
Posts: 43
Joined: Fri 14 Oct 2005 13:45

master detail relationship

Post by luis_augusto » Wed 29 Nov 2006 14:22

In the future, would be nice if Sdac could support this, since BDE with paradox does.

Thank you, anyway, for the hint. Knowing this, I can workaround the problem.

Post Reply