提交 ff192980 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue #127: Linked tables now support geometry columns.

上级 357f9251
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #127: Linked tables now support geometry columns.
</li>
<li>ABS(CAST(0.0 AS DOUBLE)) returned -0.0 instead of 0.0. <li>ABS(CAST(0.0 AS DOUBLE)) returned -0.0 instead of 0.0.
</li> </li>
<li>BNF auto-completion failed with unquoted identifiers. <li>BNF auto-completion failed with unquoted identifiers.
......
...@@ -150,12 +150,13 @@ public class TableLink extends Table { ...@@ -150,12 +150,13 @@ public class TableLink extends Table {
String n = rs.getString("COLUMN_NAME"); String n = rs.getString("COLUMN_NAME");
n = convertColumnName(n); n = convertColumnName(n);
int sqlType = rs.getInt("DATA_TYPE"); int sqlType = rs.getInt("DATA_TYPE");
String sqlTypeName = rs.getString("TYPE_NAME");
long precision = rs.getInt("COLUMN_SIZE"); long precision = rs.getInt("COLUMN_SIZE");
precision = convertPrecision(sqlType, precision); precision = convertPrecision(sqlType, precision);
int scale = rs.getInt("DECIMAL_DIGITS"); int scale = rs.getInt("DECIMAL_DIGITS");
scale = convertScale(sqlType, scale); scale = convertScale(sqlType, scale);
int displaySize = MathUtils.convertLongToInt(precision); int displaySize = MathUtils.convertLongToInt(precision);
int type = DataType.convertSQLTypeToValueType(sqlType); int type = DataType.convertSQLTypeToValueType(sqlType, sqlTypeName);
Column col = new Column(n, type, precision, scale, displaySize); Column col = new Column(n, type, precision, scale, displaySize);
col.setTable(this, i++); col.setTable(this, i++);
columnList.add(col); columnList.add(col);
......
...@@ -18,6 +18,7 @@ import java.sql.Timestamp; ...@@ -18,6 +18,7 @@ import java.sql.Timestamp;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.value.DataType;
/** /**
* Tests the linked table feature (CREATE LINKED TABLE). * Tests the linked table feature (CREATE LINKED TABLE).
...@@ -52,7 +53,7 @@ public class TestLinkedTable extends TestBase { ...@@ -52,7 +53,7 @@ public class TestLinkedTable extends TestBase {
testLinkTwoTables(); testLinkTwoTables();
testCachingResults(); testCachingResults();
testLinkedTableInReadOnlyDb(); testLinkedTableInReadOnlyDb();
testGeometry();
deleteDb("linkedTable"); deleteDb("linkedTable");
} }
...@@ -693,4 +694,35 @@ public class TestLinkedTable extends TestBase { ...@@ -693,4 +694,35 @@ public class TestLinkedTable extends TestBase {
deleteDb("testLinkedTableInReadOnlyDb"); deleteDb("testLinkedTableInReadOnlyDb");
} }
private void testGeometry() throws SQLException {
if (!config.mvStore && config.mvcc) {
return;
}
if (config.memory && config.mvcc) {
return;
}
if (DataType.GEOMETRY_CLASS == null) {
return;
}
org.h2.Driver.load();
Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
Connection cb = DriverManager.getConnection("jdbc:h2:mem:two", "sa", "sa");
Statement sa = ca.createStatement();
Statement sb = cb.createStatement();
sa.execute("CREATE TABLE TEST(ID SERIAL, the_geom geometry)");
sa.execute("INSERT INTO TEST(THE_GEOM) VALUES('POINT (1 1)')");
String sql = "CREATE LINKED TABLE T(NULL, " +
"'jdbc:h2:mem:one', 'sa', 'sa', 'TEST') READONLY";
sb.execute(sql);
ResultSet rs = sb.executeQuery("SELECT * FROM T");
try {
assertTrue(rs.next());
assertEquals("POINT (1 1)", rs.getString("THE_GEOM"));
} finally {
rs.close();
}
sb.execute("DROP TABLE T");
ca.close();
cb.close();
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论