Search in sources :

Example 6 with SQLCastExpr

use of com.alibaba.druid.sql.ast.expr.SQLCastExpr in project dble by actiontech.

the class ItemDatetimeTypecast method toExpression.

@Override
public SQLExpr toExpression() {
    SQLCastExpr cast = new SQLCastExpr();
    cast.setExpr(args.get(0).toExpression());
    SQLDataTypeImpl dataType = new SQLDataTypeImpl("DATETIME");
    if (decimals != Item.NOT_FIXED_DEC) {
        dataType.addArgument(new SQLIntegerExpr(decimals));
    }
    cast.setDataType(dataType);
    return cast;
}
Also used : SQLCastExpr(com.alibaba.druid.sql.ast.expr.SQLCastExpr) SQLIntegerExpr(com.alibaba.druid.sql.ast.expr.SQLIntegerExpr) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl)

Example 7 with SQLCastExpr

use of com.alibaba.druid.sql.ast.expr.SQLCastExpr in project dble by actiontech.

the class ItemFuncSigned method toExpression.

@Override
public SQLExpr toExpression() {
    SQLCastExpr cast = new SQLCastExpr();
    cast.setExpr(args.get(0).toExpression());
    SQLDataTypeImpl dataType = new SQLDataTypeImpl("SIGNED");
    cast.setDataType(dataType);
    return cast;
}
Also used : SQLCastExpr(com.alibaba.druid.sql.ast.expr.SQLCastExpr) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl)

Example 8 with SQLCastExpr

use of com.alibaba.druid.sql.ast.expr.SQLCastExpr in project dble by actiontech.

the class ItemFuncUnsigned method toExpression.

@Override
public SQLExpr toExpression() {
    SQLCastExpr cast = new SQLCastExpr();
    cast.setExpr(args.get(0).toExpression());
    SQLDataTypeImpl dataType = new SQLDataTypeImpl("UNSIGNED");
    cast.setDataType(dataType);
    return cast;
}
Also used : SQLCastExpr(com.alibaba.druid.sql.ast.expr.SQLCastExpr) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl)

Example 9 with SQLCastExpr

use of com.alibaba.druid.sql.ast.expr.SQLCastExpr in project dble by actiontech.

the class ItemDateTypecast method toExpression.

@Override
public SQLExpr toExpression() {
    SQLCastExpr cast = new SQLCastExpr();
    cast.setExpr(args.get(0).toExpression());
    SQLDataTypeImpl dataType = new SQLDataTypeImpl("DATE");
    cast.setDataType(dataType);
    return cast;
}
Also used : SQLCastExpr(com.alibaba.druid.sql.ast.expr.SQLCastExpr) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl)

Example 10 with SQLCastExpr

use of com.alibaba.druid.sql.ast.expr.SQLCastExpr in project druid by alibaba.

the class EqualTest_cast method test_exits.

public void test_exits() throws Exception {
    String sql = "cast(a as varchar(50))";
    String sql_c = "cast(b as varchar(50))";
    SQLCastExpr exprA, exprB, exprC;
    {
        OracleExprParser parser = new OracleExprParser(sql);
        exprA = (SQLCastExpr) parser.expr();
    }
    {
        OracleExprParser parser = new OracleExprParser(sql);
        exprB = (SQLCastExpr) parser.expr();
    }
    {
        OracleExprParser parser = new OracleExprParser(sql_c);
        exprC = (SQLCastExpr) parser.expr();
    }
    Assert.assertEquals(exprA, exprB);
    Assert.assertNotEquals(exprA, exprC);
    Assert.assertTrue(exprA.equals(exprA));
    Assert.assertFalse(exprA.equals(new Object()));
    Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
    Assert.assertEquals(new SQLCastExpr(), new SQLCastExpr());
    Assert.assertEquals(new SQLCastExpr().hashCode(), new SQLCastExpr().hashCode());
    Assert.assertEquals(new SQLDataTypeImpl(), new SQLDataTypeImpl());
    Assert.assertEquals(new SQLDataTypeImpl().hashCode(), new SQLDataTypeImpl().hashCode());
}
Also used : OracleExprParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser) SQLCastExpr(com.alibaba.druid.sql.ast.expr.SQLCastExpr) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl)

Aggregations

SQLCastExpr (com.alibaba.druid.sql.ast.expr.SQLCastExpr)10 SQLDataTypeImpl (com.alibaba.druid.sql.ast.SQLDataTypeImpl)9 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)6 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)1 OracleExprParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser)1