コード例 #1
0
  public void helpTest(Expression srcExpression, String tgtType, String expectedExpression)
      throws Exception {
    Function func =
        LANG_FACTORY.createFunction(
            "convert", //$NON-NLS-1$
            Arrays.asList(srcExpression, LANG_FACTORY.createLiteral(tgtType, String.class)),
            TypeFacility.getDataTypeClass(tgtType));

    assertEquals(
        "Error converting from " + srcExpression.getType() + " to " + tgtType,
        expectedExpression,
        helpGetString(func));
  }
コード例 #2
0
 @Test
 public void testStringToTimestamp() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral("2004-06-29 23:59:59.987", String.class),
       "timestamp",
       "to_timestamp('2004-06-29 23:59:59.987', 'YYYY-MM-DD HH24:MI:SS.MS')");
 }
コード例 #3
0
 @Test
 public void testStringToTime() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral("23:59:59", String.class),
       "time",
       "to_timestamp('23:59:59', 'HH24:MI:SS')");
 }
コード例 #4
0
 @Test
 public void testBigIntegerToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class),
       "boolean",
       "CASE WHEN 1 = 0 THEN '0' WHEN 1 IS NOT NULL THEN '1' END");
 }
コード例 #5
0
 @Test
 public void testStringToBigInteger() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral("5", String.class),
       "biginteger",
       "cast('5' AS numeric(38))"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
 }
コード例 #6
0
 @Test
 public void testShortToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Short((short) 1), Short.class),
       "string",
       "cast(1 AS varchar(4000))");
 }
コード例 #7
0
 @Test
 public void testByteToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Byte((byte) 1), Byte.class),
       "boolean",
       "CASE WHEN 1 = 0 THEN '0' WHEN 1 IS NOT NULL THEN '1' END");
 }
コード例 #8
0
 @Test
 public void testByteToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Byte((byte) 1), Byte.class),
       "string",
       "cast(1 AS varchar(4000))");
 }
コード例 #9
0
 @Test
 public void testBooleanToBigDecimal() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(Boolean.FALSE, Boolean.class),
       "bigdecimal",
       "(CASE WHEN 0 IN ( '0', 'FALSE') THEN 0 WHEN 0 IS NOT NULL THEN 1 END)");
 }
コード例 #10
0
 @Test
 public void testShortToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Short((short) 1), Short.class),
       "boolean",
       "CASE WHEN 1 = 0 THEN '0' WHEN 1 IS NOT NULL THEN '1' END");
 }
コード例 #11
0
 @Test
 public void testFloatToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
       "string",
       "cast(1.2 AS varchar(4000))");
 }
コード例 #12
0
 @Test
 public void testFloatToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Float(1.2f), Float.class),
       "boolean",
       "CASE WHEN 1.2 = 0 THEN '0' WHEN 1.2 IS NOT NULL THEN '1' END");
 }
コード例 #13
0
 @Test
 public void testBigDecimalToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class),
       "string",
       "cast(1.0 AS varchar(4000))");
 }
コード例 #14
0
 @Test
 public void testStringToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral("5", String.class),
       "boolean",
       "CASE WHEN '5' IN ('false', '0') THEN '0' WHEN '5' IS NOT NULL THEN '1' END");
 }
コード例 #15
0
 @Test
 public void testBigDecimalToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class),
       "boolean",
       "CASE WHEN 1.0 = 0 THEN '0' WHEN 1.0 IS NOT NULL THEN '1' END");
 }
コード例 #16
0
 @Test
 public void testDoubleToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
       "string",
       "cast(1.2 AS varchar(4000))");
 }
コード例 #17
0
 @Test
 public void testDoubleToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Double(1.2), Double.class),
       "boolean",
       "CASE WHEN 1.2 = 0 THEN '0' WHEN 1.2 IS NOT NULL THEN '1' END");
 }
コード例 #18
0
 @Test
 public void testBooleanToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
       "string",
       "CASE WHEN 1 = '0' THEN 'false' WHEN 1 IS NOT NULL THEN 'true' END");
 }
コード例 #19
0
 @Test
 public void testStringToDate() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral("2004-06-29", String.class),
       "date",
       "to_date('2004-06-29', 'YYYY-MM-DD')");
 }
コード例 #20
0
 @Test
 public void testBigIntegerToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class),
       "string",
       "cast(1 AS varchar(4000))");
 }
コード例 #21
0
 @Test
 public void testLongToBoolean() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Long(1), Long.class),
       "boolean",
       "CASE WHEN 1 = 0 THEN '0' WHEN 1 IS NOT NULL THEN '1' END");
 }
コード例 #22
0
 @Test
 public void testStringToInteger() throws Exception {
   helpTest(LANG_FACTORY.createLiteral("5", String.class), "integer", "cast('5' AS integer)");
 }
コード例 #23
0
 @Test
 public void testStringToShort() throws Exception {
   helpTest(LANG_FACTORY.createLiteral("5", String.class), "short", "cast('5' AS smallint)");
 }
コード例 #24
0
 @Test
 public void testStringToByte() throws Exception {
   helpTest(LANG_FACTORY.createLiteral("5", String.class), "byte", "cast('5' AS byteint)");
 }
コード例 #25
0
 // Source = STRING
 @Test
 public void testStringToChar() throws Exception {
   helpTest(LANG_FACTORY.createLiteral("5", String.class), "char", "cast('5' AS char(1))");
 }
コード例 #26
0
 @Test
 public void testStringToBigDecimal() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral("5", String.class), "bigdecimal", "cast('5' AS numeric(38,18))");
 }
コード例 #27
0
 @Test
 public void testStringToLong() throws Exception {
   helpTest(LANG_FACTORY.createLiteral("5", String.class), "long", "cast('5' AS bigint)");
 }
コード例 #28
0
 @Test
 public void testLongToString() throws Exception {
   helpTest(
       LANG_FACTORY.createLiteral(new Long(1), Long.class), "string", "cast(1 AS varchar(4000))");
 }
コード例 #29
0
 @Test
 public void testStringToDouble() throws Exception {
   helpTest(LANG_FACTORY.createLiteral("5", String.class), "double", "cast('5' AS double)");
 }
コード例 #30
0
 @Test
 public void testCharToString() throws Exception {
   helpTest(LANG_FACTORY.createLiteral(new Character('5'), Character.class), "string", "'5'");
 }