提交 31bdf7ec authored 作者: Thomas Mueller's avatar Thomas Mueller

Prepared statements with nested subqueries did not always return the correct…

Prepared statements with nested subqueries did not always return the correct result. Example: select ?, ?, (select count(*) from test t, (select id from test where 0=?) t2 where t2.id=t.id) from test
上级 95772c64
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>When using MULTI_THREADED=TRUE, the exception following exception could be thrown:
<ul><li>Prepared statements with nested subqueries did not always return the correct result. Example:
select ?, ?, (select count(*) from test t, (select id from test where 0=?) t2 where t2.id=t.id) from test
</li><li>When using MULTI_THREADED=TRUE, the exception following exception could be thrown:
"object already exists: TABLES"
</li><li>Comparison of integer columns against float numbers was not always correct. Issue 182.
</li><li>H2 Console: Editing the result of a multi-line queries failed. Issue 183.
......
......@@ -950,12 +950,11 @@ public class Parser {
if (readIf("(")) {
if (isSelect()) {
int start = lastParseIndex;
int paramIndex = parameters.size();
Query query = parseSelectUnion();
read(")");
query = parseSelectUnionExtension(query, start, true);
ArrayList<Parameter> params = New.arrayList();
for (int i = paramIndex; i < parameters.size(); i++) {
for (int i = 0; i < parameters.size(); i++) {
params.add(parameters.get(i));
}
query.setParameterList(params);
......
......@@ -35,6 +35,7 @@ public class TestCases extends TestBase {
}
public void test() throws Exception {
testPreparedSubquery();
testCompareDoubleWithIntColumn();
testDeleteIndexOutOfBounds();
testOrderByWithSubselect();
......@@ -78,6 +79,28 @@ public class TestCases extends TestBase {
deleteDb("cases");
}
private void testPreparedSubquery() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
stat.execute("insert into test values(1)");
String sql = "select ?, ?, (select count(*) from test inner join " +
"(select id from test where 0=?) as t2 on t2.id=test.id) from test";
ResultSet rs;
rs = stat.executeQuery(sql.replace('?', '0'));
rs.next();
assertEquals(1, rs.getInt(3));
PreparedStatement prep = conn.prepareStatement(sql);
prep.setInt(1, 0);
prep.setInt(2, 0);
prep.setInt(3, 0);
rs = prep.executeQuery();
rs.next();
assertEquals(1, rs.getInt(3));
conn.close();
}
private void testCompareDoubleWithIntColumn() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论