Package org.apache.derby.iapi.types

Examples of org.apache.derby.iapi.types.TypeId


      for (int index = 1; index <= numColumns; index++)
      {
        boolean nullableResult =
          (rsmd.isNullable(index) != ResultSetMetaData.columnNoNulls);

        TypeId cti;

        int jdbcColumnType = rsmd.getColumnType(index);

        switch (jdbcColumnType) {
        case Types.JAVA_OBJECT:
        case Types.OTHER:
        {
          cti = TypeId.getUserDefinedTypeId(rsmd.getColumnTypeName(index), false);
          break;
        }
        default:
        {
          cti = TypeId.getBuiltInTypeId(jdbcColumnType);
          break;
        }
        }

        // Handle the case where a VTI returns a bad column type
        if (cti == null)
        {
          throw StandardException.newException(SQLState.LANG_BAD_J_D_B_C_TYPE_INFO, Integer.toString(index));
        }

        // Get the maximum byte storage for this column
        int maxWidth;

        /* Get maximum byte storage from rsmd for variable
         * width types, set it to MAXINT for the long types,
         * otherwise get it from the TypeId
         */
        if (cti.variableLength())
        {
          maxWidth = rsmd.getColumnDisplaySize(index);
        }
        else if (jdbcColumnType == Types.LONGVARCHAR ||
             jdbcColumnType == Types.LONGVARBINARY)
        {
          maxWidth = Integer.MAX_VALUE;
        }
        else
        {
          maxWidth = 0;
        }

        int precision = cti.isDecimalTypeId() ? rsmd.getPrecision(index) : 0;
        int scale = cti.isDecimalTypeId() ? rsmd.getScale(index) : 0;
        DataTypeDescriptor dts = new DataTypeDescriptor(cti,
                      precision,
                      scale,
                      nullableResult,
                      maxWidth);
View Full Code Here


  public ValueNode bindExpression(
    FromList  fromList, SubqueryList subqueryList,
    Vector  aggregateVector)
      throws StandardException
  {
    TypeId  operandType;

    super.bindExpression(fromList, subqueryList,
        aggregateVector);

    /*
    ** Check the type of the operand - this function is allowed only on
    ** string value (char and bit) types.
    */
    operandType = operand.getTypeId();

    switch (operandType.getJDBCTypeId())
    {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.CLOB:
          break;
        case org.apache.derby.iapi.reference.JDBC20Translation.SQL_TYPES_JAVA_OBJECT:
        case Types.OTHER: 
        {
          throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE,
                    methodName,
                    operandType.getSQLTypeName());
        }

        default:
          operand =  (ValueNode)
            getNodeFactory().getNode(
View Full Code Here

    {
      bindSQRTABS();
    }
    else if (operatorType == UNARY_PLUS || operatorType == UNARY_MINUS)
    {
      TypeId operandType = operand.getTypeId();

      if ( ! operandType.isNumericTypeId())
      {
     
        throw StandardException.newException(SQLState.LANG_UNARY_ARITHMETIC_BAD_TYPE,
          (operatorType == UNARY_PLUS) ? "+" : "-",
          operandType.getSQLTypeName());
      }
    }
    /*
    ** The result type of a +, -, SQRT, ABS is the same as its operand.
    */
 
View Full Code Here

   * @exception StandardException    Thrown on error
   */
  private void bindSQRTABS()
      throws StandardException
  {
    TypeId  operandType;
    int   jdbcType;

    /*
    ** Check the type of the operand
    */
    operandType = operand.getTypeId();

    /*
      * If the operand is not a build-in type, generate a bound conversion
     * tree to build-in types.
     */
    if (operandType.userType() )
    {
      operand = operand.genSQLJavaSQLTree();
    }
    /* DB2 doesn't cast string types to numeric types for numeric functions  */

    jdbcType = operandType.getJDBCTypeId();

    /* Both SQRT and ABS are only allowed on numeric types */
    if (!operandType.isNumericTypeId())
      throw StandardException.newException(
            SQLState.LANG_UNARY_FUNCTION_BAD_TYPE,
            getOperatorString(), operandType.getSQLTypeName());

    /* For SQRT, if operand is not a DOUBLE, convert it to DOUBLE */
    if (operatorType == SQRT && jdbcType != Types.DOUBLE)
    {
      operand = (ValueNode) getNodeFactory().getNode(
View Full Code Here

      throws StandardException
  {
        ValueNode boundExpression = super.bindExpression( fromList, subqueryList, aggregateVector);

        // This operator is not allowed on XML types.
        TypeId operandType = operand.getTypeId();
        if (operandType.isXMLTypeId()) {
            throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE,
                                    getOperatorString(),
                                    operandType.getSQLTypeName());
        }

        setType( new DataTypeDescriptor( TypeId.getBuiltInTypeId( Types.INTEGER),
                                         operand.getTypeServices().isNullable()));
        return boundExpression;
View Full Code Here

    if (castTarget == null)   //CHAR or VARCHAR function without specifying target length
    {
      DataTypeDescriptor opndType = castOperand.getTypeServices();
      int length = -1;
      TypeId srcTypeId = opndType.getTypeId();
      if (opndType != null)
      {
        if (srcTypeId.isNumericTypeId())
        {
          length = opndType.getPrecision() + 1; // 1 for the sign
          if (opndType.getScale() > 0)
            length += 1;               // 1 for the decimal .
        
        }
        else
        {
          TypeId typeid = opndType.getTypeId();
          if (length < 0)
            length = DataTypeUtilities.getColumnDisplaySize(typeid.getJDBCTypeId(),-1);

        }
      }
      if (length < 0)
        length = 1// same default as in parser
View Full Code Here

   *
   */
  public void compatible(ValueNode leftOperand) throws StandardException
  {
    int       size = size();
    TypeId  leftType;
    ValueNode    valueNode;
    TypeCompiler leftTC;

    leftType = leftOperand.getTypeId();
    leftTC = leftOperand.getTypeCompiler();

    for (int index = 0; index < size; index++)
    {
      valueNode = (ValueNode) elementAt(index);
      if (valueNode.requiresTypeFromContext())
        continue;


      /*
      ** Are the types compatible to each other?  If not, throw an exception.
      */
      if (! leftTC.compatible(valueNode.getTypeId()))
      {
        throw StandardException.newException(SQLState.LANG_DB2_COALESCE_DATATYPE_MISMATCH,
            leftType.getSQLTypeName(),
            valueNode.getTypeId().getSQLTypeName()
            );
      }
    }
  }
View Full Code Here

   * @exception StandardException    Thrown on error
   */
  public void comparable(ValueNode leftOperand) throws StandardException
  {
    int       size = size();
    TypeId  leftType;
    ValueNode    valueNode;
    TypeCompiler leftTC;

    leftType = leftOperand.getTypeId();
    leftTC = leftOperand.getTypeCompiler();

    for (int index = 0; index < size; index++)
    {
      valueNode = (ValueNode) elementAt(index);

      /*
      ** Can the types be compared to each other?  If not, throw an
      ** exception.
      */
      if (! leftTC.comparable(valueNode.getTypeId(),
                  false,
                  getClassFactory()))
      {
        throw StandardException.newException(SQLState.LANG_NOT_COMPARABLE,
            leftType.getSQLTypeName(),
            valueNode.getTypeId().getSQLTypeName()
            );
      }
    }
  }
View Full Code Here

    {
      /* When sorting or choosing min/max in the list, if types are not an exact
       * match, we use the left operand's type as the "judge", assuming that they
       * are compatible, as also the case with DB2.
       */
      TypeId judgeTypeId = leftOperand.getTypeServices().getTypeId();
      DataValueDescriptor judgeODV = null//no judge, no argument
      if (! rightOperandList.allSamePrecendence(judgeTypeId.typePrecedence()))
        judgeODV = (DataValueDescriptor) judgeTypeId.getNull();

      //Sort the list in ascending order
      rightOperandList.sortInAscendingOrder(judgeODV);
      isOrdered = true;

View Full Code Here

      /*
      ** MIN and MAX may return null
      */
    DataTypeDescriptor dts = new DataTypeDescriptor((DataTypeDescriptor) inputType, true);
    TypeId compType = dts.getTypeId();

    /*
    ** If the class implements NumberDataValue, then we
    ** are in business.  Return type is same as input
    ** type.
    */
    if (compType.orderable(
            lcc.getLanguageConnectionFactory().getClassFactory()))
    {
      aggregatorClass.append(ClassName.MaxMinAggregator);
     
      return dts;
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.types.TypeId

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.