getWhereFromCommand method

SqlRequest getWhereFromCommand(
  1. ClauseSuper clause, {
  2. SqlRequest sqlRequest = const SqlRequest("", {}),
  3. bool isSubCmd = false,
})

generate 'where' clause

Implementation

SqlRequest getWhereFromCommand(
  ClauseSuper clause, {
  SqlRequest sqlRequest = const SqlRequest("", {}),
  bool isSubCmd = false,
}) {
  if (clause.sql != null) {
    sqlRequest = sqlRequest.appendSql(" ${clause.sql} ");
  }

  var cmds = <Command>[];
  cmds.addIfNotNull(clause.cmd1);
  cmds.addIfNotNull(clause.cmd2);
  cmds.addIfNotNull(clause.cmd3);

  if (cmds.length > 0) //
    sqlRequest = sqlRequest.appendSql("(");

  if (clause.bracketOrFilter is Brackets) {
    sqlRequest = sqlRequest.append(getWhereFromCommand((clause.bracketOrFilter as Brackets), isSubCmd: true));
  } else if (clause.bracketOrFilter is Filter) {
    var filter = clause.bracketOrFilter as Filter;
    if (filter is FilterOneValue) {
      var subValue = this.getNextSubstitutionValue();
      sqlRequest = sqlRequest.append(
        SqlRequest("${filter.column.name}${filter.filterOperator}@where$subValue", {"where$subValue": filter.data}),
      );
    }
  }

  if (cmds.length > 0) {
    for (var cmd in cmds) {
      sqlRequest = sqlRequest.append(getWhereFromCommand(cmd, isSubCmd: true));
    }
    sqlRequest = sqlRequest.appendSql(")");
  }

  return sqlRequest;
}