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

H2 Console: the auto-complete feature didn't quote column names that need quoting. Issue 186.

上级 07ba5508
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>The experimental LOB storage mechanism now supports all features of the <ul><li>H2 Console: the auto-complete feature didn't quote column names
that need quoting. Issue 186.
</li><li>The experimental LOB storage mechanism now supports all features of the
old one. To use it, set the system property "h2.lobInDatabase" to "true". old one. To use it, set the system property "h2.lobInDatabase" to "true".
</li><li>The functions isBeforeFirst() and isAfterLast() were not compliant to the </li><li>The functions isBeforeFirst() and isAfterLast() were not compliant to the
JDBC spec. If the ResultSet contains no rows, they must return false. Fixed. JDBC spec. If the ResultSet contains no rows, they must return false. Fixed.
......
...@@ -72,6 +72,12 @@ public class DbContents { ...@@ -72,6 +72,12 @@ public class DbContents {
*/ */
boolean isSQLite; boolean isSQLite;
/**
* True if the unquoted names are stored as upper case.
* False for MySQL and PostgreSQL.
*/
boolean storedUpperCaseIdentifiers;
/** /**
* Get the column index of a column in a result set. If the column is not * Get the column index of a column in a result set. If the column is not
* found, the default column index is returned. * found, the default column index is returned.
...@@ -119,6 +125,7 @@ public class DbContents { ...@@ -119,6 +125,7 @@ public class DbContents {
isDerby = url.startsWith("jdbc:derby:"); isDerby = url.startsWith("jdbc:derby:");
isFirebird = url.startsWith("jdbc:firebirdsql:"); isFirebird = url.startsWith("jdbc:firebirdsql:");
} }
storedUpperCaseIdentifiers = meta.storesUpperCaseIdentifiers();
String defaultSchemaName = getDefaultSchemaName(meta); String defaultSchemaName = getDefaultSchemaName(meta);
String[] schemaNames = getSchemaNames(meta); String[] schemaNames = getSchemaNames(meta);
schemas = new DbSchema[schemaNames.length]; schemas = new DbSchema[schemaNames.length];
...@@ -227,4 +234,25 @@ public class DbContents { ...@@ -227,4 +234,25 @@ public class DbContents {
return StringUtils.toUpperEnglish(identifier); return StringUtils.toUpperEnglish(identifier);
} }
/**
* Check whether an identifier from the database meta data needs to be
* quoted. This depends on how the database stores the identifiers ("test"
* doesn't need to be quoted if the database stores identifiers lowercase)
*
* @param identifier the identifier
* @return true if the identifier needs to be quoted
*/
boolean needsQuotes(String identifier) {
if (storedUpperCaseIdentifiers) {
if (identifier.equals(identifier.toUpperCase())) {
return false;
}
} else {
if (identifier.equals(identifier.toLowerCase())) {
return false;
}
}
return true;
}
} }
...@@ -259,7 +259,13 @@ public class DbContextRule implements Rule { ...@@ -259,7 +259,13 @@ public class DbContextRule implements Rule {
continue; continue;
} }
if (columnPattern.length() < columnName.length()) { if (columnPattern.length() < columnName.length()) {
sentence.add(columnName, columnName.substring(columnPattern.length()), Sentence.CONTEXT); String sub = columnName.substring(columnPattern.length());
if (sub.equals(columnName) && contents.needsQuotes(columnName)) {
columnName = StringUtils.quoteIdentifier(columnName);
sub = columnName;
}
System.out.println("add " + columnName + " " + columnName.substring(columnPattern.length()));
sentence.add(columnName, sub, Sentence.CONTEXT);
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论