Search in sources :

Example 91 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLSelectParserTest method test_select_15.

public void test_select_15() throws Exception {
    String sql = "SELect distinct high_priority straight_join sql_big_result sql_cache tb1.id,tb2.id " + "from tb1,tb2 where tb1.id2=tb2.id2";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals("SELECT DISTINCT HIGH_PRIORITY STRAIGHT_JOIN SQL_BIG_RESULT" + " SQL_CACHE tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 92 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLSelectParserTest method test_union_0.

public void test_union_0() throws Exception {
    String sql = "(select id from t1) union all (select id from t2) union all (select id from t3) ordeR By d desC limit 1 offset ?";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "SELECT id\n" + //
    "FROM t1\n" + //
    "UNION ALL\n" + //
    "SELECT id\n" + //
    "FROM t2\n" + //
    "UNION ALL\n" + //
    "(SELECT id\n" + //
    "FROM t3)\n" + //
    "ORDER BY d DESC\n" + "LIMIT ?, 1", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 93 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLSelectParserTest method test_union_1.

public void test_union_1() throws Exception {
    String sql = "(select id from t1) union  select id from t2 order by id union aLl (select id from t3) ordeR By d asC";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "SELECT id\n" + //
    "FROM t1\n" + //
    "UNION\n" + //
    "(SELECT id\n" + //
    "FROM t2\n" + //
    "ORDER BY id)\n" + //
    "UNION ALL\n" + //
    "(SELECT id\n" + //
    "FROM t3)\n" + "ORDER BY d ASC", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 94 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLSelectParserTest method test_select_0.

public void test_select_0() throws Exception {
    String sql = "SELect t1.id , t2.* from t1, test.t2 where test.t1.id=1 and t1.id=test.t2.id";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "SELECT t1.id, t2.*\n" + //
    "FROM t1, test.t2\n" + //
    "WHERE test.t1.id = 1\n" + "\tAND t1.id = test.t2.id", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 95 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLSelectParserTest method test_select_3.

public void test_select_3() throws Exception {
    String sql = "SELect distinct high_priority tb1.id,tb2.id from tb1,tb2 where tb1.id2=tb2.id2";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals("SELECT DISTINCT HIGH_PRIORITY tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1652 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)915 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)431 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)346 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)273 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)254 Column (com.alibaba.druid.stat.TableStat.Column)122 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)109 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)107 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)100 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)67 MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)60 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)46 OdpsStatementParser (com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser)44 DB2SchemaStatVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor)34 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)33 Test (org.junit.Test)31 MysqlTest (com.alibaba.druid.sql.MysqlTest)29 ArrayList (java.util.ArrayList)29 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)28