internalOpen method

  1. @override
void internalOpen()
override

Implementation

@override
void internalOpen() {
  if (isReadFromPacket()) {
    // When we read from file there is no need for Cursor, also note
    // that Database may not be assigned (original comment kept as-is)
    //FStatement.AllocateCursor;
    //Cursor.FSelectable:=True;
    //Cursor.FStatementType:=stSelect;
    _updateable = true;
  } else {
    checkPrepare();
    if (!cursor!.fSelectable) {
      databaseError(SErrNoSelectStatement, this);
    }

    // Call UpdateServerIndexDefs before Execute, to avoid problems
    // with connections which do not allow processing multiple
    // recordsets at a time. (Microsoft calls this MARS, see bug
    // 13241) (original comment kept as-is)
    if (defaultFields &&
        _updateable &&
        _usePrimaryKeyAsKey &&
        !isUniDirectional) {
      updateServerIndexDefs();
    }

    _statement.execute();
    if (cursor == null || !cursor!.fSelectable) {
      databaseError(SErrNoSelectStatement, this);
    }

    // InternalInitFieldDef is only called after a prepare. i.e. not
    // twice if a dataset is opened - closed - opened. (original comment kept as-is)
    if (cursor!.fInitFieldDef) {
      internalInitFieldDefs();
    }
    if (defaultFields) {
      createFields();

      if (_updateable && _usePrimaryKeyAsKey && !isUniDirectional) {
        for (var counter = 0;
            counter < serverIndexDefs.count;
            counter++) {
          if (serverIndexDefs[counter]
              .options
              .contains(TIndexOption.ixPrimary)) {
            // ExtractStrings([';'],[' '],...) (original semantics: split on ; and
            // trim whitespace)
            final indexFields = serverIndexDefs[counter]
                .fields
                .split(";")
                .map((s) => s.trim())
                .where((s) => s.isNotEmpty)
                .toList();
            for (var fieldc = 0; fieldc < indexFields.length; fieldc++) {
              final f = findField(indexFields[fieldc]);
              if (f != null) {
                f.providerFlags = {
                  ...f.providerFlags,
                  TProviderFlag.pfInKey
                };
              }
            }
          }
        }
      }
    }
  }
  bindFields(true);

  if (!readOnly && !_updateable && _schemaType == TSchemaType.stNoSchema) {
    if (_deleteSQL.text.trim() != '' ||
        _updateSQL.text.trim() != '' ||
        _insertSQL.text.trim() != '') {
      _updateable = true;
    }
  }

// aa ### flutter extension
  // Applies the alwaysUpdateable set before opening, here (after the updateable determination completes).
  if (_alwaysUpdateable) _updateable = true;
// zz ### flutter extension

  super.internalOpen();
}