Search in sources :

Example 36 with StatementBuilder

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

the class JdbcDatabaseMetaData method getFunctions.

private String getFunctions(String section) throws SQLException {
    try {
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC " + "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?");
        prep.setString(1, section);
        ResultSet rs = prep.executeQuery();
        StatementBuilder buff = new StatementBuilder();
        while (rs.next()) {
            String s = rs.getString(1).trim();
            String[] array = StringUtils.arraySplit(s, ',', true);
            for (String a : array) {
                buff.appendExceptFirst(",");
                String f = a.trim();
                if (f.indexOf(' ') >= 0) {
                    // remove 'Function' from 'INSERT Function'
                    f = f.substring(0, f.indexOf(' ')).trim();
                }
                buff.append(f);
            }
        }
        rs.close();
        prep.close();
        return buff.toString();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : StatementBuilder(org.h2.util.StatementBuilder) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 37 with StatementBuilder

use of org.h2.util.StatementBuilder in project ignite by apache.

the class GridSqlMerge method getSQL.

/**
 * {@inheritDoc}
 */
@Override
public String getSQL() {
    char delim = delimeter();
    StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
    buff.append("MERGE INTO ").append(into.getSQL()).append('(');
    for (GridSqlColumn col : cols) {
        buff.appendExceptFirst(", ");
        buff.append(delim).append(col.getSQL());
    }
    buff.append(delim).append(')').append(delim);
    if (!rows.isEmpty()) {
        buff.append("VALUES").append(delim);
        StatementBuilder valuesBuff = new StatementBuilder();
        for (GridSqlElement[] row : rows()) {
            valuesBuff.appendExceptFirst("," + delim);
            StatementBuilder rowBuff = new StatementBuilder("(");
            for (GridSqlElement e : row) {
                rowBuff.appendExceptFirst(", ");
                rowBuff.append(e != null ? e.getSQL() : "DEFAULT");
            }
            rowBuff.append(')');
            valuesBuff.append(rowBuff.toString());
        }
        buff.append(valuesBuff.toString());
    } else
        buff.append(delim).append(qry.getSQL());
    return buff.toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 38 with StatementBuilder

use of org.h2.util.StatementBuilder in project ignite by apache.

the class GridSqlUnion method getSQL.

/**
 * {@inheritDoc}
 */
@Override
public String getSQL() {
    char delim = delimeter();
    StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " + delim : "");
    buff.append('(').append(left.getSQL()).append(')');
    switch(unionType()) {
        case UNION_ALL:
            buff.append(delim).append("UNION ALL").append(delim);
            break;
        case UNION:
            buff.append(delim).append("UNION").append(delim);
            break;
        case INTERSECT:
            buff.append(delim).append("INTERSECT").append(delim);
            break;
        case EXCEPT:
            buff.append(delim).append("EXCEPT").append(delim);
            break;
        default:
            throw new CacheException("type=" + unionType);
    }
    buff.append('(').append(right.getSQL()).append(')');
    getSortLimitSQL(buff);
    return buff.toString();
}
Also used : CacheException(javax.cache.CacheException) StatementBuilder(org.h2.util.StatementBuilder)

Example 39 with StatementBuilder

use of org.h2.util.StatementBuilder in project ignite by apache.

the class GridSqlUpdate method getSQL.

/**
 * {@inheritDoc}
 */
@Override
public String getSQL() {
    char delim = delimeter();
    StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
    buff.append("UPDATE ").append(target.getSQL()).append(delim).append("SET").append(delim);
    for (GridSqlColumn c : cols) {
        GridSqlElement e = set.get(c.columnName());
        buff.appendExceptFirst("," + delim + "    ");
        buff.append(c.columnName()).append(" = ").append(e != null ? e.getSQL() : "DEFAULT");
    }
    if (where != null)
        buff.append(delim).append("WHERE ").append(StringUtils.unEnclose(where.getSQL()));
    if (limit != null)
        buff.append(delim).append("LIMIT ").append(StringUtils.unEnclose(limit.getSQL()));
    return buff.toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 40 with StatementBuilder

use of org.h2.util.StatementBuilder in project ignite by apache.

the class GridSqlAggregateFunction method getSQL.

/**
 * {@inheritDoc}
 */
@Override
public String getSQL() {
    if (type == COUNT_ALL)
        return "COUNT(*)";
    StatementBuilder buff = new StatementBuilder(name()).append('(');
    if (distinct)
        buff.append("DISTINCT ");
    buff.append(child().getSQL());
    if (!F.isEmpty(groupConcatOrderExpression)) {
        buff.append(" ORDER BY ");
        buff.resetCount();
        for (int i = 0; i < groupConcatOrderExpression.length; ++i) {
            buff.appendExceptFirst(", ");
            buff.append(groupConcatOrderExpression[i].getSQL());
            if (groupConcatOrderDesc[i])
                buff.append(" DESC");
        }
    }
    if (groupConcatSeparator != null)
        buff.append(" SEPARATOR ").append(groupConcatSeparator.getSQL());
    buff.append(')');
    return buff.toString();
}
Also used : 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