1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 27 28 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 29 import org.apache.derby.iapi.types.TypeId; 30 import org.apache.derby.iapi.types.DataTypeDescriptor; 31 import org.apache.derby.iapi.types.ConcatableDataValue; 32 import org.apache.derby.iapi.sql.compile.TypeCompiler; 33 import org.apache.derby.iapi.reference.SQLState; 34 import org.apache.derby.iapi.error.StandardException; 35 import org.apache.derby.iapi.reference.ClassName; 36 import org.apache.derby.iapi.reference.JDBC20Translation; 37 38 import java.sql.Types ; 39 40 import java.util.Vector ; 41 42 47 48 public final class LengthOperatorNode extends UnaryOperatorNode 49 { 50 private int parameterType; 51 private int parameterWidth; 52 53 public void setNodeType(int nodeType) 54 { 55 String operator = null; 56 String methodName = null; 57 58 if (nodeType == C_NodeTypes.CHAR_LENGTH_OPERATOR_NODE) 59 { 60 operator = "char_length"; 61 methodName = "charLength"; 62 parameterType = Types.VARCHAR; 63 parameterWidth = TypeId.VARCHAR_MAXWIDTH; 64 } 65 else 66 { 67 if (SanityManager.DEBUG) 68 { 69 SanityManager.THROWASSERT( 70 "Unexpected nodeType = " + nodeType); 71 } 72 } 73 setOperator(operator); 74 setMethodName(methodName); 75 super.setNodeType(nodeType); 76 } 77 78 89 90 public ValueNode bindExpression( 91 FromList fromList, SubqueryList subqueryList, 92 Vector aggregateVector) 93 throws StandardException 94 { 95 TypeId operandType; 96 97 super.bindExpression(fromList, subqueryList, 98 aggregateVector); 99 100 104 operandType = operand.getTypeId(); 105 switch (operandType.getJDBCTypeId()) 106 { 107 case Types.CHAR: 108 case Types.VARCHAR: 109 case Types.BINARY: 110 case Types.VARBINARY: 111 case Types.LONGVARBINARY: 112 case Types.LONGVARCHAR: 113 case JDBC20Translation.SQL_TYPES_BLOB: 114 case JDBC20Translation.SQL_TYPES_CLOB: 115 break; 116 117 default: 118 throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE, 119 getOperatorString(), 120 operandType.getSQLTypeName()); 121 } 122 123 126 setType(new DataTypeDescriptor( 127 TypeId.INTEGER_ID, 128 operand.getTypeServices().isNullable() 129 ) 130 ); 131 return this; 132 } 133 134 139 140 void bindParameter() 141 throws StandardException 142 { 143 148 149 operand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(parameterType, true, 150 parameterWidth)); 151 } 152 153 157 public String getReceiverInterfaceName() { 158 return ClassName.ConcatableDataValue; 159 } 160 } 161 | Popular Tags |