Search in sources :

Example 11 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class TableFunction method getSQL.

@Override
public String getSQL() {
    StatementBuilder buff = new StatementBuilder(getName());
    buff.append('(');
    int i = 0;
    for (Expression e : args) {
        buff.appendExceptFirst(", ");
        buff.append(columnList[i++].getCreateSQL()).append('=').append(e.getSQL());
    }
    return buff.append(')').toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 12 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class ConditionIn method getSQL.

@Override
public String getSQL() {
    StatementBuilder buff = new StatementBuilder("(");
    buff.append(left.getSQL()).append(" IN(");
    for (Expression e : valueList) {
        buff.appendExceptFirst(", ");
        buff.append(e.getSQL());
    }
    return buff.append("))").toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 13 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class BaseIndex method getColumnListSQL.

/**
 * Get the list of columns as a string.
 *
 * @return the list of columns
 */
private String getColumnListSQL() {
    StatementBuilder buff = new StatementBuilder();
    for (IndexColumn c : indexColumns) {
        buff.appendExceptFirst(", ");
        buff.append(c.getSQL());
    }
    return buff.toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder) IndexColumn(org.h2.table.IndexColumn)

Example 14 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class IndexCondition method getSQL.

/**
 * Get the SQL snippet of this comparison.
 *
 * @return the SQL snippet
 */
public String getSQL() {
    if (compareType == Comparison.FALSE) {
        return "FALSE";
    }
    StatementBuilder buff = new StatementBuilder();
    buff.append(column.getSQL());
    switch(compareType) {
        case Comparison.EQUAL:
            buff.append(" = ");
            break;
        case Comparison.EQUAL_NULL_SAFE:
            buff.append(" IS ");
            break;
        case Comparison.BIGGER_EQUAL:
            buff.append(" >= ");
            break;
        case Comparison.BIGGER:
            buff.append(" > ");
            break;
        case Comparison.SMALLER_EQUAL:
            buff.append(" <= ");
            break;
        case Comparison.SMALLER:
            buff.append(" < ");
            break;
        case Comparison.IN_LIST:
            buff.append(" IN(");
            for (Expression e : expressionList) {
                buff.appendExceptFirst(", ");
                buff.append(e.getSQL());
            }
            buff.append(')');
            break;
        case Comparison.IN_QUERY:
            buff.append(" IN(");
            buff.append(expressionQuery.getPlanSQL());
            buff.append(')');
            break;
        case Comparison.SPATIAL_INTERSECTS:
            buff.append(" && ");
            break;
        default:
            DbException.throwInternalError("type=" + compareType);
    }
    if (expression != null) {
        buff.append(expression.getSQL());
    }
    return buff.toString();
}
Also used : Expression(org.h2.expression.Expression) StatementBuilder(org.h2.util.StatementBuilder)

Example 15 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class Aggregate method getSQLArrayAggregate.

private String getSQLArrayAggregate() {
    StatementBuilder buff = new StatementBuilder("ARRAY_AGG(");
    if (distinct) {
        buff.append("DISTINCT ");
    }
    buff.append(on.getSQL());
    if (orderByList != null) {
        buff.append(" ORDER BY ");
        for (SelectOrderBy o : orderByList) {
            buff.appendExceptFirst(", ");
            buff.append(o.expression.getSQL());
            if (o.descending) {
                buff.append(" DESC");
            }
        }
    }
    buff.append(')');
    if (filterCondition != null) {
        buff.append(" FILTER (WHERE ").append(filterCondition.getSQL()).append(')');
    }
    return buff.toString();
}
Also used : SelectOrderBy(org.h2.command.dml.SelectOrderBy) StatementBuilder(org.h2.util.StatementBuilder)

Aggregations

StatementBuilder (org.h2.util.StatementBuilder)82 Value (org.h2.value.Value)16 Column (org.h2.table.Column)15 IndexColumn (org.h2.table.IndexColumn)11 PreparedStatement (java.sql.PreparedStatement)9 Expression (org.h2.expression.Expression)9 ValueString (org.h2.value.ValueString)7 Index (org.h2.index.Index)6 DbException (org.h2.message.DbException)6 ResultSet (java.sql.ResultSet)5 Row (org.h2.result.Row)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Constraint (org.h2.constraint.Constraint)3 Database (org.h2.engine.Database)3 ExpressionColumn (org.h2.expression.ExpressionColumn)3 HashMap (java.util.HashMap)2 SelectOrderBy (org.h2.command.dml.SelectOrderBy)2 ResultInterface (org.h2.result.ResultInterface)2 SearchRow (org.h2.result.SearchRow)2