提交 8516540e authored 作者: Noel Grandin's avatar Noel Grandin

Fix NPE in querying spatial data through a sub-select

上级 30ad944b
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Fix NPE in querying spatial data through a sub-select.
</li>
<li>Fix bug where a lock on the SYS table was not released when closing a session that contained a temp
table with an LOB column.
</li>
......
......@@ -164,7 +164,7 @@ public class IndexCursor implements Cursor {
if (!alwaysFalse) {
if (intersects != null && index instanceof SpatialIndex) {
cursor = ((SpatialIndex) index).findByGeometry(tableFilter,
intersects);
start, end, intersects);
} else {
cursor = index.find(tableFilter, start, end);
}
......
......@@ -24,6 +24,6 @@ public interface SpatialIndex extends Index {
* null for anything
* @return the cursor to iterate over the results
*/
Cursor findByGeometry(TableFilter filter, SearchRow intersection);
Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection);
}
......@@ -168,9 +168,9 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
}
@Override
public Cursor findByGeometry(TableFilter filter, SearchRow intersection) {
public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
if (intersection == null) {
return find(filter.getSession());
return find(filter.getSession(), first, last);
}
return new SpatialCursor(
treeMap.findIntersectingKeys(getKey(intersection)), table,
......
......@@ -160,8 +160,8 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
}
@Override
public Cursor findByGeometry(TableFilter filter, SearchRow intersection) {
return find(filter.getSession(), null, null, intersection);
public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
return find(filter.getSession(), first, last, intersection);
}
private static Query prepareSubQuery(String sql, Session session, int[] masks,
......
......@@ -197,10 +197,10 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
@Override
public Cursor findByGeometry(TableFilter filter, SearchRow intersection) {
public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
Session session = filter.getSession();
if (intersection == null) {
return find(session);
return find(session, first, last);
}
Iterator<SpatialKey> cursor =
spatialMap.findIntersectingKeys(getKey(intersection));
......
......@@ -39,7 +39,7 @@ import org.h2.value.ValueGeometry;
*/
public class TestSpatial extends TestBase {
private String url = "spatial";
private static final String url = "spatial";
/**
* Run just this test.
......@@ -60,13 +60,13 @@ public class TestSpatial extends TestBase {
}
if (DataType.GEOMETRY_CLASS != null) {
deleteDb("spatial");
url = "spatial";
testSpatial();
deleteDb("spatial");
}
}
private void testSpatial() throws SQLException {
testBug1();
testSpatialValues();
testOverlap();
testNotOverlap();
......@@ -94,6 +94,19 @@ public class TestSpatial extends TestBase {
testNullableGeometryInsert();
testNullableGeometryUpdate();
}
private void testBug1() throws SQLException {
deleteDb("spatial");
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE VECTORS (ID INTEGER NOT NULL, GEOM GEOMETRY, S INTEGER)");
stat.execute("INSERT INTO VECTORS(ID, GEOM, S) VALUES(0, 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))', 1)");
stat.executeQuery("select * from (select * from VECTORS) WHERE S=1 AND GEOM && 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'");
conn.close();
deleteDb("spatial");
}
private void testHashCode() {
ValueGeometry geomA = ValueGeometry
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论