Result getResult(Session session) {

    switch (type) {
      case StatementTypes.SIGNAL:
      case StatementTypes.RESIGNAL:

        // todo
      case StatementTypes.ITERATE:
      case StatementTypes.LEAVE:
      case StatementTypes.RETURN:
      case StatementTypes.CONDITION:
        return this.getResultValue(session);

      case StatementTypes.ASSIGNMENT:
        {
          Object[] variables =
              variable.getType() == SchemaObject.PARAMETER
                  ? session.sessionContext.routineArguments
                  : session.sessionContext.routineVariables;

          try {
            Object o = expression.getValue(session, variable.getDataType());

            variables[variableIndex] = o;

            return Result.updateZeroResult;
          } catch (HsqlException e) {
            return Result.newErrorResult(e);
          }
        }
      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "");
    }
  }
  protected void addTableColumns(Expression expression, int start, int count, HashSet exclude) {

    Table table = getTable();
    HsqlArrayList list = new HsqlArrayList();

    for (int i = start; i < start + count; i++) {
      ColumnSchema column = table.getColumn(i);
      String columnName =
          columnAliases == null ? column.getName().name : (String) columnAliases.get(i);

      if (exclude != null && exclude.contains(columnName)) {
        continue;
      }

      Expression e = new ExpressionColumn(this, i);

      list.add(e);
    }

    Expression[] nodes = new Expression[list.size()];

    list.toArray(nodes);

    expression.nodes = nodes;
  }
  void collectObjectNames(Set set) {

    switch (opType) {
      case OpTypes.SEQUENCE:
        HsqlName name = sequence.getName();

        set.add(name);

        return;

      case OpTypes.MULTICOLUMN:
      case OpTypes.DYNAMIC_PARAM:
      case OpTypes.ASTERISK:
      case OpTypes.SIMPLE_COLUMN:
      case OpTypes.COALESCE:
        break;

      case OpTypes.PARAMETER:
      case OpTypes.VARIABLE:
        break;

      case OpTypes.COLUMN:
        set.add(column.getName());

        if (column.getName().parent != null) {
          set.add(column.getName().parent);
        }

        return;
    }
  }
  ExpressionColumn(ColumnSchema column) {

    super(OpTypes.COLUMN);

    this.column = column;
    this.dataType = column.getDataType();
    columnName = column.getName().name;
  }
Exemplo n.º 5
0
  public void addSessionVariable(ColumnSchema variable) {

    int index = sessionVariables.size();

    if (!sessionVariables.add(variable.getName().name, variable)) {
      throw Error.error(ErrorCode.X_42504);
    }

    Object[] vars = new Object[sessionVariables.size()];

    ArrayUtil.copyArray(routineVariables, vars, routineVariables.length);

    routineVariables = vars;
    routineVariables[index] = variable.getDefaultValue(session);
  }
  String getColumnName() {

    if (opType == OpTypes.COLUMN && column != null) {
      return column.getName().name;
    }

    return getAlias();
  }
  void setAutoAttributesAsColumn(RangeVariable range, int i) {

    columnIndex = i;
    column = range.getColumn(i);
    dataType = column.getDataType();
    columnName = range.getColumnAlias(i).name;
    tableName = range.getTableAlias().name;
    rangeVariable = range;

    rangeVariable.addColumn(columnIndex);
  }
  void setAttributesAsColumn(RangeVariable range, int i) {

    columnIndex = i;
    column = range.getColumn(i);
    dataType = column.getDataType();
    rangeVariable = range;

    if (range.rangeType == RangeVariable.TABLE_RANGE) {
      rangeVariable.addColumn(columnIndex);
    }
  }
  /** Add all columns to a list of expressions */
  public int addTableColumns(HsqlArrayList exprList, int position, HashSet exclude) {

    Table table = getTable();
    int count = table.getColumnCount();

    for (int i = 0; i < count; i++) {
      ColumnSchema column = table.getColumn(i);
      String columnName =
          columnAliases == null ? column.getName().name : (String) columnAliases.get(i);

      if (exclude != null && exclude.contains(columnName)) {
        continue;
      }

      Expression e = new ExpressionColumn(this, i);

      exprList.add(position++, e);
    }

    return position;
  }
