示例#1
0
  /** @throws Exception */
  @Test
  public void testSpecialExpression() throws Exception {
    IComputedColumn cc = new ComputedColumn("AMOUNT2", "row.AMOUNT*2");
    this.dataSet.addComputedColumn(cc);

    QueryDefinition queryDefn = newReportQuery();

    // column mapping
    String[] name = new String[] {"testColumn1"};
    ScriptExpression[] se = new ScriptExpression[name.length];
    se[0] = new ScriptExpression("if ( 2<1 ){ true;  }else{ false;}");

    SortDefinition[] sortDefn = new SortDefinition[] {new SortDefinition()};
    sortDefn[0].setExpression("row.testColumn1");
    sortDefn[0].setSortDirection(ISortDefinition.SORT_DESC);

    for (int i = 0; i < name.length; i++) queryDefn.addBinding(new Binding(name[i], se[i]));
    for (int i = 0; i < sortDefn.length; i++) {
      queryDefn.addSort(sortDefn[i]);
    }

    IResultIterator ri = executeQuery(queryDefn);
    while (ri.next()) {
      String str = "";
      for (int i = 0; i < name.length; i++) {
        str += ri.getValue(name[i]);

        if (i < name.length - 1) str += ", ";
      }
      testPrintln(str);
    }

    checkOutputFile();
  }
示例#2
0
  /** @throws Exception */
  private void testInvalidSort(int sortIndex) throws Exception {
    QueryDefinition queryDefn = newReportQuery();
    // column mapping
    String[] name = new String[] {"rownum1", "rownum2", "rownum3"};

    ScriptExpression[] se = new ScriptExpression[name.length];
    se[0] = new ScriptExpression("row.__rownum");
    se[1] = new ScriptExpression("row.rownum1");
    se[2] = new ScriptExpression("row[\"rownum2\"]");

    for (int i = 0; i < name.length; i++) queryDefn.addBinding(new Binding(name[i], se[i]));

    SortDefinition[] sort = new SortDefinition[name.length + 1];
    sort[0] = new SortDefinition();
    sort[0].setExpression("row.rownum1");
    sort[1] = new SortDefinition();
    sort[1].setExpression("row.rownum2");
    sort[2] = new SortDefinition();
    sort[2].setExpression("row.rownum3");
    sort[3] = new SortDefinition();
    sort[3].setExpression("row.__rownum");

    queryDefn.addSort(sort[sortIndex]);

    try {
      executeQuery(queryDefn);
      fail("Should not arrive here");
    } catch (DataException e) {
    }
  }
 public static void addParameterSortBy(
     QueryDefinition queryDefn, AbstractScalarParameterHandle parameter, IModelAdapter adapter) {
   String sortBy = parameter.getSortByColumn();
   if (sortBy != null) {
     String sortDirection = parameter.getSortDirection();
     if (sortDirection != null) {
       org.eclipse.birt.report.model.api.Expression mexpr =
           (org.eclipse.birt.report.model.api.Expression)
               parameter
                   .getExpressionProperty(AbstractScalarParameter.SORT_BY_COLUMN_PROP)
                   .getValue();
       ScriptExpression dexpr = adapter.adaptExpression(mexpr);
       SortDefinition sort = new SortDefinition();
       sort.setExpression(dexpr);
       boolean direction =
           DesignChoiceConstants.SORT_DIRECTION_ASC.equalsIgnoreCase(sortDirection);
       sort.setSortDirection(direction ? ISortDefinition.SORT_ASC : ISortDefinition.SORT_DESC);
       queryDefn.addSort(sort);
     }
   }
 }