/** * Extracts the string value from a string literal, a chain of string * literals, or a CAST of a string literal. * * @deprecated Use {@link #value(SqlNode)} */ @Deprecated // to be removed before 2.0 public static String stringValue(SqlNode node) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (SqlUtil.isLiteralChain(node)) { final SqlLiteral literal = SqlLiteralChainOperator.concatenateOperands((SqlCall) node); assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (node instanceof SqlCall && ((SqlCall) node).getOperator() == SqlStdOperatorTable.CAST) { //noinspection deprecation return stringValue(((SqlCall) node).operand(0)); } else { throw new AssertionError("invalid string literal: " + node); } }
/** * Extracts the string value from a string literal, a chain of string * literals, or a CAST of a string literal. * * @deprecated Use {@link #value(SqlNode)} */ @Deprecated // to be removed before 2.0 public static String stringValue(SqlNode node) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (SqlUtil.isLiteralChain(node)) { final SqlLiteral literal = SqlLiteralChainOperator.concatenateOperands((SqlCall) node); assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (node instanceof SqlCall && ((SqlCall) node).getOperator() == SqlStdOperatorTable.CAST) { //noinspection deprecation return stringValue(((SqlCall) node).operand(0)); } else { throw new AssertionError("invalid string literal: " + node); } }
/** * Converts a chained string literals into regular literals; returns regular * literals unchanged. * @throws IllegalArgumentException if {@code node} is not a string literal * and cannot be unchained. */ public static SqlLiteral unchain(SqlNode node) { if (node instanceof SqlLiteral) { return (SqlLiteral) node; } else if (SqlUtil.isLiteralChain(node)) { return SqlLiteralChainOperator.concatenateOperands((SqlCall) node); } else if (node instanceof SqlIntervalQualifier) { final SqlIntervalQualifier q = (SqlIntervalQualifier) node; return new SqlLiteral( new SqlIntervalLiteral.IntervalValue(q, 1, q.toString()), q.typeName(), q.pos); } else { throw new IllegalArgumentException("invalid literal: " + node); } }
/** * Converts a chained string literals into regular literals; returns regular * literals unchanged. * @throws IllegalArgumentException if {@code node} is not a string literal * and cannot be unchained. */ public static SqlLiteral unchain(SqlNode node) { if (node instanceof SqlLiteral) { return (SqlLiteral) node; } else if (SqlUtil.isLiteralChain(node)) { return SqlLiteralChainOperator.concatenateOperands((SqlCall) node); } else if (node instanceof SqlIntervalQualifier) { final SqlIntervalQualifier q = (SqlIntervalQualifier) node; return new SqlLiteral( new SqlIntervalLiteral.IntervalValue(q, 1, q.toString()), q.typeName(), q.pos); } else { throw new IllegalArgumentException("invalid literal: " + node); } }
if (SqlUtil.isLiteralChain(node)) { assert node instanceof SqlCall; final SqlLiteral literal =
if (SqlUtil.isLiteralChain(node)) { assert node instanceof SqlCall; final SqlLiteral literal =
public boolean checkSingleOperandType( SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) { Util.discard(iFormalOperand); if (SqlUtil.isNullLiteral(node, true)) { if (allowNull) { return true; } if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.getOperator().getName())); } return false; } if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustBeLiteral( callBinding.getOperator().getName())); } return false; } return true; }
public boolean checkSingleOperandType( SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) { Util.discard(iFormalOperand); if (SqlUtil.isNullLiteral(node, true)) { if (allowNull) { return true; } if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.getOperator().getName())); } return false; } if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustBeLiteral( callBinding.getOperator().getName())); } return false; } return true; }