提交 354a8a9f authored 作者: Noel Grandin's avatar Noel Grandin

revert "PR #392, Table alias get lost on joins"

since it breaks all the tests.

this reverts commit 37641c9a
上级 1c2a4307
...@@ -21,8 +21,6 @@ Change Log ...@@ -21,8 +21,6 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>PR #392, Table alias get lost on joins, patch from jknack
</li>
<li>PR #389, Handle LocalTime with nanosecond resolution, patch by katzyn <li>PR #389, Handle LocalTime with nanosecond resolution, patch by katzyn
</li> </li>
<li>PR #382, Recover for "page store" H2 breaks LOBs consistency, patch by vitalus <li>PR #382, Recover for "page store" H2 breaks LOBs consistency, patch by vitalus
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
package org.h2.expression; package org.h2.expression;
import java.util.HashMap; import java.util.HashMap;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.dml.Select; import org.h2.command.dml.Select;
...@@ -249,9 +248,13 @@ public class ExpressionColumn extends Expression { ...@@ -249,9 +248,13 @@ public class ExpressionColumn extends Expression {
@Override @Override
public String getAlias() { public String getAlias() {
String table = tableAlias == null ? "" : tableAlias + "."; if (column != null) {
String columnName = column == null ? this.columnName : column.getName(); return column.getName();
return table + columnName; }
if (tableAlias != null) {
return tableAlias + "." + columnName;
}
return columnName;
} }
@Override @Override
......
...@@ -108,7 +108,6 @@ import org.h2.test.jdbcx.TestConnectionPool; ...@@ -108,7 +108,6 @@ import org.h2.test.jdbcx.TestConnectionPool;
import org.h2.test.jdbcx.TestDataSource; import org.h2.test.jdbcx.TestDataSource;
import org.h2.test.jdbcx.TestXA; import org.h2.test.jdbcx.TestXA;
import org.h2.test.jdbcx.TestXASimple; import org.h2.test.jdbcx.TestXASimple;
import org.h2.test.lostalias.LostAliasTest;
import org.h2.test.mvcc.TestMvcc1; import org.h2.test.mvcc.TestMvcc1;
import org.h2.test.mvcc.TestMvcc2; import org.h2.test.mvcc.TestMvcc2;
import org.h2.test.mvcc.TestMvcc3; import org.h2.test.mvcc.TestMvcc3;
...@@ -797,9 +796,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -797,9 +796,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestQueryCache()); addTest(new TestQueryCache());
addTest(new TestUrlJavaObjectSerializer()); addTest(new TestUrlJavaObjectSerializer());
addTest(new TestWeb()); addTest(new TestWeb());
// #392: Table alias get lost
addTest(new LostAliasTest());
runAddedTests(1); runAddedTests(1);
...@@ -878,7 +874,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -878,7 +874,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestValue()); addTest(new TestValue());
addTest(new TestValueHashMap()); addTest(new TestValueHashMap());
addTest(new TestWeb()); addTest(new TestWeb());
runAddedTests(); runAddedTests();
......
package org.h2.test.lostalias;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
public class LostAliasTest extends TestBase {
public static void main(final String[] args) throws Exception {
TestBase.createCaller().init().test();
}
@Override
public void test() throws Exception {
shouldNotLostAlias();
}
private void shouldNotLostAlias() throws SQLException {
DeleteDbFiles.execute(getBaseDir(), "lostalias", true);
Connection conn = getConnection("lostalias");
Statement stat = conn.createStatement();
stat.execute("create table entry(id int, region int, author int)");
stat.execute("create table meta(id int, type varchar(255), value varchar(255))");
stat.execute("create table person(id int, name varchar(255))");
stat.execute("insert into person(id, name) values(3, 'edgar')");
stat.execute("insert into meta(id, type, value) values(2, 'Region', 'LATAM')");
stat.execute("insert into entry(id, region, author) values(1, 2, 3)");
ResultSet rs = stat.executeQuery("select entry.*, region.*, author.* from entry entry join meta region on entry.region=region.id join person author on entry.author=author.id");
while (rs.next()) {
assertEquals(1, rs.getInt("entry.id"));
assertEquals(2, rs.getInt("region.id"));
assertEquals("Region", rs.getString("region.type"));
assertEquals("LATAM", rs.getString("region.value"));
assertEquals(3, rs.getInt("author.id"));
assertEquals("edgar", rs.getString("author.name"));
}
rs.close();
stat.close();
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论