提交 798490bc authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Avoid StatementBuilder.appendOnlyFirst()

上级 130a9f2d
...@@ -20,7 +20,6 @@ import org.h2.table.Column; ...@@ -20,7 +20,6 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.table.TableLink; import org.h2.table.TableLink;
import org.h2.util.StatementBuilder;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.TypeInfo; import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -89,20 +88,20 @@ public class LinkedIndex extends BaseIndex { ...@@ -89,20 +88,20 @@ public class LinkedIndex extends BaseIndex {
@Override @Override
public Cursor find(Session session, SearchRow first, SearchRow last) { public Cursor find(Session session, SearchRow first, SearchRow last) {
ArrayList<Value> params = Utils.newSmallArrayList(); ArrayList<Value> params = Utils.newSmallArrayList();
StatementBuilder buff = new StatementBuilder("SELECT * FROM "); StringBuilder builder = new StringBuilder("SELECT * FROM ").append(targetTableName).append(" T");
buff.append(targetTableName).append(" T"); boolean f = false;
for (int i = 0; first != null && i < first.getColumnCount(); i++) { for (int i = 0; first != null && i < first.getColumnCount(); i++) {
Value v = first.getValue(i); Value v = first.getValue(i);
if (v != null) { if (v != null) {
buff.appendOnlyFirst(" WHERE "); builder.append(f ? " AND " : " WHERE ");
buff.appendExceptFirst(" AND "); f = true;
Column col = table.getColumn(i); Column col = table.getColumn(i);
col.getSQL(buff.builder()); col.getSQL(builder);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
buff.append(" IS NULL"); builder.append(" IS NULL");
} else { } else {
buff.append(">="); builder.append(">=");
addParameter(buff.builder(), col); addParameter(builder, col);
params.add(v); params.add(v);
} }
} }
...@@ -110,20 +109,20 @@ public class LinkedIndex extends BaseIndex { ...@@ -110,20 +109,20 @@ public class LinkedIndex extends BaseIndex {
for (int i = 0; last != null && i < last.getColumnCount(); i++) { for (int i = 0; last != null && i < last.getColumnCount(); i++) {
Value v = last.getValue(i); Value v = last.getValue(i);
if (v != null) { if (v != null) {
buff.appendOnlyFirst(" WHERE "); builder.append(f ? " AND " : " WHERE ");
buff.appendExceptFirst(" AND "); f = true;
Column col = table.getColumn(i); Column col = table.getColumn(i);
col.getSQL(buff.builder()); col.getSQL(builder);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
buff.append(" IS NULL"); builder.append(" IS NULL");
} else { } else {
buff.append("<="); builder.append("<=");
addParameter(buff.builder(), col); addParameter(builder, col);
params.add(v); params.add(v);
} }
} }
} }
String sql = buff.toString(); String sql = builder.toString();
try { try {
PreparedStatement prep = link.execute(sql, params, false); PreparedStatement prep = link.execute(sql, params, false);
ResultSet rs = prep.getResultSet(); ResultSet rs = prep.getResultSet();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论