Board index » delphi » implement Master/Detail with TQuery CachedUpdates ?? ? ?

implement Master/Detail with TQuery CachedUpdates ?? ? ?

hello one and all,

i am learning to apply CachedUpdates using d3 c/s and interbase.  i
think i have hit a wall.

i have a master/detail relation and would like to cache and apply both
tables as a set to improve performance and increase transaction control.
i place qMaster (TQuery) and connect sMaster (TDatasource) to it.  i
give it the sql line

        SELECT * FROM MASTER;

and     sMaster.Dataset := qMaster;

then i place qDetail (also TQuery) and connect its datasource property
to sMaster.  i give it the sql line

        SELECT * FROM DETAIL WHERE DIV = :MASTERDIV;

with    qDetail.Datasource := sMaster;

where masterdiv is a unique (primary) field in qMaster.  this sets up
the master/detail relation nicely and it works, except when i attempt to
use CachedUpdates.

it seems that everthing is working, except when i modify either the
master or detail entries.  i set CachedUpdates := True for both master
and detail, and then place a call to

procedure MasterApply(Dataset : TDataset);
begin
if (qDetail.State in [dsInsert,dsEdit]) then
        qDetail.Post;
if (qMaster.State in [dsInsert,dsEdit]) then
        qMaster.Post;
if qMaster.UpdatesPending or qDetail.UpdatesPending then
        db.ApplyUpdates([qMaster,qDetail]);
end;

in the BeforeScroll and AfterPost of the qMaster dataset.  i place the
apply in these events so as to be transparent to the user, yet update
when browsing or explicitly posting the master file.  this way all the
updates are sent to the database in one shot and under a single
transaction.

well this is my approach and the components and methods seem sound,
however, using CachedUpdates in this way does not update the underlying
database.  inserts or modifies do not make it to the physical database.
i attempted this using RequestLive := True for both TQueries, or for
RequestLive := False and attempted using TUpdateSQL and attaching one to
each TQuery.  both methods did not update the physical data.

i am probably missing something simple.  please advise me on what to do.
thank you for your time and have a nice day.
--
lucas
lu...@rutchem.rutgers.edu
http://chmwww.rutgers.edu/~lucas

may the wind be at your back .. .  .   .

 

Re:implement Master/Detail with TQuery CachedUpdates ?? ? ?


If you are looking to commit updates after every post(kind of defeating
the purpose of cached updates in a way), you should place your call to
MasterApply in the AfterPost of the master and detail query.  And since
only one dataset can call the procedure at a time, you should write the
function like this.

 procedure ApplyAfterPost(Dataset : TBDEDataset);
 begin
   with dataset do
   begin
     if state in [dsEdit,dsInsert] then
     begin
       post;
     end;
     if UpdatesPending then
     begin
       database.ApplyUpdates([dataset]);
     end;
   end;
 end;

Writing it this way, you could basically call this using any cached
query where you wish to apply updates after posting.  Cached updates are
really awesome!  Good luck!

Quote
lucas wrote:

> hello one and all,

> i am learning to apply CachedUpdates using d3 c/s and interbase.  i
> think i have hit a wall.

> i have a master/detail relation and would like to cache and apply both
> tables as a set to improve performance and increase transaction
> control.
> i place qMaster (TQuery) and connect sMaster (TDatasource) to it.  i
> give it the sql line

>         SELECT * FROM MASTER;

> and     sMaster.Dataset := qMaster;

> then i place qDetail (also TQuery) and connect its datasource property
> to sMaster.  i give it the sql line

>         SELECT * FROM DETAIL WHERE DIV = :MASTERDIV;

> with    qDetail.Datasource := sMaster;

> where masterdiv is a unique (primary) field in qMaster.  this sets up
> the master/detail relation nicely and it works, except when i attempt
> to
> use CachedUpdates.

> it seems that everthing is working, except when i modify either the
> master or detail entries.  i set CachedUpdates := True for both master
> and detail, and then place a call to

> procedure MasterApply(Dataset : TDataset);
> begin
> if (qDetail.State in [dsInsert,dsEdit]) then
>         qDetail.Post;
> if (qMaster.State in [dsInsert,dsEdit]) then
>         qMaster.Post;
> if qMaster.UpdatesPending or qDetail.UpdatesPending then
>         db.ApplyUpdates([qMaster,qDetail]);
> end;

> in the BeforeScroll and AfterPost of the qMaster dataset.  i place the
> apply in these events so as to be transparent to the user, yet update
> when browsing or explicitly posting the master file.  this way all the
> updates are sent to the database in one shot and under a single
> transaction.

Other Threads