Update inside UniQuery.Edit

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Update inside UniQuery.Edit

Post by FCS » Thu 29 May 2014 06:43

Hello,

How exactly works the update during edit ?

I have a PostgresSQL record like this (for example):
Table1 (P1 : string[30];
P2 : string[30];
P3 : string[30];
P4 : string[30];
Geom : Geometry (spatial WKT));

I use normal query loop
....
UniQuery.SQL.Add('SELECT * FROM Table1 WHERE ....);
UniQuery.First;
while not UniQuery.Eof do begin
UniQuery.Edit
UniQuery.FieldByName('P1').AsString:='abc';
UniQuery.FieldByName('P2').AsString:='xyz';
UniQuery.Next;
end;
...
I understand that the content of others fields are safe, especially the Geom ?
How do you know whether a field is changed ?
What will happen when before editing field P1='abc'?
Will be this field treated as changed ?

Thanks
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Update inside UniQuery.Edit

Post by AlexP » Thu 29 May 2014 09:11

Hello,

I don't quite understand what your questions are about. Could you clarify what you mean?

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: Update inside UniQuery.Edit

Post by FCS » Thu 29 May 2014 10:41

Hello,

Thanks for quick reply.

UniQuery.SQL.Add('SELECT * FROM Table1 WHERE ....); //reads all fields
UniQuery.First;
while not UniQuery.Eof do begin
UniQuery.Edit
UniQuery.FieldByName('P1').AsString:='abc';
UniQuery.FieldByName('P2').AsString:='xyz';
UniQuery.Post; //put changes
UniQuery.Next;
end;

I want to know what is happen when the UniQuery.Post is executed.

Do Post make only this: UPDATE Table1 SET P1='abc', P2='xyz' on current record and the rest of fields will stay with their values not changed?

How does the Post know whether a field is changed ?

What will happen when before editing field P1='abc' and I do UniQuery.FieldByName('P1').AsString:='abc'?
Will be this field treated as changed ?

The value is the same before and after edit. Is there any indicator that the field is changed and this indicator tells which fields should be updated when the Post is executed?

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Update inside UniQuery.Edit

Post by AlexP » Fri 30 May 2014 09:44

Yes, by default, the Update query is generated only by those fields, in which changes were made (changes comparison is performed inside our components by comparing old and new values of a field). Fields, that weren't modified, won't be included to the query. This behavior can be modified by setting the UniQuery.Options.UpdateAllFields property to True. In this case, the Update query will be generated by all the fields, even if none of them were modified.
Until the Post method calling, you can check if the field was modified by comparing the NewValue and OldValue properties of this field.

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: Update inside UniQuery.Edit

Post by FCS » Fri 30 May 2014 10:15

Hello Alex,

Thanks for your reply containing such complete description of this subject

Regards
Michal

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Update inside UniQuery.Edit

Post by AlexP » Fri 30 May 2014 10:29

You are welcome. Feel free to contact us if you have any further questions.

Post Reply