Exemplo n.º 10
0
 void checkCheckConstraint(
     Session paramSession, Table paramTable, ColumnSchema paramColumnSchema, Object paramObject) {
   paramSession.sessionData.currentValue = paramObject;
   boolean bool = Boolean.FALSE.equals(this.check.getValue(paramSession));
   paramSession.sessionData.currentValue = null;
   if (bool) {
     String[] arrayOfString = {
       this.name.statementName,
       paramTable == null ? "" : paramTable.getName().statementName,
       paramColumnSchema == null ? "" : paramColumnSchema.getName().statementName
     };
     throw Error.error(null, 157, 3, arrayOfString);
   }
 }
Exemplo n.º 11
0
  public byte getNullability() {

    switch (opType) {
      case OpTypes.COLUMN:
        return column.getNullability();

      case OpTypes.SEQUENCE:
      case OpTypes.COALESCE:
      case OpTypes.ROWNUM:
        return SchemaObject.Nullability.NO_NULLS;

      default:
        return SchemaObject.Nullability.NULLABLE_UNKNOWN;
    }
  }
  SimpleName getSimpleName() {

    if (alias != null) {
      return alias;
    }

    if (column != null) {
      return column.getName();
    }

    if (opType == OpTypes.COALESCE) {
      return nodes[LEFT].getSimpleName();
    }

    return null;
  }
  public String getSQL() {

    StringBuffer sb = new StringBuffer();

    switch (type) {
      case StatementTypes.SIGNAL:
        sb.append(Tokens.T_SIGNAL);
        break;

      case StatementTypes.RESIGNAL:
        sb.append(Tokens.T_RESIGNAL);
        break;

        // todo
      case StatementTypes.ITERATE:
        sb.append(Tokens.T_ITERATE).append(' ').append(label);
        break;

      case StatementTypes.LEAVE:
        sb.append(Tokens.T_LEAVE).append(' ').append(label);
        break;

      case StatementTypes.RETURN:
        /*
                        sb.append(Tokens.T_RETURN);

                        if (expression != null) {
                            sb.append(' ').append(expression.getSQL());
                        }
                        break;
        */
        return sql;

      case StatementTypes.CONDITION:
        sb.append(expression.getSQL());
        break;

      case StatementTypes.ASSIGNMENT:
        sb.append(Tokens.T_SET).append(' ');
        sb.append(variable.getName().statementName).append(' ');
        sb.append('=').append(' ').append(expression.getSQL());
        break;
    }

    return sb.toString();
  }
Exemplo n.º 14
0
  SimpleName getSimpleName() {

    if (alias != null) {
      return alias;
    }

    if (rangeVariable != null && rangeVariable.hasColumnAlias()) {
      return rangeVariable.getColumnAlias(columnIndex);
    }

    if (column != null) {
      return column.getName();
    }

    if (opType == OpTypes.COALESCE) {
      return nodes[LEFT].getSimpleName();
    } else if (opType == OpTypes.ROWNUM) {
      return rownumName;
    }

    return null;
  }
Exemplo n.º 15
0
  protected String describe(Session session, int blanks) {

    StringBuffer sb = new StringBuffer(64);

    sb.append('\n');

    for (int i = 0; i < blanks; i++) {
      sb.append(' ');
    }

    switch (opType) {
      case OpTypes.DEFAULT:
        sb.append(Tokens.T_DEFAULT);
        break;

      case OpTypes.ASTERISK:
        sb.append("OpTypes.ASTERISK ");
        break;

      case OpTypes.VARIABLE:
        sb.append("VARIABLE: ");
        sb.append(column.getName().name);
        break;

      case OpTypes.PARAMETER:
        sb.append(Tokens.T_PARAMETER).append(": ");
        sb.append(column.getName().name);
        break;

      case OpTypes.COALESCE:
        sb.append(Tokens.T_COLUMN).append(": ");
        sb.append(columnName);

        if (alias != null) {
          sb.append(" AS ").append(alias.name);
        }
        break;

      case OpTypes.COLUMN:
        sb.append(Tokens.T_COLUMN).append(": ");
        sb.append(column.getName().getSchemaQualifiedStatementName());

        if (alias != null) {
          sb.append(" AS ").append(alias.name);
        }
        break;

      case OpTypes.DYNAMIC_PARAM:
        sb.append("DYNAMIC PARAM: ");
        sb.append(", TYPE = ").append(dataType.getNameString());
        break;

      case OpTypes.SEQUENCE:
        sb.append(Tokens.T_SEQUENCE).append(": ");
        sb.append(sequence.getName().name);
        break;

      case OpTypes.MULTICOLUMN:

        // shouldn't get here
    }

    return sb.toString();
  }
