/** * concat translation * * @param buf The buffer to append into * @param parsedArgs arguments */ public static void sqlconcat(StringBuilder buf, List<? extends CharSequence> parsedArgs) { appendCall(buf, "(", "||", ")", parsedArgs); }
/** * ceiling to ceil translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlceiling(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { singleArgumentFunctionCall(buf, "ceil(", "ceiling", parsedArgs); }
/** * power to pow translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlpower(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { twoArgumentsFunctionCall(buf, "pow(", "power", parsedArgs); }
private static void appendInterval(StringBuilder buf, String type, String value) throws SQLException { if (!isTsi(type)) { throw new PSQLException(GT.tr("Interval {0} not yet implemented", type), PSQLState.SYNTAX_ERROR); } if (appendSingleIntervalCast(buf, SQL_TSI_DAY, type, value, "day") || appendSingleIntervalCast(buf, SQL_TSI_SECOND, type, value, "second") || appendSingleIntervalCast(buf, SQL_TSI_HOUR, type, value, "hour") || appendSingleIntervalCast(buf, SQL_TSI_MINUTE, type, value, "minute") || appendSingleIntervalCast(buf, SQL_TSI_MONTH, type, value, "month") || appendSingleIntervalCast(buf, SQL_TSI_WEEK, type, value, "week") || appendSingleIntervalCast(buf, SQL_TSI_YEAR, type, value, "year") ) { return; } if (areSameTsi(SQL_TSI_QUARTER, type)) { buf.append("CAST((").append(value).append("::int * 3) || ' month' as interval)"); return; } throw new PSQLException(GT.tr("Interval {0} not yet implemented", type), PSQLState.NOT_IMPLEMENTED); }
private static String constantToDatePart(StringBuilder buf, String type) throws SQLException { if (!isTsi(type)) { throw new PSQLException(GT.tr("Interval {0} not yet implemented", type), PSQLState.SYNTAX_ERROR); } if (areSameTsi(SQL_TSI_DAY, type)) { return "day"; } else if (areSameTsi(SQL_TSI_SECOND, type)) { return "second"; } else if (areSameTsi(SQL_TSI_HOUR, type)) { return "hour"; } else if (areSameTsi(SQL_TSI_MINUTE, type)) { return "minute"; } else { throw new PSQLException(GT.tr("Interval {0} not yet implemented", type), PSQLState.SYNTAX_ERROR); } // See http://archives.postgresql.org/pgsql-jdbc/2006-03/msg00096.php /* * else if (SQL_TSI_MONTH.equalsIgnoreCase(shortType)) return "month"; else if * (SQL_TSI_QUARTER.equalsIgnoreCase(shortType)) return "quarter"; else if * (SQL_TSI_WEEK.equalsIgnoreCase(shortType)) return "week"; else if * (SQL_TSI_YEAR.equalsIgnoreCase(shortType)) return "year"; */ }
Method method = EscapedFunctions2.getFunction(functionName); if (method == null) { newsql.append(functionName); EscapedFunctions2.appendCall(newsql, "(", ",", ")", parsedArgs); return i;
/** * database translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqldatabase(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { zeroArgumentFunctionCall(buf, "current_database()", "database", parsedArgs); }
private static boolean appendSingleIntervalCast(StringBuilder buf, String cmp, String type, String value, String pgType) { if (!areSameTsi(type, cmp)) { return false; } buf.ensureCapacity(buf.length() + 5 + 4 + 14 + value.length() + pgType.length()); buf.append("CAST(").append(value).append("||' ").append(pgType).append("' as interval)"); return true; }
/** * time stamp add * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqltimestampadd(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { if (parsedArgs.size() != 3) { throw new PSQLException( GT.tr("{0} function takes three and only three arguments.", "timestampadd"), PSQLState.SYNTAX_ERROR); } buf.append('('); appendInterval(buf, parsedArgs.get(0).toString(), parsedArgs.get(1).toString()); buf.append('+').append(parsedArgs.get(2)).append(')'); }
/** * time stamp diff * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqltimestampdiff(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { if (parsedArgs.size() != 3) { throw new PSQLException( GT.tr("{0} function takes three and only three arguments.", "timestampdiff"), PSQLState.SYNTAX_ERROR); } buf.append("extract( ") .append(constantToDatePart(buf, parsedArgs.get(0).toString())) .append(" from (") .append(parsedArgs.get(2)) .append("-") .append(parsedArgs.get(1)) .append("))"); }
/** * curdate to current_date translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlcurdate(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { zeroArgumentFunctionCall(buf, "current_date", "curdate", parsedArgs); }
/** * dayofmonth translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqldayofmonth(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { singleArgumentFunctionCall(buf, "extract(day from ", "dayofmonth", parsedArgs); }
private static void twoArgumentsFunctionCall(StringBuilder buf, String call, String functionName, List<? extends CharSequence> parsedArgs) throws PSQLException { if (parsedArgs.size() != 2) { throw new PSQLException(GT.tr("{0} function takes two and only two arguments.", functionName), PSQLState.SYNTAX_ERROR); } appendCall(buf, call, ",", ")", parsedArgs); }
/** * user translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqluser(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { zeroArgumentFunctionCall(buf, "user", "user", parsedArgs); }
/** * truncate to trunc translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqltruncate(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { twoArgumentsFunctionCall(buf, "trunc(", "truncate", parsedArgs); }
/** * second translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlsecond(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { singleArgumentFunctionCall(buf, "extract(second from ", "second", parsedArgs); }
/** * left to substring translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlleft(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { if (parsedArgs.size() != 2) { throw new PSQLException(GT.tr("{0} function takes two and only two arguments.", "left"), PSQLState.SYNTAX_ERROR); } appendCall(buf, "substring(", " for ", ")", parsedArgs); }
/** * curtime to current_time translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlcurtime(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { zeroArgumentFunctionCall(buf, "current_time", "curtime", parsedArgs); }
/** * ifnull translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlifnull(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { twoArgumentsFunctionCall(buf, "coalesce(", "ifnull", parsedArgs); }
/** * rtrim translation * * @param buf The buffer to append into * @param parsedArgs arguments * @throws SQLException if something wrong happens */ public static void sqlrtrim(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException { singleArgumentFunctionCall(buf, "trim(trailing from ", "rtrim", parsedArgs); }