Search in sources :

Example 51 with SQLStatementParser

use of com.alibaba.druid.sql.parser.SQLStatementParser in project druid by alibaba.

the class DateAndTimeFunctionsTest method test_45.

public void test_45() throws Exception {
    String sql = "SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    String text = output(stmtList);
    Assert.assertEquals("SELECT TIMESTAMPDIFF(MONTH, '2003-02-01', '2003-05-01');", text);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 52 with SQLStatementParser

use of com.alibaba.druid.sql.parser.SQLStatementParser in project druid by alibaba.

the class DateAndTimeValuesTest method test_2.

public void test_2() throws Exception {
    String sql = "SELECT '2008-02-31' + INTERVAL 0 MONTH";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    String text = output(stmtList);
    Assert.assertEquals("SELECT '2008-02-31' + INTERVAL 0 MONTH;", text);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 53 with SQLStatementParser

use of com.alibaba.druid.sql.parser.SQLStatementParser in project druid by alibaba.

the class DeleteSyntaxTest method test_3.

public void test_3() throws Exception {
    String sql = "DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a1.id=a2.id";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement stmt = stmtList.get(0);
    Assert.assertEquals(//
    "DELETE FROM a1, a2 USING (t1) AS a1" + "\n\tINNER JOIN t2 a2\nWHERE a1.id = a2.id", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals(//
    "delete from a1, a2 using (t1) as a1" + "\n\tinner join t2 a2\nwhere a1.id = a2.id", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 54 with SQLStatementParser

use of com.alibaba.druid.sql.parser.SQLStatementParser in project druid by alibaba.

the class DeleteSyntaxTest method test_4.

public void test_4() throws Exception {
    String sql = "DELETE LOW_PRIORITY QUICK IGNORE FROM T";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement stmt = stmtList.get(0);
    Assert.assertEquals("DELETE LOW_PRIORITY QUICK IGNORE FROM T", SQLUtils.toMySqlString(stmt));
    Assert.assertEquals("delete low_priority quick ignore from T", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 55 with SQLStatementParser

use of com.alibaba.druid.sql.parser.SQLStatementParser in project druid by alibaba.

the class DeleteSyntaxTest method test_1.

public void test_1() throws Exception {
    String sql = "DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement stmt = stmtList.get(0);
    Assert.assertEquals(//
    "DELETE t1" + //
    "\nFROM t1" + //
    "\n\tLEFT JOIN t2 ON t1.id = t2.id" + "\nWHERE t2.id IS NULL", SQLUtils.toMySqlString(stmt));
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)436 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)431 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)382 ArrayList (java.util.ArrayList)21 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)19 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)14 MycatSchemaStatVisitor (io.mycat.route.parser.druid.MycatSchemaStatVisitor)6 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)5 MySqlExportParameterVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor)5 ExportParameterVisitor (com.alibaba.druid.sql.visitor.ExportParameterVisitor)5 TableStat (com.alibaba.druid.stat.TableStat)5 MycatStatementParser (io.mycat.route.parser.druid.MycatStatementParser)5 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)4 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)4 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)4 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)3 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)3 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)3 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)3 RouteResultset (io.mycat.route.RouteResultset)3