提交 231990d4 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 313: NullPointerException in select query with a subquery or view.

上级 c2ac2eb8
...@@ -22,6 +22,7 @@ import org.h2.result.SearchRow; ...@@ -22,6 +22,7 @@ import org.h2.result.SearchRow;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.util.IntArray; import org.h2.util.IntArray;
import org.h2.util.New;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -264,11 +265,10 @@ public class ViewIndex extends BaseIndex { ...@@ -264,11 +265,10 @@ public class ViewIndex extends BaseIndex {
} }
} }
int len = paramIndex.size(); int len = paramIndex.size();
columns = new Column[len]; ArrayList<Column> columnList = New.arrayList();
for (int i = 0; i < len;) { for (int i = 0; i < len;) {
int idx = paramIndex.get(i); int idx = paramIndex.get(i);
Column col = table.getColumn(idx); columnList.add(table.getColumn(idx));
columns[i] = col;
int mask = masks[idx]; int mask = masks[idx];
if ((mask & IndexCondition.EQUALITY) == IndexCondition.EQUALITY) { if ((mask & IndexCondition.EQUALITY) == IndexCondition.EQUALITY) {
Parameter param = new Parameter(firstIndexParam + i); Parameter param = new Parameter(firstIndexParam + i);
...@@ -287,6 +287,8 @@ public class ViewIndex extends BaseIndex { ...@@ -287,6 +287,8 @@ public class ViewIndex extends BaseIndex {
} }
} }
} }
columns = new Column[columnList.size()];
columnList.toArray(columns);
String sql = q.getPlanSQL(); String sql = q.getPlanSQL();
q = (Query) session.prepare(sql, true); q = (Query) session.prepare(sql, true);
return q; return q;
......
...@@ -30,6 +30,7 @@ public class TestView extends TestBase { ...@@ -30,6 +30,7 @@ public class TestView extends TestBase {
} }
public void test() throws SQLException { public void test() throws SQLException {
testEmptyColumn();
testChangeSchemaSearchPath(); testChangeSchemaSearchPath();
testParameterizedView(); testParameterizedView();
testCache(); testCache();
...@@ -41,6 +42,16 @@ public class TestView extends TestBase { ...@@ -41,6 +42,16 @@ public class TestView extends TestBase {
deleteDb("view"); deleteDb("view");
} }
private void testEmptyColumn() throws SQLException {
deleteDb("view");
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
stat.execute("create table test(a int, b int)");
stat.execute("create view test_view as select a, b from test");
stat.execute("select * from test_view where a between 1 and 2 and b = 2");
conn.close();
}
private void testChangeSchemaSearchPath() throws SQLException { private void testChangeSchemaSearchPath() throws SQLException {
deleteDb("view"); deleteDb("view");
Connection conn = getConnection("view;FUNCTIONS_IN_SCHEMA=TRUE"); Connection conn = getConnection("view;FUNCTIONS_IN_SCHEMA=TRUE");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论