getFieldDataNative method
Implementation
@override
bool getFieldDataNative(TField field, TValueBuffer? buffer) {
final TRecordBuffer? rec;
switch (state) {
case TDataSetState.dsCalcFields:
rec = calcBuffer;
break;
case TDataSetState.dsOldValue:
// @@@ fix: while applyRecUpdate() is running (_applyingUpdate is
// non-null), _applyingUpdate.oldValues must be read first -- that's
// the "real" old-value snapshot for this pending update
// (internalDelete()/internalPost() both correctly save it, and
// applyUpdates()'s loop has already assigned it to
// _applyingUpdate). The old code only recognized _oldValueBuffer
// (only internalEdit() sets it, and internalPost() clears it to
// null once used) or fell back to activeBuffer() (whatever record
// the cursor currently points at) -- after a DELETE removes a
// record from _records, the resulting array shift means the next
// record ends up at that cursor position; and even for a MODIFY,
// _oldValueBuffer has usually already been cleared by
// internalPost() by this point. Either way, this read the old
// values of "whatever record the cursor currently points at"
// instead of "the record actually being updated", so the WHERE
// clause built from it targeted the wrong record (e.g. deleting
// the next record instead).
if (_applyingUpdate != null) {
rec = TRecordBuffer()..fieldData.addAll(_applyingUpdate!.oldValues);
} else {
rec = _oldValueBuffer ?? activeBuffer();
}
break;
default:
rec = activeBuffer();
}
if (rec == null) return false;
final key = field.fieldName.toUpperCase();
final dynamic v;
if (field.fieldKind == TFieldKind.fkCalculated ||
field.fieldKind == TFieldKind.fkLookup) {
if (!rec.calcData.containsKey(key)) return false;
v = rec.calcData[key];
} else {
if (!rec.fieldData.containsKey(key)) return false;
v = rec.fieldData[key];
}
if (v == null) return false;
if (buffer != null) buffer.value = v;
return true;
}