Java Code Examples for com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor

The following examples show how to use com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor. These examples are extracted from open source projects. 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 Project: Mycat2   Source File: DruidSelectParser.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void parseOrderAggGroupMysql(SchemaConfig schema, SQLStatement stmt, RouteResultset rrs, MySqlSelectQueryBlock mysqlSelectQuery)
	{
		MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
		stmt.accept(visitor);
//		rrs.setGroupByCols((String[])visitor.getGroupByColumns().toArray());
		if(!isNeedParseOrderAgg)
		{
			return;
		}
		Map<String, String> aliaColumns = parseAggGroupCommon(schema, stmt, rrs, mysqlSelectQuery);

		//setOrderByCols
		if(mysqlSelectQuery.getOrderBy() != null) {
			List<SQLSelectOrderByItem> orderByItems = mysqlSelectQuery.getOrderBy().getItems();
			rrs.setOrderByCols(buildOrderByCols(orderByItems,aliaColumns));
		}
		isNeedParseOrderAgg=false;
	}
 
Example 2
/**
 * 解析 SQL 获取指定表及条件列的值
 * 
 * @param sql
 * @param tableName
 * @param colnumName
 * @return
 */
public List<Object> parseConditionValues(String sql, String tableName, String colnumName)  {
	
	List<Object> values = null;
	
	if ( sql != null && tableName != null && columnName != null ) {
	
		values = new ArrayList<Object>();
		
		MySqlStatementParser parser = new MySqlStatementParser(sql);
		SQLStatement stmt = parser.parseStatement();
		
		MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
		stmt.accept(visitor);
		
		String currentTable = visitor.getCurrentTable();
		if ( tableName.equalsIgnoreCase( currentTable ) ) {
			
			List<Condition> conditions = visitor.getConditions();
			for(Condition condition: conditions) {
				
				String ccN = condition.getColumn().getName();
				ccN = fixName(ccN);
				
				if ( colnumName.equalsIgnoreCase( ccN ) ) {					
					List<Object> ccVL = condition.getValues();
					values.addAll( ccVL );
				}
			}
		}				
	}
	return values;
}
 
Example 3
Source Project: azeroth   Source File: SqlParseUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    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);

    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    statemen.accept(visitor);

    System.out.println(visitor.getTables());

    System.out.println(visitor.getColumns());

    System.out.println(visitor.getConditions());
}
 
Example 4
Source Project: jeesuite-libs   Source File: SqlParseUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	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);
	 
	MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
	statemen.accept(visitor);
	
	System.out.println(visitor.getTables());
	
	System.out.println(visitor.getColumns());
	
	System.out.println(visitor.getConditions());
}