Java Code Examples for com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock#getWhere()

The following examples show how to use com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock#getWhere() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DruidSelectParser.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
private boolean isConditionAlwaysTrue(SQLStatement statement) {
	SQLSelectStatement selectStmt = (SQLSelectStatement)statement;
	SQLSelectQuery sqlSelectQuery = selectStmt.getSelect().getQuery();
	if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
		MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)selectStmt.getSelect().getQuery();
		SQLExpr expr = mysqlSelectQuery.getWhere();

		Object o = WallVisitorUtils.getValue(expr);
		if(Boolean.TRUE.equals(o)) {
			return true;
		}
		return false;
	} else {//union
		return false;
	}

}
 
Example 2
Source File: TestMySQLItemVisitor.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testWhere() {
    MySqlSelectQueryBlock query = getQuery("select col1,col2  from table1 where a =1 ");
    SQLExpr expr = query.getWhere();

    MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset,null, null);
    expr.accept(v);
    Item item = v.getItem();
    Assert.assertEquals(true, "a = 1".equals(item.getItemName()));
}
 
Example 3
Source File: MysqlCountOutputVisitor.java    From Zebra with Apache License 2.0 5 votes vote down vote up
public boolean visit(MySqlSelectQueryBlock x) {
	if (x.getOrderBy() != null) {
		x.getOrderBy().setParent(x);
	}

	boolean rewriteDistinct = false;
	if (x.getSelectList() != null) {
		rewriteDistinct = visitSelectItems(x.getSelectList(), SQLSetQuantifier.DISTINCT == x.getDistionOption());
	}

	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);
	}

	if (rewriteDistinct) {
		print0(") ZebraDaoDistinctTable");
	}

	return false;
}
 
Example 4
Source File: WhereParser.java    From elasticsearch-sql with Apache License 2.0 4 votes vote down vote up
public WhereParser(SqlParser sqlParser, MySqlSelectQueryBlock query) {
    this.sqlParser = sqlParser;
    this.query = query;
    this.where = query.getWhere();
}