I'm using TMyQuery component (from MyDAC suite) with the this sentence:
SELECT id, name, salary, ‘n’ as modified FROM employees
If I change the fields SALARY and MODIFIED I would receive the error “Unknown column MODIFIED in field list”
OK. One solution would be the use of SQLUpdate property, specifying the sentence for update:
UPDATE employees SET name = x, salary = y WHERE id = z
But… this implies that the field NAME would be updated even if the only field really changed is SALARY. And this could lead to problem. Imagine that, at the same time, ComputerA changes the field NAME and ComputerB changes the field SALARY. The data from the last computer to apply would prevail.
Could anyone please help me?
MODIFIED
since it is not a real field in the DB. But, in any case, if you don't actually have a new value to assign to theNAME
field then simply don'tUPDATE
theNAME
, eg:UPDATE employees SET salary = y WHERE id = z
. But the real question is, why would you have 2 computers updating the same DB record at the same time? Yes, the lastUPDATE
to run will "win", so don't update a field if it doesn't actually need to be changed. And you should synchronize the two computers to avoid overlappingUPDATE
s.TMyQuery
to let you modify such fields in the first place. If it is, I would consider that a bug, such fields should be read-only. On the other had, there is nothing stopping you from querying the table structure to see if a given field actually exists or not before allowing it to be modified.