首页 > 代码库 > druid sqlparser使用例子
druid sqlparser使用例子
package com.alibaba.druid.bvt.sql.mysql; import java.util.List; import org.junit.Assert; import com.alibaba.druid.sql.MysqlTest; import com.alibaba.druid.sql.ast.SQLStatement; import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor; import com.alibaba.druid.stat.TableStat; import com.alibaba.druid.stat.TableStat.Column; public class MySqlDeleteTest_0 extends MysqlTest { public void test_0() throws Exception { String sql = "DELETE a1, a2 FROM t1 AS a1 INNER JOIN t2 AS a2 WHERE a1.id=a2.id;"; MySqlStatementParser parser = new MySqlStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement statemen = statementList.get(0); // print(statementList); Assert.assertEquals(1, statementList.size()); MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor(); statemen.accept(visitor); // System.out.println("Tables : " + visitor.getTables()); // System.out.println("fields : " + visitor.getColumns()); // System.out.println("coditions : " + visitor.getConditions()); // System.out.println("orderBy : " + visitor.getOrderByColumns()); Assert.assertEquals(2, visitor.getTables().size()); Assert.assertEquals(2, visitor.getColumns().size()); Assert.assertEquals(2, visitor.getConditions().size()); Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1"))); Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2"))); Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "id"))); Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id"))); } }
druid sqlparser使用例子
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。