addSelectStatement method

void addSelectStatement(
  1. BaseSelectStatement<BaseSelectStatement, dynamic> select
)

Implementation

void addSelectStatement(BaseSelectStatement select) {
  final isRoot = statement.buffer.isEmpty;
  if (isRoot) {
    statement.isReadOnly = true;
    statement.resultSetStructure = select.structure;
  }

  statement.buffer.write('SELECT ');
  if (select.distinct) {
    statement.buffer.write('DISTINCT ');
  }

  statement.hasMultipleTables |= select.fromClause.elements.length > 1;

  if (!_ignoreResultSet) {
    addResultSetExpressions(select.structure);
  } else {
    statement.buffer.write('1');
  }

  _ignoreResultSet = false;

  select.fromClause.compileWith(this);

  if (select.whereClause case final where?) {
    statement.space();
    where.compileWith(this);
  }

  if (select.groupByClause case final groupBy?) {
    statement.space();
    groupBy.compileWith(this);
  }

  for (final compound in select.compounds) {
    compound.compileWith(this);
  }

  if (select.orderByClause case final orderBy?) {
    statement.space();
    orderBy.compileWith(this);
  }

  if (select.limitClause case final limit?) {
    statement.space();
    limit.compileWith(this);
  }

  if (isRoot) {
    statement.semicolon();
  }
}