Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: Master-Detail through MasterSource in ADQuery
Master-Detail through MasterSource in ADQuery
Posted: 2007/08/07 09:40
 
Master-Detail through MasterSource in ADQuery returns empty detail for true value selected in master:

demo:
same query on ADQuery1 and ADQuery2

SELECT b
FROM t

b is bit field - using MS SQL 2000

ADQuery2.MasterSource := DataSource1;
ADQuery2.IndexFieldNames := 'b';
ADQuery2.MasterFields := 'b';

On False b value in master - Ok - shows all records with False in detail
On True b value in master detail is empty

Checked same demo on 2 ADClientDataSets - works Ok
demo:
ADClientDataSet1.CreateDataSet;
ADClientDataSet1.AppendRecord( [ False ] );
ADClientDataSet1.AppendRecord( [ True ] );
ADClientDataSet2.CreateDataSet;
ADClientDataSet2.AppendRecord( [ False ] );
ADClientDataSet2.AppendRecord( [ True ] );

Ok - Shows in detail one record

By the way - setting IndexFieldNames before MasterFields is significant and as I've checked wrong order of this two lines leads to failing of different kind on different DB engine. For AnyDac it may lead to return of empty detail. Do you think it will be worthwhile to raise exception like ClientDataSet does?

ClientDataSet1.CreateDataSet;
ClientDataSet1.AppendRecord( [ False ] );
ClientDataSet1.AppendRecord( [ True ] );
ClientDataSet1.MasterSource := DataSource1;
// Now error will be raised by TClientDataSet
ClientDataSet1.MasterFields := 'b'; <- EDatabaseError "Field index out of range"
ClientDataSet1.IndexFieldNames := 'b';
Re:Master-Detail through MasterSource in ADQuery
Posted: 2007/08/08 01:17
 
Hello

1) On False b value in master - Ok - shows all records with False in detail
On True b value in master detail is empty

Ok, fixed. To fix this issue, open daADDatSManager.pas, find there method TADDatSRow.CompareData and replace code for dtBoolean with this one:

     dtBoolean:       if PWordBool(ABuff1)^ then         if PWordBool(ABuff2)^ then           Result := 0         else           Result := 1       else         if PWordBool(ABuff2)^ then           Result := -1         else           Result := 0;


2) setting IndexFieldNames before MasterFields is significant
In AnyDAC it must work well. If not, then please report your case.

Regards,
Dmitry
Re:Master-Detail through MasterSource in ADQuery
Posted: 2007/08/08 03:07
 

2) setting IndexFieldNames before MasterFields is significant
In AnyDAC it must work well. If not, then please report your case.


I've attached demo with ADClientDataSet
File Attachment:
File name: ad_demo.zip
File size:1770 bytes
Re:Master-Detail through MasterSource in ADQuery
Posted: 2007/08/09 01:42
 
Ok, thank you. Fixed. I decided to not post patch, because few places was affected.