Search in sources :

Example 96 with SQLStatement

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

the class AssignmentOperatorsTest method test_1.

public void test_1() throws Exception {
    String sql = "SELECT @var1 := 1, @var2;";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    String text = output(stmtList);
    Assert.assertEquals("SELECT @var1 := 1, @var2;", 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 97 with SQLStatement

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

the class AssignmentOperatorsTest method test_2.

public void test_2() throws Exception {
    String sql = "SELECT @var1, @var2 := @var1;";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    String text = output(stmtList);
    Assert.assertEquals("SELECT @var1, @var2 := @var1;", 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 98 with SQLStatement

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

the class AssignmentOperatorsTest method output.

private String output(List<SQLStatement> stmtList) {
    StringBuilder out = new StringBuilder();
    for (SQLStatement stmt : stmtList) {
        stmt.accept(new MySqlOutputVisitor(out));
        out.append(";");
    }
    return out.toString();
}
Also used : MySqlOutputVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 99 with SQLStatement

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

the class AssignmentOperatorsTest method test_4.

public void test_4() throws Exception {
    String sql = "UPDATE t1 SET c1 = 2 WHERE c1 = @var1:= 1;";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    String text = output(stmtList);
    Assert.assertEquals("UPDATE t1\nSET c1 = 2\nWHERE c1 = (@var1 := 1);", 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 100 with SQLStatement

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

the class AssignmentOperatorsTest method test_0.

public void test_0() throws Exception {
    String sql = "SELECT @var1, @var2;";
    SQLStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    String text = output(stmtList);
    Assert.assertEquals("SELECT @var1, @var2;", 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)

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