Page 1 of 1

Update inside UniQuery.Edit

Posted: Thu 29 May 2014 06:43
by FCS
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

Re: Update inside UniQuery.Edit

Posted: Thu 29 May 2014 09:11
by AlexP
Hello,

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

Re: Update inside UniQuery.Edit

Posted: Thu 29 May 2014 10:41
by FCS
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

Re: Update inside UniQuery.Edit

Posted: Fri 30 May 2014 09:44
by AlexP
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.

Re: Update inside UniQuery.Edit

Posted: Fri 30 May 2014 10:15
by FCS
Hello Alex,

Thanks for your reply containing such complete description of this subject

Regards
Michal

Re: Update inside UniQuery.Edit

Posted: Fri 30 May 2014 10:29
by AlexP
You are welcome. Feel free to contact us if you have any further questions.