@Override
  public void printSQLSelectStatement(
      DatabaseCall call, ExpressionSQLPrinter printer, SQLSelectStatement statement) {
    int max = 0;
    int firstRow = 0;
    ReadQuery query = statement.getQuery();
    if (query != null) {
      max = query.getMaxRows();
      firstRow = query.getFirstResult();
    }

    if (max <= 0 && firstRow <= 0) {
      // neither max nor firstRow is set
      super.printSQLSelectStatement(call, printer, statement);
      return;
    }
    if (max <= 0) {
      // if max row is not set use MAX_VALUE instead
      // this is done, because NewDB does not allow
      // OFFSET without LIMIT, and scrollable cursor is not supported
      // in order to support firstRows without MaxRows also MaxRow has to be set
      // this limits also the size of the result set in this case to Integer.MAX_VALUE rows
      query.setMaxRows(Integer.MAX_VALUE);
    }
    statement.setUseUniqueFieldAliases(true);
    call.setFields(statement.printSQL(printer));
    printer.printString(" LIMIT ");
    printer.printParameter(DatabaseCall.MAXROW_FIELD);
    printer.printString(" OFFSET ");
    printer.printParameter(DatabaseCall.FIRSTRESULT_FIELD);
    call.setIgnoreFirstRowSetting(true);
    call.setIgnoreMaxResultsSetting(true);
  }