use of org.h2.value.ValueString in project h2database by h2database.
the class Function method getSQL.
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(info.name);
if (info.type == CASE) {
if (args[0] != null) {
buff.append(" ").append(args[0].getSQL());
}
for (int i = 1, len = args.length - 1; i < len; i += 2) {
buff.append(" WHEN ").append(args[i].getSQL());
buff.append(" THEN ").append(args[i + 1].getSQL());
}
if (args.length % 2 == 0) {
buff.append(" ELSE ").append(args[args.length - 1].getSQL());
}
return buff.append(" END").toString();
}
buff.append('(');
switch(info.type) {
case CAST:
{
buff.append(args[0].getSQL()).append(" AS ").append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
break;
}
case CONVERT:
{
if (database.getMode().swapConvertFunctionParameters) {
buff.append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL()).append(',').append(args[0].getSQL());
} else {
buff.append(args[0].getSQL()).append(',').append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
}
break;
}
case EXTRACT:
{
ValueString v = (ValueString) ((ValueExpression) args[0]).getValue(null);
buff.append(v.getString()).append(" FROM ").append(args[1].getSQL());
break;
}
default:
{
for (Expression e : args) {
buff.appendExceptFirst(", ");
buff.append(e.getSQL());
}
}
}
return buff.append(')').toString();
}
use of org.h2.value.ValueString in project ignite by apache.
the class GridSqlFunction method getSQL.
/**
* {@inheritDoc}
*/
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder();
if (schema != null)
buff.append(Parser.quoteIdentifier(schema)).append('.');
// We don't need to quote identifier as long as H2 never does so with function names when generating plan SQL.
// On the other hand, quoting identifiers that also serve as keywords (like CURRENT_DATE() and CURRENT_DATE)
// turns CURRENT_DATE() into "CURRENT_DATE"(), which is not good.
buff.append(name);
if (type == CASE) {
buff.append(' ').append(child().getSQL());
for (int i = 1, len = size() - 1; i < len; i += 2) {
buff.append(" WHEN ").append(child(i).getSQL());
buff.append(" THEN ").append(child(i + 1).getSQL());
}
if ((size() & 1) == 0)
buff.append(" ELSE ").append(child(size() - 1).getSQL());
return buff.append(" END").toString();
}
buff.append('(');
switch(type) {
case CAST:
case CONVERT:
assert size() == 1;
String castType = resultType().sql();
assert !F.isEmpty(castType) : castType;
buff.append(child().getSQL());
buff.append(type == CAST ? " AS " : ",");
buff.append(castType);
break;
case EXTRACT:
ValueString v = (ValueString) ((GridSqlConst) child(0)).value();
buff.append(v.getString()).append(" FROM ").append(child(1).getSQL());
break;
case TABLE:
for (int i = 0; i < size(); i++) {
buff.appendExceptFirst(", ");
GridSqlElement e = child(i);
// id int = ?, name varchar = ('aaa', 'bbb')
buff.append(Parser.quoteIdentifier(((GridSqlAlias) e).alias())).append(' ').append(e.resultType().sql()).append('=').append(e.child().getSQL());
}
break;
default:
for (int i = 0; i < size(); i++) {
buff.appendExceptFirst(", ");
buff.append(child(i).getSQL());
}
}
return buff.append(')').toString();
}
Aggregations