The list of questions and answers related to data editing.
A: This error often happens when AnyDAC includes some float / double / single / date / datetime / time or some other table fields, which are the subject to the precision lost, into WHERE phrase. Then at the parameter assignments the precision lost may happen. As result of that the WHERE phrase returns no records.
AnyDAC may include such fields into WHERE depending on UpdateOptions.UpdateMode. Sometimes you can see this error with upWhereKeyOnly. Although you have specified upWhereKeyOnly, AnyDAC still may use upWhereAll. Which is fallback, when there is no PK fields defined. No PK fields may be defined when:
Other reason with some DBMS (SQL Server, PostgreSQL) is that the table has a trigger, which modifies the data. With SQL Server put SET NOCOUNT ON at trigger beginning. With PostgreSQL set UpdateOptions.CountUpdatedRecords to False.
A: AnyDAC generates updating SQL commands automatically, when the original SQL command is a simple SELECT or a SELECT with JOIN, where is a single table preserving the primary key fields. So, the TADUpdateSQL usage is optional. TADUpdateSQL is required when:
A: Use the following code:
ADUpdateSQL1.Commands[arInsert].MacroByName('MacroName').Value := 'value';
A: After calling ApplyUpdate, you should call CommitUpdates. After this call all changes will be deleted from internal cache.
A: Two ways:
A: You can work directly with internal dataset data storage. It is accessible through TADDataSet.Table property. For example, to delete row with index 3 do the following:
ADQuery1.Table.Rows[3].Free; ADQuery1.UpdateCursorPos; ADQuery1.Resync([]);
For example, to delete the current record do the following:
ADQuery1.UpdateCursorPos; ADQuery1.GetRow.Free; ADQuery1.UpdateCursorPos; ADQuery1.Resync([]);
And finally you can use CachedUpdates mode. Set a dataset to the cached updates mode. Then delete a record and call CommitUpdates.
A: Use the TADDataSet.CopyDataSet method with the following options:
A: Use the following code:
(AMemTable.FieldByName('Field1') as TGUIDField).AsGuid := aGUID;
A: Assign an expression to the TField.DefaultExpression property.
Yes, if a field is a normal resultset field. If a field is fkInternalCalc one, then the result of the DefaultExpression will be used as a field value. And it will be updated like any other calculated fields.
A: No, you are using AnyDAC escape functions. They are supported only in the SQL commands, not in expressions. In expressions, like constraints and default value expressions, you should use functions and syntax, supported by AnyDAC expression evaluator:
DAYOFMONTH(CURDATE())
Also, to use such functions, you should include uADStanExprFuncs unit into your application.
A: To specify a default value for a dataset field, assign required expression to the TField.DefaultValue property.
To assign default value to a boolean field, you can use one of the following strings - F, FA, FAL, FALS, FALSE as False names. And similar for True.
Q: Appending constraint via:
ADQuery.FieldByName('FIELD_NAME').CustomConstraint := 'FIELD_NAME > 1';
ADQuery.UpdateConstraints;
ADQuery.Table.Constraints.Check(ADQuery.GetRow(), rsModified, ctAtEditEnd);
It's not working - exception is not raised...
A: That is OK (explanation will be later).
Q: But:
ADQuery.Constraints.Add.CustomConstraint := 'FIELD_NAME > 1'; ADQuery.UpdateConstraints; ADQuery.Table.Constraints.Check(ADQuery.GetRow(), rsModified, ctAtEditEnd);
It's working! Why?
A: Also OK.
Q: What exactly mean ctAtEditEnd and ctAtColumnChange?
A: These enums are specifying the event, when AnyDAC should check constraints:
Now explanation:
ADQuery.FieldByName('FIELD_NAME').CustomConstraint := 'FIELD_NAME > 1';
This is adding a field-level constraint. They are checked at ctAtColumnChange event only.
ADQuery.Constraints.Add.CustomConstraint := 'FIELD_NAME > 1';
This is adding a record-level constraint. They are checked at ctAtEditEnd event only.
|
What do you think about this topic? Send feedback!
|