Package railo.runtime.sql.exp

Examples of railo.runtime.sql.exp.Expression


      if(s.isDistinct()) sb.append("distinct\n\t");
      ValueNumber top = s.getTop();
      if(top!=null) sb.append("top "+top.getString()+"\n\t");
      // select
      Expression[] sels = s.getSelects();
      Expression exp;
      boolean first=true;
      for(int i=0;i<sels.length;i++) {
        if(!first)sb.append("\t,");
        exp=sels[i];
        sb.append(exp.toString(false)+"\n");
        first=false;
      }
 
      // from
      sb.append("from\n\t");
      Column[] forms = s.getFroms();
      first=true;
      for(int i=0;i<forms.length;i++) {
        if(!first)sb.append("\t,");
        exp=forms[i];
        sb.append(exp.toString(false)+"\n");
        first=false;
      }
 
      // where
      if(s.getWhere()!=null){
        sb.append("where \n\t");
        sb.append(s.getWhere().toString(true));
        sb.append("\n");
      }
 
      // group by
      Column[] gbs = s.getGroupbys();
      if(gbs.length>0) {
        sb.append("group by\n\t");
        first=true;
        for(int i=0;i<gbs.length;i++) {
          if(!first)sb.append("\t,");
          exp=gbs[i];
          sb.append(exp.toString(false)+"\n");
          first=false;
        }
      }
 
     
      // having
      Operation having = s.getHaving();
      if(having!=null){
        sb.append("having \n\t");
        sb.append(having.toString(true));
        sb.append("\n");
      }
     
    }

    // order by
    if(__selects.orderbys!=null && __selects.orderbys.size()>0) {
      sb.append("order by\n\t");
      Iterator<Column> it = __selects.orderbys.iterator();
      Expression exp;
      boolean first = true;
      while(it.hasNext()) {
        if(!first)sb.append("\t,");
        exp=it.next();
        sb.append(exp.toString(false)+" "+(exp.isDirectionBackward()?"DESC":"ASC")+"\n");
        first=false;
      }
    }
    return sb.toString();
  }
View Full Code Here


      sb.append('(');
      Iterator it = operants.iterator();
      boolean isFirst=true;
      while(it.hasNext()) {
        if(!isFirst)sb.append(',');
        Expression exp=(Expression) it.next();
        sb.append(exp.toString(!operator.equalsIgnoreCase("cast")));
        isFirst=false;
      }
      sb.append(')');
      return sb.toString();
    }
View Full Code Here

    if(!raw.isAfterLast()) throw new SQLParserException("can not read the full sql statement (stop at:"+raw.getCurrent()+")");
    return selects;
  }

  private void orderByExpressions(ParserString raw, Selects selects) throws SQLParserException {
    Expression exp=null;
    do {
      raw.removeSpace();
      //print.out(raw.getCurrent());
      exp=expression(raw);
      if(!(exp instanceof Column)) throw new SQLParserException("invalid order by part of query");
View Full Code Here

    raw.removeSpace();
  }

  private void whereExpressions(ParserString raw, Select select) throws SQLParserException {
    raw.removeSpace();
    Expression exp = expression(raw);
    if(exp==null) throw new SQLParserException("missing where expression");
    if(!(exp instanceof Operation)) throw new SQLParserException("invalid where expression ("+Caster.toClassName(exp)+")");
    select.setWhereExpression((Operation)exp);
    raw.removeSpace();
  }
View Full Code Here

    raw.removeSpace();
  }

  private void havingExpressions(ParserString raw, Select select) throws SQLParserException {
    raw.removeSpace();
    Expression exp = expression(raw);
    if(exp==null) throw new SQLParserException("missing having expression");
    if(!(exp instanceof Operation)) throw new SQLParserException("invalid having expression");
    select.setHaving((Operation)exp);
    raw.removeSpace();
  }
View Full Code Here

    select.setHaving((Operation)exp);
    raw.removeSpace();
  }

  private void groupByExpressions(ParserString raw, Select select) throws SQLParserException {
    Expression exp=null;
    do {
      raw.removeSpace();
      //print.out(raw.getCurrent());
      exp=expression(raw);
      if(!(exp instanceof Column)) throw new SQLParserException("invalid group by part of query");
View Full Code Here

    raw.removeSpace();
  }
 
  private void tableList(ParserString raw, Select select) throws SQLParserException {
    Column column=null;
    Expression exp=null;
    do {
      raw.removeSpace();
     
      exp=column(raw);
      if(!(exp instanceof Column)) throw new SQLParserException("invalid table definition");
View Full Code Here

 
  }

  // { (selectStatement) [AS] label | tableName [AS] label}
  private void selectExpressions(ParserString raw, Select select) throws SQLParserException {
    Expression exp=null;
    do {
      raw.removeSpace();
     
      exp=expression(raw);
      if(exp==null) throw new SQLParserException("missing expression in select part of query");
      raw.removeSpace();
      if(raw.forwardIfCurrent("as ")) {
        String alias=identifier(raw,new RefBooleanImpl(false));
        if(alias==null) throw new SQLParserException("missing alias in select part");
        exp.setAlias(alias);
      }
      else {
        int start=raw.getPos();
        RefBoolean hb = new RefBooleanImpl(false);
        String alias=identifier(raw,hb);
        if(!hb.toBooleanValue() && "from".equalsIgnoreCase(alias)) raw.setPos(start);
        else if(alias!=null) exp.setAlias(alias);
      }
      select.addSelectExpression(exp);
      raw.removeSpace();
    }
    while(raw.forwardIfCurrent(','));
View Full Code Here

  private Expression expression(ParserString raw) throws SQLParserException {
    return xorOp(raw);
  }
 
  private Expression xorOp(ParserString raw) throws SQLParserException {
    Expression expr = orOp(raw);
   
    while(raw.forwardIfCurrentAndNoWordNumberAfter("xor")) {
      raw.removeSpace();
          expr=new Operation2(expr, orOp(raw), Operation.OPERATION2_XOR);
    }
View Full Code Here

    }
    return expr;
  }
 
  private Expression orOp(ParserString raw) throws SQLParserException {
    Expression expr = andOp(raw);
   
    while(raw.forwardIfCurrentAndNoWordNumberAfter("or")) {
      raw.removeSpace();
          expr=new Operation2(expr, andOp(raw),Operation.OPERATION2_OR);
    }
View Full Code Here

TOP

Related Classes of railo.runtime.sql.exp.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.