internalInitFieldDefs method

  1. @override
void internalInitFieldDefs()
override

Implementation

@override
void internalInitFieldDefs() {
  if (_loadingFieldDefs) return;
  _loadingFieldDefs = true;
  try {
    fieldDefs.clear();
    sqlConnection!.addFieldDefs(cursor!, fieldDefs);
// aa ??? issue
    // When a query returns zero rows, the backend (gateway) doesn't return field metadata, so fieldDefs ends up
    // empty → bindFields afterward can't match a persistent field (az…), throwing
    // "Field not found: az" and crashing (symptom: a query with no data crashes).
    // Here, fieldDefs is inferred backward from the "already-defined persistent fields": an empty set never
    // actually reads values anyway — what matters is that the field "exists". lookup / calculated fields aren't physical
    // fields, so they aren't put into fieldDefs.
    if (fieldDefs.count == 0 && fields.count > 0) {
      for (var i = 0; i < fields.count; i++) {
        final f = fields[i];
        if (f.fieldKind != TFieldKind.fkData) continue;
        fieldDefs.addField(f.fieldName, f.dataType, f.size, f.required);
      }
    }
// zz ??? issue
  } finally {
    _loadingFieldDefs = false;
    if (cursor != null) cursor!.fInitFieldDef = false;
  }
}