Skip to content

SchemaStatVisitor

wenshao edited this page May 17, 2016 · 5 revisions

SelectStatement Stat

String sql = "select name, age from t_user where id = 1";

String dbType = JdbcConstants.MYSQL;
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
SQLStatement stmt = stmtList.get(0);

SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);

System.out.println(statVisitor.getColumns()); // [t_user.name, t_user.age, t_user.id]
System.out.println(statVisitor.getTables()); // {t_user=Select}
System.out.println(statVisitor.getConditions()); // [t_user.id = 1]

CreateTable Stat

String sql = "create table t_org (fid int, name varchar(256))";

String dbType = JdbcConstants.MYSQL;
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
SQLStatement stmt = stmtList.get(0);

SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);

System.out.println(statVisitor.getTables()); //{t_org=Create}
System.out.println(statVisitor.getColumns()); // [t_org.fid, t_org.name]
Clone this wiki locally