Java Code Examples for com.alibaba.druid.sql.SQLUtils#toSQLString()

The following examples show how to use com.alibaba.druid.sql.SQLUtils#toSQLString() . 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
protected void setLimitIFChange(SQLStatement stmt, RouteResultset rrs, SchemaConfig schema, SQLBinaryOpExpr one, int firstrownum, int lastrownum)
{
	rrs.setLimitStart(firstrownum);
	rrs.setLimitSize(lastrownum - firstrownum);
	LayerCachePool tableId2DataNodeCache = (LayerCachePool) MycatServer.getInstance().getCacheService().getCachePool("TableID2DataNodeCache");
	try
	{
		tryRoute(schema, rrs, tableId2DataNodeCache);
	} catch (SQLNonTransientException e)
	{
		throw new RuntimeException(e);
	}
	if (isNeedChangeLimit(rrs))
	{
		one.setRight(new SQLIntegerExpr(0));
		String curentDbType ="db2".equalsIgnoreCase(this.getCurentDbType())?"oracle":getCurentDbType();
		String sql =   SQLUtils.toSQLString(stmt, curentDbType);;
		rrs.changeNodeSqlAfterAddLimit(schema,getCurentDbType(), sql,0,lastrownum, false);
		//设置改写后的sql
		getCtx().setSql(sql);
	}
}
 
Example 2
Source File: ElasticSearchPreparedStatement.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
public String getExecutableSql() {
    if (parametersSize < 1) {
        return sql;
    }

    List<Object> parameters = new ArrayList<>(parametersSize);
    JdbcParameter jdbcParam;
    for (int i = 0; i < parametersSize; ++i) {
        jdbcParam = this.parameters[i];
        parameters.add(jdbcParam != null ? jdbcParam.getValue() : null);
    }

    try {
        SQLStatementParser parser = ESActionFactory.createSqlStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        return SQLUtils.toSQLString(statementList, JdbcConstants.MYSQL, parameters, sqlFormatOption);
    } catch (ClassCastException | ParserException ex) {
        LOG.warn("format error", ex);
        return sql;
    }
}
 
Example 3
Source File: SelectParser.java    From dts with Apache License 2.0 5 votes vote down vote up
@Override
protected String getWhere(SQLSelectStatement parseSqlStatement) {
    SQLSelectQueryBlock selectQueryBlock = parseSqlStatement.getSelect().getQueryBlock();
    SQLExpr where = selectQueryBlock.getWhere();
    if (where == null) {
        return "";
    }
    return SQLUtils.toSQLString(where);

}
 
Example 4
Source File: DeleteParser.java    From dts with Apache License 2.0 4 votes vote down vote up
@Override
protected String getWhere(MySqlDeleteStatement parseSqlStatement) {
    return SQLUtils.toSQLString(parseSqlStatement.getWhere());
}
 
Example 5
Source File: UpdateParser.java    From dts with Apache License 2.0 4 votes vote down vote up
@Override
protected String getWhere(SQLUpdateStatement parseSqlStatement) {
    return SQLUtils.toSQLString(parseSqlStatement.getWhere());
}