Search in sources :

Example 6 with StatementBuilder

use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.

the class ExpressionList method exportParameters.

@Override
public String exportParameters(TableFilter filter, List<Value> container) {
    StatementBuilder buff = new StatementBuilder("(");
    for (Expression e : list) {
        buff.appendExceptFirst(", ");
        buff.append(e.exportParameters(filter, container));
    }
    if (list.length == 1) {
        buff.append(',');
    }
    return buff.append(')').toString();
}
Also used : StatementBuilder(com.wplatform.ddal.util.StatementBuilder)

Example 7 with StatementBuilder

use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.

the class Update method getPlanSQL.

@Override
public String getPlanSQL() {
    StatementBuilder buff = new StatementBuilder("UPDATE ");
    buff.append(tableFilter.getPlanSQL(false)).append("\nSET\n    ");
    for (int i = 0, size = columns.size(); i < size; i++) {
        Column c = columns.get(i);
        Expression e = expressionMap.get(c);
        buff.appendExceptFirst(",\n    ");
        buff.append(c.getName()).append(" = ").append(e.getSQL());
    }
    if (condition != null) {
        buff.append("\nWHERE ").append(StringUtils.unEnclose(condition.getSQL()));
    }
    return buff.toString();
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) ValueExpression(com.wplatform.ddal.command.expression.ValueExpression) Expression(com.wplatform.ddal.command.expression.Expression) StatementBuilder(com.wplatform.ddal.util.StatementBuilder)

Example 8 with StatementBuilder

use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.

the class Aggregate method getSQLGroupConcat.

private String getSQLGroupConcat() {
    StatementBuilder buff = new StatementBuilder("GROUP_CONCAT(");
    if (distinct) {
        buff.append("DISTINCT ");
    }
    buff.append(on.getSQL());
    if (groupConcatOrderList != null) {
        buff.append(" ORDER BY ");
        for (SelectOrderBy o : groupConcatOrderList) {
            buff.appendExceptFirst(", ");
            buff.append(o.expression.getSQL());
            if (o.descending) {
                buff.append(" DESC");
            }
        }
    }
    if (groupConcatSeparator != null) {
        buff.append(" SEPARATOR ").append(groupConcatSeparator.getSQL());
    }
    return buff.append(')').toString();
}
Also used : SelectOrderBy(com.wplatform.ddal.command.dml.SelectOrderBy) StatementBuilder(com.wplatform.ddal.util.StatementBuilder)

Example 9 with StatementBuilder

use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.

the class Aggregate method getValue.

@Override
public Value getValue(Session session) {
    HashMap<Expression, Object> group = select.getCurrentGroup();
    if (group == null) {
        throw DbException.get(ErrorCode.INVALID_USE_OF_AGGREGATE_FUNCTION_1, getSQL());
    }
    AggregateData data = (AggregateData) group.get(this);
    if (data == null) {
        data = AggregateData.create(type);
    }
    Value v = data.getValue(session.getDatabase(), dataType, distinct);
    if (type == GROUP_CONCAT) {
        ArrayList<Value> list = ((AggregateDataGroupConcat) data).getList();
        if (list == null || list.size() == 0) {
            return ValueNull.INSTANCE;
        }
        if (groupConcatOrderList != null) {
            final SortOrder sortOrder = groupConcatSort;
            Collections.sort(list, new Comparator<Value>() {

                @Override
                public int compare(Value v1, Value v2) {
                    Value[] a1 = ((ValueArray) v1).getList();
                    Value[] a2 = ((ValueArray) v2).getList();
                    return sortOrder.compare(a1, a2);
                }
            });
        }
        StatementBuilder buff = new StatementBuilder();
        String sep = groupConcatSeparator == null ? "," : groupConcatSeparator.getValue(session).getString();
        for (Value val : list) {
            String s;
            if (val.getType() == Value.ARRAY) {
                s = ((ValueArray) val).getList()[0].getString();
            } else {
                s = val.getString();
            }
            if (s == null) {
                continue;
            }
            if (sep != null) {
                buff.appendExceptFirst(sep);
            }
            buff.append(s);
        }
        v = ValueString.get(buff.toString());
    }
    return v;
}
Also used : StatementBuilder(com.wplatform.ddal.util.StatementBuilder) SortOrder(com.wplatform.ddal.result.SortOrder)

Example 10 with StatementBuilder

use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.

the class ConditionIn method exportParameters.

@Override
public String exportParameters(TableFilter filter, List<Value> container) {
    StatementBuilder buff = new StatementBuilder("(");
    buff.append(left.exportParameters(filter, container)).append(" IN(");
    for (Expression e : valueList) {
        buff.appendExceptFirst(", ");
        buff.append(e.exportParameters(filter, container));
    }
    return buff.append("))").toString();
}
Also used : StatementBuilder(com.wplatform.ddal.util.StatementBuilder)

Aggregations

StatementBuilder (com.wplatform.ddal.util.StatementBuilder)49 Value (com.wplatform.ddal.value.Value)13 Expression (com.wplatform.ddal.command.expression.Expression)9 Column (com.wplatform.ddal.dbobject.table.Column)8 PreparedStatement (java.sql.PreparedStatement)7 SQLException (java.sql.SQLException)4 IndexColumn (com.wplatform.ddal.dbobject.table.IndexColumn)3 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)3 Connection (java.sql.Connection)3 DataSource (javax.sql.DataSource)3 Index (com.wplatform.ddal.dbobject.index.Index)2 JdbcWorker (com.wplatform.ddal.excutor.JdbcWorker)2 DbException (com.wplatform.ddal.message.DbException)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 AlterTableAddConstraint (com.wplatform.ddal.command.ddl.AlterTableAddConstraint)1 AlterTableAlterColumn (com.wplatform.ddal.command.ddl.AlterTableAlterColumn)1