Search in sources :

Example 1 with MySqlExprParser

use of com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser in project druid by alibaba.

the class EqualTest_extract_mysql method test_exits.

public void test_exits() throws Exception {
    String sql = "EXTRACT (YEAR FROM x)";
    String sql_c = "EXTRACT (MONTH FROM y)";
    MySqlExtractExpr exprA, exprB, exprC;
    {
        MySqlExprParser parser = new MySqlExprParser(sql);
        exprA = (MySqlExtractExpr) parser.expr();
    }
    {
        MySqlExprParser parser = new MySqlExprParser(sql);
        exprB = (MySqlExtractExpr) parser.expr();
    }
    {
        MySqlExprParser parser = new MySqlExprParser(sql_c);
        exprC = (MySqlExtractExpr) 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 MySqlExtractExpr(), new MySqlExtractExpr());
    Assert.assertEquals(new MySqlExtractExpr().hashCode(), new MySqlExtractExpr().hashCode());
}
Also used : MySqlExtractExpr(com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr) MySqlExprParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser)

Example 2 with MySqlExprParser

use of com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser in project druid by alibaba.

the class EqualTest_inquery method test_exits.

public void test_exits() throws Exception {
    String sql = "fstate in (select state from t_status)";
    String sql_c = "fstate_c in (select state from t_status)";
    SQLInSubQueryExpr exprA, exprB, exprC;
    {
        MySqlExprParser parser = new MySqlExprParser(sql);
        exprA = (SQLInSubQueryExpr) parser.expr();
    }
    {
        MySqlExprParser parser = new MySqlExprParser(sql);
        exprB = (SQLInSubQueryExpr) parser.expr();
    }
    {
        MySqlExprParser parser = new MySqlExprParser(sql_c);
        exprC = (SQLInSubQueryExpr) 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());
}
Also used : MySqlExprParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser) SQLInSubQueryExpr(com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)

Example 3 with MySqlExprParser

use of com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser in project druid by alibaba.

the class EqualTest_binary method test_exits.

public void test_exits() throws Exception {
    String sql = "b'01010'";
    String sql_c = "b'010101'";
    SQLBinaryExpr exprA, exprB, exprC;
    {
        SQLExprParser parser = new MySqlExprParser(sql);
        exprA = (SQLBinaryExpr) parser.expr();
    }
    {
        SQLExprParser parser = new MySqlExprParser(sql);
        exprB = (SQLBinaryExpr) parser.expr();
    }
    {
        SQLExprParser parser = new MySqlExprParser(sql_c);
        exprC = (SQLBinaryExpr) 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 SQLBinaryExpr(), new SQLBinaryExpr());
    Assert.assertEquals(new SQLBinaryExpr().hashCode(), new SQLBinaryExpr().hashCode());
}
Also used : SQLBinaryExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryExpr) MySqlExprParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser) SQLExprParser(com.alibaba.druid.sql.parser.SQLExprParser)

Example 4 with MySqlExprParser

use of com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser in project druid by alibaba.

the class EqualTest_boolean method test_exits.

public void test_exits() throws Exception {
    String sql = "true";
    String sql_c = "false";
    SQLBooleanExpr exprA, exprB, exprC;
    {
        SQLExprParser parser = new MySqlExprParser(sql);
        exprA = (SQLBooleanExpr) parser.expr();
    }
    {
        SQLExprParser parser = new MySqlExprParser(sql);
        exprB = (SQLBooleanExpr) parser.expr();
    }
    {
        SQLExprParser parser = new MySqlExprParser(sql_c);
        exprC = (SQLBooleanExpr) 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 SQLBooleanExpr(), new SQLBooleanExpr());
    Assert.assertEquals(new SQLBooleanExpr().hashCode(), new SQLBooleanExpr().hashCode());
}
Also used : SQLBooleanExpr(com.alibaba.druid.sql.ast.expr.SQLBooleanExpr) MySqlExprParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser) SQLExprParser(com.alibaba.druid.sql.parser.SQLExprParser)

Example 5 with MySqlExprParser

use of com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser in project druid by alibaba.

the class LiteralHexadecimalTest method test_1.

public void test_1() throws Exception {
    String sql = "x'0D0A'";
    SQLHexExpr hex = (SQLHexExpr) new MySqlExprParser(sql).expr();
    Assert.assertEquals("\r\n", new String(hex.toBytes(), "utf-8"));
}
Also used : SQLHexExpr(com.alibaba.druid.sql.ast.expr.SQLHexExpr) MySqlExprParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser)

Aggregations

MySqlExprParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser)13 SQLHexExpr (com.alibaba.druid.sql.ast.expr.SQLHexExpr)6 SQLExprParser (com.alibaba.druid.sql.parser.SQLExprParser)3 SQLBinaryExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryExpr)1 SQLBooleanExpr (com.alibaba.druid.sql.ast.expr.SQLBooleanExpr)1 SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)1 SQLUnaryExpr (com.alibaba.druid.sql.ast.expr.SQLUnaryExpr)1 MySqlExtractExpr (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr)1 MySqlIntervalExpr (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr)1 MySqlMatchAgainstExpr (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr)1