Exemplo n.º 16
0
  public String getSQL() {

    switch (opType) {
      case OpTypes.DEFAULT:
        return Tokens.T_DEFAULT;

      case OpTypes.DYNAMIC_PARAM:
        return Tokens.T_QUESTION;

      case OpTypes.ASTERISK:
        return "*";

      case OpTypes.COALESCE:
        return alias.getStatementName();

      case OpTypes.DIAGNOSTICS_VARIABLE:
      case OpTypes.VARIABLE:
      case OpTypes.PARAMETER:
        return column.getName().statementName;

      case OpTypes.ROWNUM:
        {
          StringBuffer sb = new StringBuffer(Tokens.T_ROWNUM);

          sb.append('(').append(')');
        }
      case OpTypes.COLUMN:
        {
          if (column == null) {
            if (alias != null) {
              return alias.getStatementName();
            } else {
              return columnName;
            }
          }

          if (rangeVariable.tableAlias == null) {
            return column.getName().getSchemaQualifiedStatementName();
          } else {
            StringBuffer sb = new StringBuffer();

            sb.append(rangeVariable.tableAlias.getStatementName());
            sb.append('.');
            sb.append(column.getName().statementName);

            return sb.toString();
          }
        }
      case OpTypes.MULTICOLUMN:
        {
          if (nodes.length == 0) {
            return "*";
          }

          StringBuffer sb = new StringBuffer();

          for (int i = 0; i < nodes.length; i++) {
            Expression e = nodes[i];

            if (i > 0) {
              sb.append(',');
            }

            String s = e.getSQL();

            sb.append(s);
          }

          return sb.toString();
        }
      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "ExpressionColumn");
    }
  }
Exemplo n.º 17
0
  private boolean resolveColumnReference(RangeVariable rangeVar) {

    Expression e = rangeVar.getColumnExpression(columnName);

    if (e != null) {
      opType = e.opType;
      nodes = e.nodes;
      dataType = e.dataType;

      return true;
    }

    int colIndex = rangeVar.findColumn(schema, tableName, columnName);

    if (colIndex == -1) {
      return false;
    }

    switch (rangeVar.rangeType) {
      case RangeVariable.PARAMETER_RANGE:
      case RangeVariable.VARIALBE_RANGE:
        {
          if (tableName != null) {
            return false;
          }

          ColumnSchema column = rangeVar.getColumn(colIndex);

          if (column.getParameterMode() == SchemaObject.ParameterModes.PARAM_OUT) {
            return false;
          } else {
            opType =
                rangeVar.rangeType == RangeVariable.VARIALBE_RANGE
                    ? OpTypes.VARIABLE
                    : OpTypes.PARAMETER;
          }

          break;
        }
      case RangeVariable.TRANSITION_RANGE:
        {
          if (tableName == null) {
            return false;
          }

          if (schema != null) {
            return false;
          }

          opType = OpTypes.TRANSITION_VARIABLE;

          break;
        }
      default:
        {
          break;
        }
    }

    setAttributesAsColumn(rangeVar, colIndex);

    return true;
  }
Exemplo n.º 18
0
  void setAttributesAsColumn(ColumnSchema column, boolean isWritable) {

    this.column = column;
    dataType = column.getDataType();
    this.isWritable = isWritable;
  }
Exemplo n.º 19
0
 public HsqlName getBaseColumnHsqlName() {
   return column.getName();
 }