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