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

H2 Console autocomplete: the autocomplete feature didn't support quoted names.

上级 412311f3
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>It is now longer allowed to create an index on a CLOB or BLOB column
<ul><li>H2 Console autocomplete: the autocomplete feature didn't support quoted names.
</li><li>It is now longer allowed to create an index on a CLOB or BLOB column
(except for in-memory databases or indexes), because recovery doesn't work
on such columns. Fulltext indexes on such column are still supported of course.
</li><li>The PUBLIC schema could be renamed, which could result in a database that
......
......@@ -21,16 +21,23 @@ class DbColumn {
*/
String name;
/**
* The quoted table name.
*/
String quotedName;
/**
* The data type name (including precision and the NOT NULL flag if
* applicable).
*/
String dataType;
DbColumn(ResultSet rs, boolean isSQLite) throws SQLException {
DbColumn(DbContents contents, ResultSet rs) throws SQLException {
name = rs.getString("COLUMN_NAME");
quotedName = contents.quoteIdentifier(name);
String type = rs.getString("TYPE_NAME");
int size = rs.getInt(DbContents.findColumn(rs, "COLUMN_SIZE", 7));
boolean isSQLite = contents.isSQLite;
if (size > 0 && !isSQLite) {
type += "(" + size;
int prec = rs.getInt(DbContents.findColumn(rs, "DECIMAL_DIGITS", 9));
......
......@@ -79,13 +79,18 @@ public class DbContextRule implements Rule {
String best = null;
DbTableOrView bestTable = null;
for (DbTableOrView table : tables) {
String compare = up;
String name = StringUtils.toUpperEnglish(table.name);
if (up.startsWith(name)) {
if (table.quotedName.length() > name.length()) {
name = table.quotedName;
compare = query;
}
if (compare.startsWith(name)) {
if (best == null || name.length() > best.length()) {
best = name;
bestTable = table;
}
} else if (s.length() == 0 || name.startsWith(up)) {
} else if (s.length() == 0 || name.startsWith(compare)) {
if (s.length() < name.length()) {
sentence.add(table.quotedName, table.quotedName.substring(s.length()), Sentence.CONTEXT);
}
......@@ -131,12 +136,17 @@ public class DbContextRule implements Rule {
DbTableOrView last = sentence.getLastMatchedTable();
if (last != null && last.columns != null) {
for (DbColumn column : last.columns) {
String compare = up;
String name = StringUtils.toUpperEnglish(column.name);
if (up.startsWith(name)) {
if (column.quotedName.length() > name.length()) {
name = column.quotedName;
compare = query;
}
if (compare.startsWith(name)) {
String b = s.substring(name.length());
if (best == null || b.length() < best.length()) {
best = b;
} else if (s.length() == 0 || name.startsWith(up)) {
} else if (s.length() == 0 || name.startsWith(compare)) {
if (s.length() < name.length()) {
sentence.add(column.name, column.name.substring(s.length()), Sentence.CONTEXT);
}
......
......@@ -60,7 +60,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(rs, schema.contents.isSQLite);
DbColumn column = new DbColumn(schema.contents, rs);
list.add(column);
}
rs.close();
......
......@@ -475,7 +475,7 @@ public class WebApp {
columnsBuffer.append(' ');
}
columnsBuffer.append(column.name);
String col = StringUtils.urlEncode(PageParser.escapeJavaScript(column.name));
String col = escapeIdentifier(column.name);
String level = mainSchema ? ", 1, 1" : ", 2, 2";
buff.append("setNode(" + treeIndex + level + ", 'column', '" + PageParser.escapeJavaScript(column.name)
+ "', 'javascript:ins(\\'" + col + "\\')');\n");
......@@ -489,6 +489,10 @@ public class WebApp {
return treeIndex;
}
private static String escapeIdentifier(String name) {
return StringUtils.urlEncode(PageParser.escapeJavaScript(name)).replace('+', ' ');
}
/**
* This class represents index information for the GUI.
*/
......@@ -595,7 +599,7 @@ public class WebApp {
if (!mainSchema) {
tab = schema.quotedName + "." + tab;
}
tab = StringUtils.urlEncode(PageParser.escapeJavaScript(tab));
tab = escapeIdentifier(tab);
buff.append("setNode(" + treeIndex + indentation + " 'table', '" + PageParser.escapeJavaScript(table.name)
+ "', 'javascript:ins(\\'" + tab + "\\',true)');\n");
treeIndex++;
......@@ -619,7 +623,7 @@ public class WebApp {
if (!mainSchema) {
tab = view.schema.quotedName + "." + tab;
}
tab = StringUtils.urlEncode(PageParser.escapeJavaScript(tab));
tab = escapeIdentifier(tab);
buff.append("setNode(" + treeIndex + indentation + " 'view', '" + PageParser.escapeJavaScript(view.name)
+ "', 'javascript:ins(\\'" + tab + "\\',true)');\n");
treeIndex++;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论