Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Modifications of a read only (Sensitive=False) query result.
Tue, Sep 17 2024 2:08 PMPermanent Link

Mario Enríquez

Open Consult

Hi folks,

I need to do a modification on a  readonly TEDBQuery before converting to JSON string (no need to affect the database) and I really don't want to go with the overhead of using TClientDataset.

Here's the code

       sqlGetMovs.First;
       while not sqlGetMovs.Eof do
       begin
         sqlGetMovs.Edit; <--- Readonly Error
         saldo := saldo + (sqlGetMovs.FieldByName('ingresos').AsFloat -          sqlGetMovs.FieldByName('egresos').AsFloat);
         sqlGetMovs.FieldByName('saldo').Value := saldo;
         sqlGetMovs.Post;
         sqlGetMovs.Next;
       end;
       JSONRaw := DataSetToJSON(sqlGetMovs);

Is there any property or setting that could help avoid the read only validation?

Regards,
Mario
Tue, Sep 17 2024 2:37 PMPermanent Link

Terry Swiers

> I need to do a modification on a  readonly TEDBQuery before converting to JSON string (no need to affect the database) and I really don't want to go with the overhead of using TClientDataset.

I don't know of anything direct that you can change in EDB to allow for this.  In my app, I use a TFDMemTable to get thing local when EDB can't.  I have a global function that I can call, which makes it really easy to grab any query results with a single function call just by passing the EDB object:

function GetFDMemTable(DataSet: TDataSet; CachedUpdates: Boolean): TFDMemTable;
begin
 Result := TFDMemTable.Create(nil);
 Result.CachedUpdates := CachedUpdates; //indicate if you want to keep track of changes
 Result.CopyDataSet(DataSet, [coStructure, coRestart, coAppend]);
 if CachedUpdates then Result.MergeChangeLog;
end;

If you have the DevExpress components, you can also use the TdxMemData class, or any other in memory dataset that you might have installed in your environment.
Tue, Sep 17 2024 4:43 PMPermanent Link

Mario Enríquez

Open Consult

Thank you very much Terry, I would look into it.
Wed, Sep 18 2024 7:34 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Mario


I must be missing something here, or being very thick, why not just include that in the sql that generates sqlGetMovs?

Roy Lambert
Wed, Sep 18 2024 5:13 PMPermanent Link

Mario Enríquez

Open Consult

Hi Roy,

Yes, the field is include in the query, but I need to updated with some last state calculation (info not in the database). However I did solve another way. Thanks for asking.

Regards,
Mario
Image