Search in sources :

Example 11 with MySqlExprParser

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

the class EqualTest_unary_mysql method test_exits.

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

Example 12 with MySqlExprParser

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

the class EqualTest_interval_mysql method test_exits.

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

Example 13 with MySqlExprParser

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

the class EqualTest_mysqlMatch method test_exits.

public void test_exits() throws Exception {
    String sql = "MATCH (f1, f2) AGAINST (f3 IN BOOLEAN MODE)";
    String sql_c = "MATCH (f1, f2) AGAINST (f4 IN BOOLEAN MODE)";
    MySqlMatchAgainstExpr exprA, exprB, exprC;
    {
        MySqlExprParser parser = new MySqlExprParser(sql);
        exprA = (MySqlMatchAgainstExpr) parser.expr();
    }
    {
        MySqlExprParser parser = new MySqlExprParser(sql);
        exprB = (MySqlMatchAgainstExpr) parser.expr();
    }
    {
        MySqlExprParser parser = new MySqlExprParser(sql_c);
        exprC = (MySqlMatchAgainstExpr) 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 MySqlMatchAgainstExpr(), new MySqlMatchAgainstExpr());
    Assert.assertEquals(new MySqlMatchAgainstExpr().hashCode(), new MySqlMatchAgainstExpr().hashCode());
    exprA.setColumns(null);
    exprB.setColumns(null);
    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 : MySqlMatchAgainstExpr(com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr) 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