TDatabase.DataSets Iteration (Bug?) 
Author Message
 TDatabase.DataSets Iteration (Bug?)

Problem:
During a TDatabase.DataSets array iteration, a dsInactive Dataset is added
to the DataSets array upon calling the ApplyUpdates method of an open and
cached TQuery.

Watches return the state of this "phantom" dataset as dsInactive and
Name='', which is nconsistent with the contents of the DataSets array which
should only hold currently open datasets.

The error happens when 2 DataSets are open - one a TTable and the other
TQuery. No error is generated when the DataSets array contains only TTables.

procedure PostOpenDataSets;

var
  I,J : Integer;
  ShouldCommit : Boolean;

begin
  ShouldCommit := false;

  {post tables if needed}
  for I := 0 to dmCM.dbCM.DataSetCount - 1 do
    if dmCM.dbCM.DataSets[I].State in [dsInsert, dsEdit] then
    begin
      dmCM.dbCM.DataSets[I].Post;

      {the following if statement was added as a fix when
       the DataSets array contains a TQuery. TQuery's
       don't like a Refresh command. If attempted, the
       program returns EDBEngine Error - " Table does not support
       this operation because it is not uniquely indexed"}

      if dmCM.dbCM.DataSets[I] is TTable then
        dmCM.dbCM.DataSets[I].Refresh;
    end;

    {check for necessity of transaction}
    for I := 0 to dmCM.dbCM.DataSetCount - 1 do
      if dmCM.dbCM.DataSets[I].CachedUpdates = true then
        if dmCM.dbCM.DataSets[I].UpdatesPending then
          ShouldCommit := true;

    {if necessary, do transaction}
    if ShouldCommit then
    begin
      dmCM.dbCM.StartTransaction;
      try

        {apply updates}

        {I is a DataSet tag value between 0 and 2. All
         master level tables have a tag value of 0.
         Tables are posted in order of their increasing
         tag value to avoid RI conflicts.}

        for I := 0 to 2 do
          for J := 0 to dmCM.dbCM.DataSetCount - 1 do
            if dmCM.dbCM.Datasets[J].Tag = I then
              if dmCM.dbCM.DataSets[J].UpdatesPending then
                dmCM.dbCM.Datasets[J].ApplyUpdates;

        {as the TQuery is posted in the above line,
         the dmCM.dbCM.DataSetCount value increments
         from 2 to 3. The "new" TDataSet has a Name = ''
         and a State = dsInactive !!!! Go figure!}

        {commit database}
        dmCM.dbCM.Commit;

        {commit (clear) updates}
        for I := 0 to dmCM.dbCM.DataSetCount - 1 do
          if dmCM.dbCM.DataSets[I].CachedUpdates = true then
            dmCM.dbCM.DataSets[I].CommitUpdates;

      except
        dmCM.dbCM.Rollback;
        raise;
      end;
    end;
  end;
end;

--
David Sweeney
Texas A&M University
*please forgive the anti-spam format of my address*
adaptiman (-at-) tamu.edu



Wed, 18 Jun 1902 08:00:00 GMT  
 TDatabase.DataSets Iteration (Bug?)


Wed, 18 Jun 1902 08:00:00 GMT  
 TDatabase.DataSets Iteration (Bug?)

 I got tentative confirmation from Borland yesterday that this does happen
and may be a bug.  These are the circumstances:

When a compound query (one that uses the Unique command or that joins two or
more tables) is open and cached, after the call to ApplyUpdates is made, an
extra TQuery is added to the TDatabase.DataSets array and the DataSetCount
is incremented by 1.  This extra dataset has a Name = '' and State of
dsInactive.  Since DataSets is supposed to be an array of all active
datasets, this extra inactive dataset poses a problem if you use DataSets to
iterate through the array of open datasets if, for example, you want to
create a procedure that posts multiple open datasets from within a
transaction.  The extra TQuery (for some strange reason) does not recognize
the property CachedUpdates, so any call to this property returns an error.

What I don't know is if this happens with a simple query (one that queries
only one table).  I haven't tested it.  Maybe someone else will.

David Sweeney
Texas A&M University
*please forgive the anti-spam format of my address*
adaptiman (-at-) tamu.edu


Quote:
>Problem:
>During a TDatabase.DataSets array iteration, a dsInactive Dataset is added
>to the DataSets array upon calling the ApplyUpdates method of an open and
>cached TQuery.

>Watches return the state of this "phantom" dataset as dsInactive and
>Name='', which is inconsistent with the contents of the DataSets array
which
>should only hold currently open datasets.

>The error happens when 2 DataSets are open - one a TTable and the other
>TQuery. No error is generated when the DataSets array contains only
TTables.

>procedure PostOpenDataSets;

>var
>  I,J : Integer;
>  ShouldCommit : Boolean;

>begin
>  ShouldCommit := false;

>  {post tables if needed}
>  for I := 0 to dmCM.dbCM.DataSetCount - 1 do
>    if dmCM.dbCM.DataSets[I].State in [dsInsert, dsEdit] then
>    begin
>      dmCM.dbCM.DataSets[I].Post;

>      {the following if statement was added as a fix when
>       the DataSets array contains a TQuery. TQuery's
>       don't like a Refresh command. If attempted, the
>       program returns EDBEngine Error - " Table does not support
>       this operation because it is not uniquely indexed"}

>      if dmCM.dbCM.DataSets[I] is TTable then
>        dmCM.dbCM.DataSets[I].Refresh;
>    end;

>    {check for necessity of transaction}
>    for I := 0 to dmCM.dbCM.DataSetCount - 1 do
>      if dmCM.dbCM.DataSets[I].CachedUpdates = true then
>        if dmCM.dbCM.DataSets[I].UpdatesPending then
>          ShouldCommit := true;

>    {if necessary, do transaction}
>    if ShouldCommit then
>    begin
>      dmCM.dbCM.StartTransaction;
>      try

>        {apply updates}

>        {I is a DataSet tag value between 0 and 2. All
>         master level tables have a tag value of 0.
>         Tables are posted in order of their increasing
>         tag value to avoid RI conflicts.}

>        for I := 0 to 2 do
>          for J := 0 to dmCM.dbCM.DataSetCount - 1 do
>            if dmCM.dbCM.Datasets[J].Tag = I then
>              if dmCM.dbCM.DataSets[J].UpdatesPending then
>                dmCM.dbCM.Datasets[J].ApplyUpdates;

>        {as the TQuery is posted in the above line,
>         the dmCM.dbCM.DataSetCount value increments
>         from 2 to 3. The "new" TDataSet has a Name = ''
>         and a State = dsInactive !!!! Go figure!}

>        {commit database}
>        dmCM.dbCM.Commit;

>        {commit (clear) updates}
>        for I := 0 to dmCM.dbCM.DataSetCount - 1 do
>          if dmCM.dbCM.DataSets[I].CachedUpdates = true then
>            dmCM.dbCM.DataSets[I].CommitUpdates;

>      except
>        dmCM.dbCM.Rollback;
>        raise;
>      end;
>    end;
>  end;
>end;

>--
>David Sweeney
>Texas A&M University
>*please forgive the anti-spam format of my address*
>adaptiman (-at-) tamu.edu



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. BDE bug and Live Datasets??

2. TDatabase class bug

3. TDatabase bug

4. URGENT ** Problem with Iteration ** URGENT

5. recursion vs. iteration

6. Slooooow iterations

7. datasets

8. flat-file datasets

9. Saving multiple client datasets to one file?

10. stored procs returning datasets

11. Datasets - updating

12. Non-BDE-Datasets, where's the list?

 

 
Powered by phpBB® Forum Software