🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.multi-tier
Article #403

StatusFilter Help Request with Compilable Illustration

#403
From: Paul J. Keller
Date: Tue, 28 May 2002 21:14
115 lines
4714 bytes
This is Paul Keller.

I must be misunderstanding TClientDataset::StatusFilter and how it's used.
I'm wondering if someone could help me determine what I'm doing wrong.  I've
included a compilable illustration of the issue I'm working through.  I'm
developing in CPPBuilder 6 Enterprise, Update #1.

In my application, I don't want to see any records that have been added or
deleted in a TClientDataSet before the records have been merged from the
change log.  From what I understand, if I set StatusFilter to
usModified<<usUnmodified, I should not see any records that have been
inserted or deleted in the client dataset.  However, what I'm observing is
that all records in the TClientDataSet are returned.  In fact, it doesn't
seem to matter what I set the StatusFilter of a TClientDataSet object to, it
always returns all records.

The example I have included below illustrates the behavior that I'm getting.
This can be pasted into the OnClick event of a button on a form, and after
including DBClient.hpp in the header of the form, you should be able to
compile and run this example to observe what I'm seeing.

The example below does the following:
   creates a client data set with three fields
   sets the StatusFilter property to only show modified and unmodified
records
   sets up an index to order the records for display
   inserts a record and merges it (to illustrate the existing data in the
dataset with usUnModified status)
   inserts another record (without merging) so it's status is usInserted
   loops through the records in the data set, displaying the update status
and UserID field of each record

What I expect to see is only the "previously merged" records being displayed
in the "while" loop.  But instead, all records, including the newly inserted
(and "unmerged" record), are seen when iterating through the client dataset.

Thanks for any help in advance,
Paul

Here's the example:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TClientDataSet *tmpcds=new TClientDataSet(this);
  try
  {
    // Define fields
    tmpcds->FieldDefs->Clear();
    // UserID
    TFieldDef *pfd=tmpcds->FieldDefs->AddFieldDef();
    pfd->Name="UserID";
    pfd->DataType=ftInteger;
    pfd->Required=true;
    // DomainName
    pfd=tmpcds->FieldDefs->AddFieldDef();
    pfd->Name="DomainName";
    pfd->DataType=ftString;
    pfd->Size=64;
    pfd->Required=true;
    // UserName
    pfd=tmpcds->FieldDefs->AddFieldDef();
    pfd->Name="UserName";
    pfd->DataType=ftString;
    pfd->Size=64;
    pfd->Required=true;

    // create the ClientDataSet
    tmpcds->CreateDataSet();
    // only show modified and unmodified records
    tmpcds->StatusFilter<<usModified<<usUnmodified;
    // set the IndexFieldNames explicitly;
    tmpcds->IndexFieldNames="DomainName;UserName;UserID";

    // open the ClientDataSet
    tmpcds->Open();

    // add a record
    tmpcds->InsertRecord(ARRAYOFCONST((1,"ZDOM","j1232")));

    // merge changes to this point in the dataset
    tmpcds->MergeChangeLog();

    // add another record without merging changes
    tmpcds->InsertRecord(ARRAYOFCONST((2,"ZDOM","j1230")));

    // move to beginning
    tmpcds->First();

    // show status of each record we can see
    while (!tmpcds->Eof)
    {
      AnsiString st="";
      switch (tmpcds->UpdateStatus())
      {
        case usModified : st="Mod";break;
        case usUnmodified : st="Unmod";break;
        case usDeleted : st="Del";break;
        case usInserted : st="Ins";break;
      };
      ShowMessage(st+"-"+tmpcds->FieldByName("UserID")->AsInteger);
      tmpcds->Next();
    }

    // close the dataset
    tmpcds->Close();
  }
  __finally
  {
   if (tmpcds)
   {
      delete tmpcds;
      tmpcds=NULL;
   }
  }
}
Technical Details
Message-ID: <3cf3efa8$1_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!cox.net!news-out.visi.com!hermes.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcd2b,b37f5206896865c2,start
X-Google-Attributes: gidfcd2b,public
X-Google-ArrivalTime: 2002-05-28 14:10:17 PST
From: "Paul J. Keller" <kellerpj@NOSPAMepix.net>
Newsgroups: borland.public.cppbuilder.database.multi-tier
Subject: StatusFilter Help Request with Compilable Illustration
Date: Tue, 28 May 2002 17:14:12 -0400
Lines: 118
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700
NNTP-Posting-Host: 24.154.87.120
Message-ID: <3cf3efa8$1_2@dnews>
X-Trace: dnews 1022619560 24.154.87.120 (28 May 2002 13:59:20 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!cox.net!news-out.visi.com!hermes.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!dnews