Forum > Databases

is there any solution like clentdataset-DataSetProvider-query on delphi

(1/5) > >>

Hello everyone:
 i always develop n-tier application on delphi. and is used to code by ClientDataSet on client side and DataSetProvider on server side. is there any solution like above on lazarus?
  I attach some example code that i worked on delphi:
1. get data from database:
1.1server-side code:
   Query.Connection:=DBConnect;  //DBConnection connected to the database  and Query connected to the DBconnection
   Query.SQL.Text:='select * from tablename'; //manully set sql statement
      result:=DataSetProvider .GetRecords(-1,i,MetaDataOption+ResetOption); // DataSetProvider linked to the query and

1.2 return search result by networt transfom like web service

1.3 Client-side code:
      :=search result returned by server-side web service

2. commit clientdataset changed record  to server side database:
2.1 Client-side code:
             send ClientDataSet.Delta to server side by web service

2.2server-side code:
            Query.Connection:=DBConnect;  //DBConnection connected to the database  and Query connected to the DBconnection
            Query.SQL.Text:= 'select * from tablename where 1=2';
            DataSetProvider.ApplyUpdates(Deltadata,0,i); // Deltadata is from ClientDataSet.Delta
2.3 on DataSetProviderBeforeUpdateRecord  event  to write code for some sql manully like below:

   procedure TdmSysManage.dspDepartMentBeforeUpdateRecord(Sender: TObject;
  SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
  UpdateKind: TUpdateKind; var Applied: Boolean);
  if SourceDS =qryDepartMent then
     //DeltaDS.FieldByName('ID').ProviderFlags := [];
     case UpdateKind of
        DeltaDS.FieldByName('ID').NewValue:=newID ;
        Applied :=False;
        Applied :=False;
        DeltaDS.FieldByName('ID').ProviderFlags := [pfInKey];
        Applied :=true;
        DBConnect.Execute('delete from tablename where ID = ' + DeltaDS.FieldByName('ID').oldvalue);

this is very convenient way to process changed record, I can save changed record to database automatic or manully if needed.

in lazarus is there some similar way?

thanks a lot!

It is the exact same on Freepascal/Lazarus as it is in Delphi..

Hello, Thaddy
 is it  exact same on Freepascal/Lazarus as it is in Delphi ? can you attch some example code for refrence?
thank you!

Like your own code? Which is not complete. But Your own code should work if it works in Delphi.
Otherwise report back.

I couldn't find anything like either TDataSetProvider or TClientDataSet in Lazarus.
Currently I'm using TBufDataSet instead of TClientDataSet.

1. get data from database:

   When there is a request frrom client,

   1) Execute SQL statement in server. This is TSQLQuery. I copy it to TBufDataSet,
       using TBufDataSet.CopyFromDataSet(SQLQuery1), save it as TStream,
       and server returns the TStream to the client. 
   2) Client gets the stream, and a copy of TBufDataSet is made --- using TBufDataSet.LoadFromStream.

2.  Update changes to the server

    As there are no TDataSetProvider, there are no Delta neither.

    There are two options.

    1) For a table with large amount of modifications,
       - First I pack the new table as a TStream, and send it to server.
       - Server first delete all records of the specific condition.
       - Server inserts all records received from the client.

    2)  Small changes :  I try to keep both table (server and client) as the same at record basis ---
         treated in the event handlers of  beforepost, beforeinsert, beforedelete, etc.
         of client's local dataset (TBufDataSet).
         When there is a deletion, for example, the client first request the server to delete a record
         with the key fields in the server DB, and if successful then delete client's dataset record
         but calls DataSet.Cancel if not successful.

         Insertions and updates are treated within beforepost event.
         Client sends one records data in the TStrings.Text format (fieldname=value...),
         and server call InsertOrUpdate based on keys.

Hope anybody suggests better idea.


[0] Message Index

[#] Next page

Go to full version