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);
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations