/* * Copyright (c) 2009 Mysema Ltd. * All rights reserved. * */ package com.mysema.query.sql; import org.junit.Test; import com.mysema.query.functions.MathFunctions; import com.mysema.query.functions.StringFunctions; import com.mysema.query.sql.domain.QEMPLOYEE; import com.mysema.query.types.expr.EConstant; import com.mysema.query.types.expr.EString; import com.mysema.query.types.expr.Expr; /** * HsqldbFunctionsTest provides * * @author tiwe * @version $Id$ */ public class HsqldbFunctionsTest { @Test public void testNumeric() { Expr i = EConstant.create(1); Expr d = EConstant.create(1.0); // ABS(d) returns the absolute value of a double value MathFunctions.abs(i); // ACOS(d) returns the arc cosine of an angle MathFunctions.acos(d); // ASIN(d) returns the arc sine of an angle MathFunctions.asin(d); // ATAN(d) returns the arc tangent of an angle MathFunctions.atan(d); // ATAN2(a,b) returns the tangent of a/b // BITAND(a,b) return a & b // BITOR(a,b) returns a | b // CEILING(d) returns the smallest integer that is not less than d MathFunctions.ceil(d); // COS(d) returns the cosine of an angle MathFunctions.cos(d); // COT(d) returns the cotangent of an angle // DEGREES(d) converts radians to degrees // EXP(d) returns e (2.718...) raised to the power of d MathFunctions.exp(d); // FLOOR(d) returns the largest integer that is not greater than d MathFunctions.floor(d); // LOG(d) returns the natural logarithm (base e) MathFunctions.log(d); // LOG10(d) returns the logarithm (base 10) MathFunctions.log10(d); // MOD(a,b) returns a modulo b // QMath.mod(i,i); // PI() returns pi (3.1415...) // POWER(a,b) returns a raised to the power of b MathFunctions.pow(d, d); // RADIANS(d) converts degrees to radians // RAND() returns a random number x bigger or equal to 0.0 and smaller // than 1.0 MathFunctions.random(); // ROUND(a,b) rounds a to b digits after the decimal point MathFunctions.round(d); // ROUNDMAGIC(d) solves rounding problems such as 3.11-3.1-0.01 // SIGN(d) returns -1 if d is smaller than 0, 0 if d==0 and 1 if d is // bigger than 0 // SIN(d) returns the sine of an angle MathFunctions.sin(d); // SQRT(d) returns the square root MathFunctions.sqrt(i); // TAN(A) returns the trigonometric tangent of an angle MathFunctions.tan(d); // TRUNCATE(a,b) truncates a to b digits after the decimal point } @Test public void testStringFunctions() { EString s = new QEMPLOYEE("e").firstname; // // String built-in Functions / Stored Procedures // // ASCII(s) returns the ASCII code of the leftmost character of s // BIT_LENGTH(str)[2] returns the length of the string in bits // CHAR(c) returns a character that has the ASCII code c // CHAR_LENGTH(str)[2] returns the length of the string in characters // CONCAT(str1,str2) returns str1 + str2 s.concat(s); // DIFFERENCE(s1,s2) returns the difference between the sound of s1 and // s2 // HEXTORAW(s1)[2] returns translated string // INSERT(s,start,len,s2)returns a string where len number of characters // beginning at start has been replaced by s2 // LCASE(s) converts s to lower case s.lower(); // LEFT(s,count) returns the leftmost count of characters of s) - // requires double quoting - use SUBSTRING() instead // LENGTH(s) returns the number of characters in s // QString.length(s); // LOCATE(search,s,[start])returns the first index (1=left, 0=not found) // where search is found in s, starting at start // LTRIM(s) removes all leading blanks in s StringFunctions.ltrim(s); // OCTET_LENGTH(str)[2] returns the length of the string in bytes (twice // the number of characters) // RAWTOHEX(s1)[2] returns translated string // REPEAT(s,count) returns s repeated count times // REPLACE(s,replace,s2) replaces all occurrences of replace in s with // s2 // RIGHT(s,count) returns the rightmost count of characters of s // RTRIM(s) removes all trailing spaces StringFunctions.rtrim(s); // SOUNDEX(s) returns a four character code representing the sound of s // SPACE(count) returns a string consisting of count spaces StringFunctions.space(4); // SUBSTR(s,start[,len]) alias for substring s.substring(1); // SUBSTRING(s,start[,len]) returns the substring starting at start // (1=left) with length len // UCASE(s) converts s to upper case s.upper(); // LOWER(s) converts s to lower case s.lower(); // UPPER(s) converts s to upper case s.upper(); } // @Test // public void testDateTimeFunctions() { // Expr d = new EConstant(new Date()); // Expr