提交 85b6ffd6 authored 作者: Thomas Mueller's avatar Thomas Mueller

LINKED TABLE: worked around a bug in Oracle with the CHAR data type.

上级 4f2cb320
......@@ -16,6 +16,7 @@ import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.TableLink;
import org.h2.value.Value;
......@@ -90,8 +91,10 @@ public class LinkedIndex extends BaseIndex {
if (buff.length() != 0) {
buff.append(" AND ");
}
buff.append(table.getColumn(i).getSQL());
buff.append(">=?");
Column col = table.getColumn(i);
buff.append(col.getSQL());
buff.append(">=");
addParameter(buff, col);
}
}
for (int i = 0; last != null && i < last.getColumnCount(); i++) {
......@@ -100,8 +103,10 @@ public class LinkedIndex extends BaseIndex {
if (buff.length() != 0) {
buff.append(" AND ");
}
buff.append(table.getColumn(i).getSQL());
buff.append("<=?");
Column col = table.getColumn(i);
buff.append(col.getSQL());
buff.append("<=");
addParameter(buff, col);
}
}
if (buff.length() > 0) {
......@@ -132,6 +137,20 @@ public class LinkedIndex extends BaseIndex {
throw wrapException(sql, e);
}
}
private void addParameter(StringBuffer buff, Column col) {
if (col.getType() == Value.STRING_FIXED && link.isOracle()) {
// workaround for Oracle
// create table test(id int primary key, name char(15));
// insert into test values(1, 'Hello')
// select * from test where name = ? -- where ? = "Hello" > no rows
buff.append("CAST(? AS CHAR(");
buff.append(col.getPrecision());
buff.append("))");
} else {
buff.append("?");
}
}
public double getCost(Session session, int[] masks) {
return 100 + getCostRangeIndex(masks, rowCount + Constants.COST_ROW_OFFSET);
......@@ -171,12 +190,15 @@ public class LinkedIndex extends BaseIndex {
if (i > 0) {
buff.append("AND ");
}
buff.append(table.getColumn(i).getSQL());
Column col = table.getColumn(i);
buff.append(col.getSQL());
Value v = row.getValue(i);
if (isNull(v)) {
buff.append(" IS NULL ");
} else {
buff.append("=? ");
buff.append('=');
addParameter(buff, col);
buff.append(' ');
}
}
String sql = buff.toString();
......@@ -217,12 +239,15 @@ public class LinkedIndex extends BaseIndex {
if (i > 0) {
buff.append("AND ");
}
buff.append(table.getColumn(i).getSQL());
Column col = table.getColumn(i);
buff.append(col.getSQL());
Value v = oldRow.getValue(i);
if (isNull(v)) {
buff.append(" IS NULL ");
} else {
buff.append("=? ");
buff.append('=');
addParameter(buff, col);
buff.append(' ');
}
}
String sql = buff.toString();
......
......@@ -391,6 +391,10 @@ public class TableLink extends Table {
prepared = null;
invalidate();
}
public boolean isOracle() {
return url.startsWith("jdbc:oracle:");
}
public ObjectArray getIndexes() {
return indexes;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论