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

H2 Console: when loading the schema, incorrect JDBC calls where issued, which…

H2 Console: when loading the schema, incorrect JDBC calls where issued, which caused the exception "Column PRECISION not found".
上级 3be159f0
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Improved Geometry processing (issue 535). <ul><li>H2 Console: when loading the schema, incorrect JDBC calls where issued, which caused
the exception "Column PRECISION not found".
</li><li>Improved Geometry processing (issue 535).
</li><li>The collation can now be set in the database URL, even if there are data tables, </li><li>The collation can now be set in the database URL, even if there are data tables,
if the collection is the same as the current collation. if the collection is the same as the current collation.
</li><li>Improved Oracle compatibility for CASE WHEN and DECODE. </li><li>Improved Oracle compatibility for CASE WHEN and DECODE.
......
...@@ -24,24 +24,24 @@ public class DbColumn { ...@@ -24,24 +24,24 @@ public class DbColumn {
private int position; private int position;
public DbColumn(DbContents contents, ResultSet rs) throws SQLException { public DbColumn(DbContents contents, ResultSet rs, boolean prodecureColumn) throws SQLException {
name = rs.getString("COLUMN_NAME"); name = rs.getString("COLUMN_NAME");
quotedName = contents.quoteIdentifier(name); quotedName = contents.quoteIdentifier(name);
String type = rs.getString("TYPE_NAME"); String type = rs.getString("TYPE_NAME");
// a procedures column size is identified by PRECISION, for table this // a procedures column size is identified by PRECISION, for table this
// is COLUMN_SIZE // is COLUMN_SIZE
int precisionColumnIndex = DbContents.findColumn(rs, "PRECISION", 0); String columnSizeName;
int size; if (prodecureColumn) {
if (precisionColumnIndex == 0) { columnSizeName = "PRECISION";
size = rs.getInt(DbContents.findColumn(rs, "COLUMN_SIZE", 7));
} else { } else {
size = rs.getInt(precisionColumnIndex); columnSizeName = "COLUMN_SIZE";
} }
int size = rs.getInt(columnSizeName);
position = rs.getInt("ORDINAL_POSITION"); position = rs.getInt("ORDINAL_POSITION");
boolean isSQLite = contents.isSQLite(); boolean isSQLite = contents.isSQLite();
if (size > 0 && !isSQLite) { if (size > 0 && !isSQLite) {
type += "(" + size; type += "(" + size;
int prec = rs.getInt(DbContents.findColumn(rs, "DECIMAL_DIGITS", 9)); int prec = rs.getInt("DECIMAL_DIGITS");
if (prec > 0) { if (prec > 0) {
type += ", " + prec; type += ", " + prec;
} }
......
...@@ -9,6 +9,7 @@ package org.h2.bnf.context; ...@@ -9,6 +9,7 @@ package org.h2.bnf.context;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -117,13 +118,22 @@ public class DbContents { ...@@ -117,13 +118,22 @@ public class DbContents {
* This is a workaround for a JDBC-ODBC bridge problem. * This is a workaround for a JDBC-ODBC bridge problem.
* *
* @param rs the result set * @param rs the result set
* @param columnName the column name * @param columnLabel the column name
* @param defaultColumnIndex the default column index * @param defaultColumnIndex the default column index
* @return the column index * @return the column index
*/ */
public static int findColumn(ResultSet rs, String columnName, int defaultColumnIndex) { public static int findColumn(ResultSet rs, String columnLabel, int defaultColumnIndex) {
try { try {
return rs.findColumn(columnName); // don't use ResultSet.findColumn because that would throw an
// exception, and we don't want to use exception handling for flow
// control
ResultSetMetaData meta = rs.getMetaData();
for (int i = 1; i <= meta.getColumnCount(); i++) {
if (meta.getColumnLabel(i).equalsIgnoreCase(columnLabel)) {
return i;
}
}
return defaultColumnIndex;
} catch (SQLException e) { } catch (SQLException e) {
return defaultColumnIndex; return defaultColumnIndex;
} }
...@@ -204,7 +214,7 @@ public class DbContents { ...@@ -204,7 +214,7 @@ public class DbContents {
ResultSet rs = meta.getSchemas(); ResultSet rs = meta.getSchemas();
ArrayList<String> schemaList = New.arrayList(); ArrayList<String> schemaList = New.arrayList();
while (rs.next()) { while (rs.next()) {
String schema = rs.getString(findColumn(rs, "TABLE_SCHEM", 1)); String schema = rs.getString("TABLE_SCHEM");
String[] ignoreNames = null; String[] ignoreNames = null;
if (isOracle) { if (isOracle) {
ignoreNames = new String[] { "CTXSYS", "DIP", "DBSNMP", ignoreNames = new String[] { "CTXSYS", "DIP", "DBSNMP",
......
...@@ -76,7 +76,7 @@ public class DbProcedure { ...@@ -76,7 +76,7 @@ public class DbProcedure {
ResultSet rs = meta.getProcedureColumns(null, schema.name, name, null); ResultSet rs = meta.getProcedureColumns(null, schema.name, name, null);
ArrayList<DbColumn> list = New.arrayList(); ArrayList<DbColumn> list = New.arrayList();
while (rs.next()) { while (rs.next()) {
DbColumn column = new DbColumn(schema.getContents(), rs); DbColumn column = new DbColumn(schema.getContents(), rs, true);
if (column.getPosition() > 0) { if (column.getPosition() > 0) {
// Not the return type // Not the return type
list.add(column); list.add(column);
......
...@@ -95,7 +95,7 @@ public class DbTableOrView { ...@@ -95,7 +95,7 @@ public class DbTableOrView {
ResultSet rs = meta.getColumns(null, schema.name, name, null); ResultSet rs = meta.getColumns(null, schema.name, name, null);
ArrayList<DbColumn> list = New.arrayList(); ArrayList<DbColumn> list = New.arrayList();
while (rs.next()) { while (rs.next()) {
DbColumn column = new DbColumn(schema.getContents(), rs); DbColumn column = new DbColumn(schema.getContents(), rs, false);
list.add(column); list.add(column);
} }
rs.close(); rs.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论