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

DATABASE_TO_UPPER: when set to false, all identifier names (table names, column…

DATABASE_TO_UPPER: when set to false, all identifier names (table names, column names)  are case sensitive (except aggregate, built-in functions, data types, and keywords).
上级 0cc4689e
......@@ -18,7 +18,13 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Simplified test cases using assertThrows(...).
<ul><li>DATABASE_TO_UPPER: when set to false, all identifier names (table names, column names)
are case sensitive (except aggregate, built-in functions, data types, and keywords).
This is for improved compatibility with MySQL and PostgreSQL.
</li><li>When upgrading from an older 1.3.x version to version 1.3.157, when using BLOB or CLOB data,
the database could only be opened once.
</li><li>SUM on a boolean expression will now count the number of 'true' rows.
</li><li>Simplified test cases using assertThrows(...).
</li><li>A Java function that returns a result set that was generated using the provided connection
could cause an internal error in some cases. Now such result sets are copied early on.
</li><li>Data type RESULT_SET: information_schema.function_aliases returned type 0; now type -10 is returned (the same as Oracle: OracleTypes.CURSOR = -10).
......
......@@ -2138,11 +2138,19 @@ public class Parser {
return agg;
}
private int getAggregateType(String name) {
if (!identifiersToUpper) {
// if not yet converted to uppercase, do it now
name = StringUtils.toUpperEnglish(name);
}
return Aggregate.getAggregateType(name);
}
private Expression readFunction(Schema schema, String name) {
if (schema != null) {
return readJavaFunction(schema, name);
}
int agg = Aggregate.getAggregateType(name);
int agg = getAggregateType(name);
if (agg >= 0) {
return readAggregate(agg);
}
......@@ -4057,7 +4065,7 @@ public class Parser {
CreateAggregate command = new CreateAggregate(session);
command.setForce(force);
String name = readIdentifierWithSchema();
if (isKeyword(name) || Function.getFunction(database, name) != null || Aggregate.getAggregateType(name) >= 0) {
if (isKeyword(name) || Function.getFunction(database, name) != null || getAggregateType(name) >= 0) {
throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
}
command.setName(name);
......@@ -4175,7 +4183,7 @@ public class Parser {
String aliasName = readIdentifierWithSchema();
if (isKeyword(aliasName) ||
Function.getFunction(database, aliasName) != null ||
Aggregate.getAggregateType(aliasName) >= 0) {
getAggregateType(aliasName) >= 0) {
throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
}
CreateFunctionAlias command = new CreateFunctionAlias(session, getSchema());
......
......@@ -59,7 +59,9 @@ public class DbSettings extends SettingsBase {
* Database setting <code>DATABASE_TO_UPPER</code> (default: true).<br />
* Database short names are converted to uppercase for the DATABASE()
* function, and in the CATALOG column of all database meta data methods.
* Setting this to "false" is experimental.
* Setting this to "false" is experimental. When set to false, all
* identifier names (table names, column names) are case sensitive (except
* aggregate, built-in functions, data types, and keywords).
*/
public final boolean databaseToUpper = get("DATABASE_TO_UPPER", true);
......
......@@ -393,6 +393,10 @@ public class Function extends Expression implements FunctionCall {
* @return the function object or null
*/
public static Function getFunction(Database database, String name) {
if (!database.getSettings().databaseToUpper) {
// if not yet converted to uppercase, do it now
name = StringUtils.toUpperEnglish(name);
}
FunctionInfo info = getFunctionInfo(name);
if (info == null) {
return null;
......
......@@ -34,6 +34,8 @@ public class TestCompatibility extends TestBase {
public void test() throws SQLException {
deleteDb("compatibility");
testCaseSensitiveIdentifiers();
conn = getConnection("compatibility");
testDomain();
testColumnAlias();
......@@ -49,6 +51,22 @@ public class TestCompatibility extends TestBase {
deleteDb("compatibility");
}
private void testCaseSensitiveIdentifiers() throws SQLException {
Connection c = getConnection("compatibility;DATABASE_TO_UPPER=FALSE");
Statement stat = c.createStatement();
stat.execute("create table test(id int primary key, name varchar) as select 1, 'hello'");
ResultSet rs;
rs = stat.executeQuery("select * from test");
assertEquals("id", rs.getMetaData().getColumnLabel(1));
assertEquals("name", rs.getMetaData().getColumnLabel(2));
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).
execute("select * from TEST");
stat.execute("select COUNT(*), count(*), Count(*), Sum(id) from test");
stat.execute("select LENGTH(name), length(name), Length(name) from test");
stat.execute("drop table test");
c.close();
}
private void testDomain() throws SQLException {
if (config.memory) {
return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论