Search in sources :

Example 71 with SQLStatement

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

the class DMLDeleteParserTest method testDelete_8.

public void testDelete_8() throws Exception {
    String sql = "deLetE from t1";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals("DELETE FROM t1", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 72 with SQLStatement

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

the class DMLDeleteParserTest method testDelete_4.

public void testDelete_4() throws Exception {
    String sql = "deLetE from id where col1='adf' ordEr by d liMit ? offset 2";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "DELETE FROM id\n" + //
    "WHERE col1 = 'adf'\n" + //
    "ORDER BY d\n" + "LIMIT 2, ?", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 73 with SQLStatement

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

the class DMLDeleteParserTest method testDelete_10.

public void testDelete_10() throws Exception {
    String sql = "deLetE quick tb1.*,id1.t from t1";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals("DELETE QUICK tb1.*, id1.t\n" + "FROM t1", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 74 with SQLStatement

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

the class DMLDeleteParserTest method testDelete_7.

public void testDelete_7() throws Exception {
    String sql = "deLetE from t1 where t1.id1='abc' order by a limit 5";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "DELETE FROM t1\n" + //
    "WHERE t1.id1 = 'abc'\n" + //
    "ORDER BY a\n" + "LIMIT 5", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 75 with SQLStatement

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

the class DMLDeleteParserTest method testDelete_2.

public void testDelete_2() throws Exception {
    String sql = "delete from offer.*,wp_image.* using offer a,wp_image b where a.member_id=b.member_id and a.member_id='abc' ";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "DELETE FROM offer.*, wp_image.*" + //
    " USING (offer) AS a, wp_image b\n" + //
    "WHERE a.member_id = b.member_id\n" + "\tAND a.member_id = 'abc'", 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