提交 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
<h1>Change Log</h1>
<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,
if the collection is the same as the current collation.
</li><li>Improved Oracle compatibility for CASE WHEN and DECODE.
......
......@@ -24,24 +24,24 @@ public class DbColumn {
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");
quotedName = contents.quoteIdentifier(name);
String type = rs.getString("TYPE_NAME");
// a procedures column size is identified by PRECISION, for table this
// is COLUMN_SIZE
int precisionColumnIndex = DbContents.findColumn(rs, "PRECISION", 0);
int size;
if (precisionColumnIndex == 0) {
size = rs.getInt(DbContents.findColumn(rs, "COLUMN_SIZE", 7));
String columnSizeName;
if (prodecureColumn) {
columnSizeName = "PRECISION";
} else {
size = rs.getInt(precisionColumnIndex);
columnSizeName = "COLUMN_SIZE";
}
int size = rs.getInt(columnSizeName);
position = rs.getInt("ORDINAL_POSITION");
boolean isSQLite = contents.isSQLite();
if (size > 0 && !isSQLite) {
type += "(" + size;
int prec = rs.getInt(DbContents.findColumn(rs, "DECIMAL_DIGITS", 9));
int prec = rs.getInt("DECIMAL_DIGITS");
if (prec > 0) {
type += ", " + prec;
}
......
......@@ -9,6 +9,7 @@ package org.h2.bnf.context;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
......@@ -117,13 +118,22 @@ public class DbContents {
* This is a workaround for a JDBC-ODBC bridge problem.
*
* @param rs the result set
* @param columnName the column name
* @param columnLabel the column name
* @param defaultColumnIndex the default 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 {
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) {
return defaultColumnIndex;
}
......@@ -204,7 +214,7 @@ public class DbContents {
ResultSet rs = meta.getSchemas();
ArrayList<String> schemaList = New.arrayList();
while (rs.next()) {
String schema = rs.getString(findColumn(rs, "TABLE_SCHEM", 1));
String schema = rs.getString("TABLE_SCHEM");
String[] ignoreNames = null;
if (isOracle) {
ignoreNames = new String[] { "CTXSYS", "DIP", "DBSNMP",
......
......@@ -76,7 +76,7 @@ public class DbProcedure {
ResultSet rs = meta.getProcedureColumns(null, schema.name, name, null);
ArrayList<DbColumn> list = New.arrayList();
while (rs.next()) {
DbColumn column = new DbColumn(schema.getContents(), rs);
DbColumn column = new DbColumn(schema.getContents(), rs, true);
if (column.getPosition() > 0) {
// Not the return type
list.add(column);
......
......@@ -95,7 +95,7 @@ public class DbTableOrView {
ResultSet rs = meta.getColumns(null, schema.name, name, null);
ArrayList<DbColumn> list = New.arrayList();
while (rs.next()) {
DbColumn column = new DbColumn(schema.getContents(), rs);
DbColumn column = new DbColumn(schema.getContents(), rs, false);
list.add(column);
}
rs.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论