提交 09956514 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Display correct types of H2's columns in Console

上级 5dab1f7f
......@@ -21,8 +21,16 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #1576: H2 Console should not display precision and scale for data types that don't have them
</li>
<li>PR #1662: Fix Alter Table Drop Column In View when table name is wrapped by Double Quotes
</li>
<li>PR #1660: Optimize window aggregates with AND UNBOUNDED FOLLOWING and no exclusions
</li>
<li>PR #1658: Assorted small changes
</li>
<li>PR #1657: Failure to stop background thread
</li>
<li>PR #1656: Optimize window aggregates with ORDER BY + UNBOUNDED PRECEDING + no exclusions
</li>
<li>Issue #1654: OOM in TestMemoryUsage, in big mode
......
......@@ -27,31 +27,30 @@ public class DbColumn {
throws SQLException {
name = rs.getString("COLUMN_NAME");
quotedName = contents.quoteIdentifier(name);
position = rs.getInt("ORDINAL_POSITION");
if (contents.isH2() && !procedureColumn) {
dataType = rs.getString("COLUMN_TYPE");
return;
}
String type = rs.getString("TYPE_NAME");
// a procedures column size is identified by PRECISION, for table this
// is COLUMN_SIZE
String precisionColumnName;
String precisionColumnName, scaleColumnName;
if (procedureColumn) {
precisionColumnName = "PRECISION";
scaleColumnName = "SCALE";
} else {
precisionColumnName = "COLUMN_SIZE";
scaleColumnName = "DECIMAL_DIGITS";
}
int precision = rs.getInt(precisionColumnName);
position = rs.getInt("ORDINAL_POSITION");
boolean isSQLite = contents.isSQLite();
if (precision > 0 && !isSQLite) {
type += "(" + precision;
String scaleColumnName;
if (procedureColumn) {
scaleColumnName = "SCALE";
if (precision > 0 && !contents.isSQLite()) {
int scale = rs.getInt(scaleColumnName);
if (scale > 0) {
type = type + '(' + precision + ", " + scale + ')';
} else {
scaleColumnName = "DECIMAL_DIGITS";
}
int prec = rs.getInt(scaleColumnName);
if (prec > 0) {
type += ", " + prec;
type = type + '(' + precision + ')';
}
type += ")";
}
if (rs.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls) {
type += " NOT NULL";
......
......@@ -6,6 +6,7 @@
package org.h2.bnf.context;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
......@@ -119,15 +120,20 @@ public class DbSchema {
rs.close();
tables = list.toArray(new DbTableOrView[0]);
if (tables.length < SysProperties.CONSOLE_MAX_TABLES_LIST_COLUMNS) {
for (DbTableOrView tab : tables) {
try {
tab.readColumns(meta);
} catch (SQLException e) {
// MySQL:
// View '...' references invalid table(s) or column(s)
// or function(s) or definer/invoker of view
// lack rights to use them HY000/1356
// ignore
try (PreparedStatement ps = contents.isH2() ? meta.getConnection().prepareStatement(
"SELECT COLUMN_NAME, ORDINAL_POSITION, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS"
+ " WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?")
: null) {
for (DbTableOrView tab : tables) {
try {
tab.readColumns(meta, ps);
} catch (SQLException e) {
// MySQL:
// View '...' references invalid table(s) or column(s)
// or function(s) or definer/invoker of view
// lack rights to use them HY000/1356
// ignore
}
}
}
}
......
......@@ -6,6 +6,7 @@
package org.h2.bnf.context;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
......@@ -88,9 +89,18 @@ public class DbTableOrView {
* Read the column for this table from the database meta data.
*
* @param meta the database meta data
* @param ps prepared statement with custom query for H2 database, null for
* others
*/
public void readColumns(DatabaseMetaData meta) throws SQLException {
ResultSet rs = meta.getColumns(null, schema.name, name, null);
public void readColumns(DatabaseMetaData meta, PreparedStatement ps) throws SQLException {
ResultSet rs;
if (schema.getContents().isH2()) {
ps.setString(1, schema.name);
ps.setString(2, name);
rs = ps.executeQuery();
} else {
rs = meta.getColumns(null, schema.name, name, null);
}
ArrayList<DbColumn> list = new ArrayList<>();
while (rs.next()) {
DbColumn column = DbColumn.getColumn(schema.getContents(), rs);
......
......@@ -805,4 +805,4 @@ queryparser tokenized freeze factorings recompilation unenclosed rfe dsync
econd irst bcef ordinality nord unnest
analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan
corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes
preserves masking holder unboxing avert iae transformed subtle reevaluate exclusions subclause
preserves masking holder unboxing avert iae transformed subtle reevaluate exclusions subclause ftbl
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论