本文整理汇总了Java中com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom方法的典型用法代码示例。如果您正苦于以下问题:Java MySqlSelectQueryBlock.getFrom方法的具体用法?Java MySqlSelectQueryBlock.getFrom怎么用?Java MySqlSelectQueryBlock.getFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock
的用法示例。
在下文中一共展示了MySqlSelectQueryBlock.getFrom方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Override
public boolean visit(MySqlSelectQueryBlock x) {
SQLOrderBy orderBy = x.getOrderBy();
SQLLimit limit = x.getLimit();
if (limit != null && (orderBy == null || orderBy.getItems().size() == 0)) {
boolean subQueryHasOrderBy = false;
SQLTableSource from = x.getFrom();
if (from instanceof SQLSubqueryTableSource) {
SQLSubqueryTableSource subqueryTabSrc = (SQLSubqueryTableSource) from;
SQLSelect select = subqueryTabSrc.getSelect();
if (select.getQuery() instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock subquery = (SQLSelectQueryBlock) select.getQuery();
if (subquery.getOrderBy() != null && subquery.getOrderBy().getItems().size() > 0) {
subQueryHasOrderBy = true;
}
}
}
if (!subQueryHasOrderBy) {
unorderedLimitCount++;
}
}
return true;
}
示例2: isSupportSelect
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private static boolean isSupportSelect(String stmt) {
SQLStatementParser parser = new MySqlStatementParser(stmt);
SQLStatement statement = parser.parseStatement();
if (!(statement instanceof SQLSelectStatement)) {
return false;
}
SQLSelectQuery sqlSelectQuery = ((SQLSelectStatement) statement).getSelect().getQuery();
if (!(sqlSelectQuery instanceof MySqlSelectQueryBlock)) {
return false;
}
MySqlSelectQueryBlock selectQueryBlock = (MySqlSelectQueryBlock) sqlSelectQuery;
SQLTableSource mysqlFrom = selectQueryBlock.getFrom();
if (mysqlFrom != null) {
return false;
}
for (SQLSelectItem item : selectQueryBlock.getSelectList()) {
SQLExpr selectItem = item.getExpr();
if (!isVariantRef(selectItem)) {
return false;
}
}
return true;
}
示例3: findGroupBy
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void findGroupBy(MySqlSelectQueryBlock query, Select select) throws SqlParseException {
SQLSelectGroupByClause groupBy = query.getGroupBy();
SQLTableSource sqlTableSource = query.getFrom();
if (groupBy == null) {
return;
}
List<SQLExpr> items = groupBy.getItems();
List<SQLExpr> standardGroupBys = new ArrayList<>();
for (SQLExpr sqlExpr : items) {
//todo: mysql expr patch
if (sqlExpr instanceof MySqlSelectGroupByExpr) {
MySqlSelectGroupByExpr sqlSelectGroupByExpr = (MySqlSelectGroupByExpr) sqlExpr;
sqlExpr = sqlSelectGroupByExpr.getExpr();
}
if ((sqlExpr instanceof SQLParensIdentifierExpr || !(sqlExpr instanceof SQLIdentifierExpr || sqlExpr instanceof SQLMethodInvokeExpr)) && !standardGroupBys.isEmpty()) {
// flush the standard group bys
select.addGroupBy(convertExprsToFields(standardGroupBys, sqlTableSource));
standardGroupBys = new ArrayList<>();
}
if (sqlExpr instanceof SQLParensIdentifierExpr) {
// single item with parens (should get its own aggregation)
select.addGroupBy(FieldMaker.makeField(sqlExpr, null, sqlTableSource.getAlias()));
} else if (sqlExpr instanceof SQLListExpr) {
// multiple items in their own list
SQLListExpr listExpr = (SQLListExpr) sqlExpr;
select.addGroupBy(convertExprsToFields(listExpr.getItems(), sqlTableSource));
} else {
// everything else gets added to the running list of standard group bys
standardGroupBys.add(sqlExpr);
}
}
if (!standardGroupBys.isEmpty()) {
select.addGroupBy(convertExprsToFields(standardGroupBys, sqlTableSource));
}
}
示例4: getOwnerTableName
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
/**
* get table name of field in between expr
*
* @param betweenExpr
* @param column
* @return
*/
private String getOwnerTableName(SQLBetweenExpr betweenExpr, String column) {
if (tableStats.size() == 1) { //only has 1 table
return tableStats.keySet().iterator().next().getName();
} else if (tableStats.size() == 0) { //no table
return "";
} else { // multi tables
for (Column col : columns.keySet()) {
if (col.getName().equals(column)) {
return col.getTable();
}
}
//parser from parent
SQLObject parent = betweenExpr.getParent();
if (parent instanceof SQLBinaryOpExpr) {
parent = parent.getParent();
}
if (parent instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
if (select.getFrom() instanceof SQLJoinTableSource) {
SQLJoinTableSource joinTableSource = (SQLJoinTableSource) select.getFrom();
//FIXME :left as driven table
return joinTableSource.getLeft().toString();
} else if (select.getFrom() instanceof SQLExprTableSource) {
return select.getFrom().toString();
}
} else if (parent instanceof SQLUpdateStatement) {
SQLUpdateStatement update = (SQLUpdateStatement) parent;
return update.getTableName().getSimpleName();
} else if (parent instanceof SQLDeleteStatement) {
SQLDeleteStatement delete = (SQLDeleteStatement) parent;
return delete.getTableName().getSimpleName();
}
}
return "";
}
示例5: testJoinCondition
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Test
public void testJoinCondition() {
MySqlSelectQueryBlock query = getQuery("select a.col1,b.col2 from table1 a inner join table2 b on a.id =b.id");
SQLJoinTableSource from = (SQLJoinTableSource) query.getFrom();
MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset,null);
from.getCondition().accept(v);
Item item = v.getItem();
Assert.assertEquals(true, "a.id = b.id".equals(item.getItemName()));
}
示例6: visit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public boolean visit(MySqlSelectQueryBlock x) {
if (x.getOrderBy() != null) {
x.getOrderBy().setParent(x);
}
print0(ucase ? "SELECT COUNT(*) " : "select count(*) ");
if (x.getFrom() != null) {
println();
print0(ucase ? "FROM " : "from ");
x.getFrom().accept(this);
}
if (x.getWhere() != null) {
println();
print0(ucase ? "WHERE " : "where ");
x.getWhere().setParent(x);
x.getWhere().accept(this);
}
if (x.getGroupBy() != null) {
println();
x.getGroupBy().accept(this);
}
if (x.getOrderBy() != null) {
println();
x.getOrderBy().accept(this);
}
return false;
}
示例7: visit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Override
public boolean visit(final MySqlSelectQueryBlock x) {
selectLayer++;
if (x.getFrom() instanceof SQLExprTableSource) {
SQLExprTableSource tableExpr = (SQLExprTableSource) x.getFrom();
setCurrentTable(tableExpr.getExpr().toString(), Optional.fromNullable(tableExpr.getAlias()));
}
//处理distinct
if(isEnableCollectMetadata()){
if(SQLSetQuantifier.DISTINCT==x.getDistionOption()){
parseResult.markDistinct();
}
}
return super.visit(x);
}
示例8: getOwnerTableName
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
/**
* 从between语句中获取字段所属的表名。
* 对于容易出现ambiguous的(字段不知道到底属于哪个表),实际应用中必须使用别名来避免歧义
* @param betweenExpr
* @param column
* @return
*/
private String getOwnerTableName(SQLBetweenExpr betweenExpr,String column) {
if(tableStats.size() == 1) {//只有一个表,直接返回这一个表名
return tableStats.keySet().iterator().next().getName();
} else if(tableStats.size() == 0) {//一个表都没有,返回空串
return "";
} else {//多个表名
for (Column col : columns.keySet())
{
if(col.getName().equals(column)) {
return col.getTable();
}
}
// for(Column col : columns) {//从columns中找表名
// if(col.getName().equals(column)) {
// return col.getTable();
// }
// }
//前面没找到表名的,自己从parent中解析
SQLObject parent = betweenExpr.getParent();
if(parent instanceof SQLBinaryOpExpr)
{
parent=parent.getParent();
}
if(parent instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
if(select.getFrom() instanceof SQLJoinTableSource) {//多表连接
SQLJoinTableSource joinTableSource = (SQLJoinTableSource)select.getFrom();
return joinTableSource.getLeft().toString();//将left作为主表,此处有不严谨处,但也是实在没有办法,如果要准确,字段前带表名或者表的别名即可
} else if(select.getFrom() instanceof SQLExprTableSource) {//单表
return select.getFrom().toString();
}
}
else if(parent instanceof SQLUpdateStatement) {
SQLUpdateStatement update = (SQLUpdateStatement) parent;
return update.getTableName().getSimpleName();
} else if(parent instanceof SQLDeleteStatement) {
SQLDeleteStatement delete = (SQLDeleteStatement) parent;
return delete.getTableName().getSimpleName();
} else {
}
}
return "";
}
示例9: isJoin
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private static boolean isJoin(SQLQueryExpr sqlExpr,String sql) {
MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) sqlExpr.getSubQuery().getQuery();
return query.getFrom() instanceof SQLJoinTableSource && sql.toLowerCase().contains("join");
}
示例10: visit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public boolean visit(MySqlSelectQueryBlock sqlSelectQuery) {
SQLTableSource from = sqlSelectQuery.getFrom();
if (from != null) {
visit(from);
if (this.tableNode instanceof NoNameNode) {
this.tableNode.setSql(SQLUtils.toMySqlString(sqlSelectQuery));
}
} else {
this.tableNode = new NoNameNode(currentDb, SQLUtils.toMySqlString(sqlSelectQuery));
}
if (tableNode != null && (sqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCT || sqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCTROW)) {
this.tableNode.setDistinct(true);
}
List<SQLSelectItem> items = sqlSelectQuery.getSelectList();
if (items != null) {
List<Item> selectItems = handleSelectItems(items);
if (selectItems != null) {
this.tableNode.select(selectItems);
}
}
SQLExpr whereExpr = sqlSelectQuery.getWhere();
if (whereExpr != null) {
handleWhereCondition(whereExpr);
}
SQLOrderBy orderBy = sqlSelectQuery.getOrderBy();
if (orderBy != null) {
handleOrderBy(orderBy);
}
SQLSelectGroupByClause groupBy = sqlSelectQuery.getGroupBy();
if (groupBy != null) {
handleGroupBy(groupBy);
}
SQLLimit limit = sqlSelectQuery.getLimit();
if (limit != null) {
handleLimit(limit);
}
return true;
}