public class SQLClob
{
protected static final int MAX_STRING_LITERAL_LENGTH = 3904;
public final String value;
public SQLClob(String value)
{
this.value = value;
}
// @SuppressWarnings("ConstantConditions")
public void appendTo(StringBuilder sql)
{
if (value == null)
{
sql.append("to_clob(null)");
return;
}
else if (value.isEmpty())
{
sql.append("empty_clob()");
return;
}
for (int i = 0, j, n = value.length(); i < n; i = j)
{
if (i > 0) sql.append(" ||");
j = Math.min(i + MAX_STRING_LITERAL_LENGTH, n);
sql.append("to_clob('")
.append(value.substring(i, j).replace("'", "''"))
.append("')");
}
}
}