@Override protected String prettyPrintSingleArg( SQLSkin skin, OperatorDefinition opDef, OperatorPiece piece, String[] args) throws RenderingException { String txt = "CAST("; txt += args[0] + " AS "; if (CastOperatorDefinition.TO_TIMESTAMP.equals(opDef.getExtendedID())) { txt += "DATETIME)"; } else if (CastOperatorDefinition.TO_DATE.equals(opDef.getExtendedID())) { txt += "DATE)"; } else if (CastOperatorDefinition.TO_CHAR.equals(opDef.getExtendedID())) { // length is optional on mysql txt = "CHAR("; txt += ((CastOperatorDefinition) opDef).getPieceLength(getExtendedPieces(piece)) + "))"; } else if (CastOperatorDefinition.TO_NUMBER.equals(opDef.getExtendedID())) { if (args.length == 1) { // txt = "(" + args[0] + " + 0.0)"; txt += "DECIMAL(65,30))"; } else if (args.length == 3) { txt += "DECIMAL(" + args[1] + "," + args[2] + "))"; } } else if (CastOperatorDefinition.TO_INTEGER.equals(opDef.getExtendedID())) { txt += "SIGNED)"; } return txt; }
@Override public String prettyPrintTwoArgs( SQLSkin skin, OperatorPiece piece, OperatorDefinition opDef, String[] args) throws RenderingException { ExtendedType[] types = getExtendedPieces(piece); if (CastOperatorDefinition.TO_CHAR.equals(opDef.getExtendedID())) { if (types[0].getDomain().isInstanceOf(IDomain.TEMPORAL)) { return "CAST(DATE_FORMAT(" + args[0] + "," + formatMapping(args[1]) + ") AS CHAR)"; } else { return super.prettyPrintTwoArgs(skin, piece, opDef, args); } } else if (CastOperatorDefinition.TO_DATE.equals(opDef.getExtendedID()) || CastOperatorDefinition.TO_DATE.equals(opDef.getExtendedID())) { if (types[0].getDomain().isInstanceOf(IDomain.STRING)) { return "STR_TO_DATE(" + args[0] + "," + formatMapping(args[1]) + ")"; } else { return "DATE_FORMAT(" + args[0] + "," + formatMapping(args[1]) + ")"; } } else { return super.prettyPrintTwoArgs(skin, piece, opDef, args); } }