Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a2e677

Browse filesBrowse files
committed
Get data types directly from linked tables from H2
1 parent 69aff24 commit 4a2e677
Copy full SHA for 4a2e677

File tree

Expand file treeCollapse file tree

3 files changed

+28
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+28
-4
lines changed

‎h2/src/main/org/h2/jdbc/JdbcResultSet.java

Copy file name to clipboardExpand all lines: h2/src/main/org/h2/jdbc/JdbcResultSet.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4277,4 +4277,13 @@ public Value[] getUpdateRow() {
42774277
return updateRow;
42784278
}
42794279

4280+
/**
4281+
* INTERNAL
4282+
*
4283+
* @return result
4284+
*/
4285+
public ResultInterface getResult() {
4286+
return result;
4287+
}
4288+
42804289
}

‎h2/src/main/org/h2/table/TableLink.java

Copy file name to clipboardExpand all lines: h2/src/main/org/h2/table/TableLink.java
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.h2.index.IndexType;
2525
import org.h2.index.LinkedIndex;
2626
import org.h2.jdbc.JdbcConnection;
27+
import org.h2.jdbc.JdbcResultSet;
2728
import org.h2.message.DbException;
2829
import org.h2.result.LocalResult;
30+
import org.h2.result.ResultInterface;
2931
import org.h2.result.Row;
3032
import org.h2.schema.Schema;
3133
import org.h2.util.JdbcUtils;
@@ -177,10 +179,20 @@ private void readMetaData() throws SQLException {
177179

178180
try (Statement stat = conn.getConnection().createStatement();
179181
ResultSet rs = stat.executeQuery("SELECT * FROM " + qualifiedTableName + " T WHERE 1=0")) {
180-
if (columnList.isEmpty()) {
182+
if (rs instanceof JdbcResultSet) {
183+
ResultInterface result = ((JdbcResultSet) rs).getResult();
184+
columnList.clear();
185+
columnMap.clear();
186+
for (int i = 0, l = result.getVisibleColumnCount(); i < l;) {
187+
String n = result.getColumnName(i);
188+
Column col = new Column(n, result.getColumnType(i), this, ++i);
189+
columnList.add(col);
190+
columnMap.put(n, col);
191+
}
192+
} else if (columnList.isEmpty()) {
181193
// alternative solution
182194
ResultSetMetaData rsMeta = rs.getMetaData();
183-
for (int i = 0; i < rsMeta.getColumnCount();) {
195+
for (int i = 0, l = rsMeta.getColumnCount(); i < l;) {
184196
String n = rsMeta.getColumnName(i + 1);
185197
n = convertColumnName(n);
186198
int sqlType = rsMeta.getColumnType(i + 1);

‎h2/src/test/org/h2/test/db/TestLinkedTable.java

Copy file name to clipboardExpand all lines: h2/src/test/org/h2/test/db/TestLinkedTable.java
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,17 @@ private void testGeometry() throws SQLException {
703703
Connection cb = DriverManager.getConnection("jdbc:h2:mem:two", "sa", "sa");
704704
Statement sa = ca.createStatement();
705705
Statement sb = cb.createStatement();
706-
sa.execute("CREATE TABLE TEST(ID SERIAL, the_geom geometry)");
707-
sa.execute("INSERT INTO TEST(THE_GEOM) VALUES('POINT (1 1)')");
706+
sa.execute("CREATE TABLE TEST(ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,"
707+
+ " THE_GEOM GEOMETRY, THE_GEOM_2 GEOMETRY(POINT, 4326))");
708+
sa.execute("INSERT INTO TEST(THE_GEOM, THE_GEOM_2) VALUES"
709+
+ " (GEOMETRY 'POINT (1 1)', GEOMETRY 'SRID=4326;POINT(2 2)')");
708710
String sql = "CREATE LINKED TABLE T(NULL, " +
709711
"'jdbc:h2:mem:one', 'sa', 'sa', 'TEST') READONLY";
710712
sb.execute(sql);
711713
try (ResultSet rs = sb.executeQuery("SELECT * FROM T")) {
712714
assertTrue(rs.next());
713715
assertEquals("POINT (1 1)", rs.getString("THE_GEOM"));
716+
assertEquals("SRID=4326;POINT (2 2)", rs.getString("THE_GEOM_2"));
714717
}
715718
sb.execute("DROP TABLE T");
716719
ca.close();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.