2009. május 7., csütörtök

Sending data from database by portions


Problem/Question/Abstract:

Some times we need send hugo quantity of data from MiddleWare Server to client application. If we do it one portion than user mast wait long time, but we can send this data by portions, when user is needed in it.

Answer:

Some times we need send hugo quantity of data from MiddleWare Server to client application. If we do it one portion than user mast wait long time, but we can send this data by portions, when user is needed in it.

This is sample about getting portion of data from DataSetProvider and adding it to CLientDataSet.

In my article "Accessing DataBase via 3th server" you can read how send data between applications usin INDY components.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DB, DBTables, Provider, DBClient, Grids,
  DBGrids, ExtCtrls, DBCtrls, IdBaseComponent,
  IdAntiFreezeBase, IdAntiFreeze, JvSpecialProgress;

type
  TForm1 = class(TForm)
    DataSetProvider1: TDataSetProvider;
    Table1: TTable;
    BitBtn1: TBitBtn;
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    ClientDataSet1: TClientDataSet;
    BitBtn2: TBitBtn;
    DBNavigator1: TDBNavigator;
    IdAntiFreeze1: TIdAntiFreeze;
    BitBtn3: TBitBtn;
    JvSpecialProgress1: TJvSpecialProgress;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure BitBtn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    data: OleVariant;
    records: integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  recs: integer;
  j: integer;
begin
  ClientDataSet1.Active := False;
  data := DataSetProvider1.GetRecords(1, recs, ResetOption + MetaDataOption);
  Showmessage(format('get %d Records', [recs, i]));
  ClientDataSet1.AppendData(data, False);
  ClientDataSet1.Active := True;

end;

procedure TForm1.FormShow(Sender: TObject);
begin
  records := DataSetProvider1.DataSet.RecordCount;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
  recs: integer;
  j: integer;
begin
  data := DataSetProvider1.GetRecords(-1, recs, ResetOption + MetaDataOption);
  ClientDataSet1.AppendData(data, False);
  ClientDataSet1.Active := True;
end;

procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
var
  recs: integer;
begin

  case Button of
    nbNext:
      begin
        if DBNavigator1.DataSource.DataSet.RecordCount data :=
          DataSetProvider1.GetRecords(1, recs, ResetOption + MetaDataOption);
        ClientDataSet1.AppendData(data, False);
      end;
  end;
  nbPrior:
  begin
  end;
  nbLast:
  begin
    if DBNavigator1.DataSource.DataSet.RecordCount data :=
      DataSetProvider1.GetRecords(-1, recs, ResetOption + MetaDataOption);
    ClientDataSet1.AppendData(data, False);
  end;
end;
nbFirst:
begin
end;
end;

end;

procedure TForm1.BitBtn3Click(Sender: TObject);
var
  recs: integer;
begin
  JvSpecialProgress1.Maximum := records;
  JvSpecialProgress1.Position := 1;
  while ClientDataSet1.RecordCount data := DataSetProvider1.GetRecords(1, recs,
    ResetOption + MetaDataOption);
  ClientDataSet1.AppendData(data, False);
  JvSpecialProgress1.Position := JvSpecialProgress1.Position + 1;
end;
end;

end.

Nincsenek megjegyzések:

Megjegyzés küldése