提交 bb47d6be 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".
上级 aa66166c
......@@ -24,24 +24,30 @@ public class DbColumn {
private int position;
public DbColumn(DbContents contents, ResultSet rs, boolean procedureColumn) throws SQLException {
private DbColumn(DbContents contents, ResultSet rs, boolean procedureColumn) 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
String columnSizeName;
String precisionColumnName;
if (procedureColumn) {
columnSizeName = "PRECISION";
precisionColumnName = "PRECISION";
} else {
columnSizeName = "COLUMN_SIZE";
precisionColumnName = "COLUMN_SIZE";
}
int size = rs.getInt(columnSizeName);
int precision = rs.getInt(precisionColumnName);
position = rs.getInt("ORDINAL_POSITION");
boolean isSQLite = contents.isSQLite();
if (size > 0 && !isSQLite) {
type += "(" + size;
int prec = rs.getInt("DECIMAL_DIGITS");
if (precision > 0 && !isSQLite) {
type += "(" + precision;
String scaleColumnName;
if (procedureColumn) {
scaleColumnName = "SCALE";
} else {
scaleColumnName = "DECIMAL_DIGITS";
}
int prec = rs.getInt(scaleColumnName);
if (prec > 0) {
type += ", " + prec;
}
......@@ -52,6 +58,28 @@ public class DbColumn {
}
dataType = type;
}
/**
* Create a column from a DatabaseMetaData.getProcedureColumns row.
*
* @param contents the database contents
* @param rs the result set
* @return the column
*/
public static DbColumn getProcedureColumn(DbContents contents, ResultSet rs) throws SQLException {
return new DbColumn(contents, rs, true);
}
/**
* Create a column from a DatabaseMetaData.getColumns row.
*
* @param contents the database contents
* @param rs the result set
* @return the column
*/
public static DbColumn getColumn(DbContents contents, ResultSet rs) throws SQLException {
return new DbColumn(contents, rs, false);
}
/**
* @return The data type name (including precision and the NOT NULL flag if
......
......@@ -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, true);
DbColumn column = DbColumn.getProcedureColumn(schema.getContents(), rs);
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, false);
DbColumn column = DbColumn.getColumn(schema.getContents(), rs);
list.add(column);
}
rs.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论