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

The collation can now be set in the database URL, even if there are data tables,…

The collation can now be set in the database URL, even if there are data tables, if the collection is the same as the current collation.
上级 a3b65519
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Improved Oracle compatibility for CASE WHEN and DECODE.
<ul><li>The collation can now be set in the database URL, even if there are data tables,
if the collection is the same as the current collation.
</li><li>Improved Oracle compatibility for CASE WHEN and DECODE.
</li><li>The statement "drop all objects" did not work if a table depends on a view via a constraint.
</li><li>Subqueries or views with "order by" an alias expression could not be executed
due to a regression introduced in version 1.3.174.
......
......@@ -110,10 +110,9 @@ public class Set extends Prepared {
}
case SetTypes.COLLATION: {
session.getUser().checkAdmin();
Table table = database.getFirstUserTable();
if (table != null) {
throw DbException.get(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, table.getSQL());
}
final boolean binaryUnsigned = database.getCompareMode().isBinaryUnsigned();
CompareMode compareMode;
StringBuilder buff = new StringBuilder(stringValue);
......@@ -133,6 +132,14 @@ public class Set extends Prepared {
}
compareMode = CompareMode.getInstance(stringValue, strength, binaryUnsigned);
}
CompareMode old = database.getCompareMode();
if (old.equals(compareMode)) {
break;
}
Table table = database.getFirstUserTable();
if (table != null) {
throw DbException.get(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, table.getSQL());
}
addOrUpdateSetting(name, buff.toString(), 0);
database.setCompareMode(compareMode);
break;
......
......@@ -63,7 +63,10 @@ public class CompareMode {
private final String name;
private final int strength;
/** if true, sort BINARY columns as if they contain unsigned bytes */
/**
* If true, sort BINARY columns as if they contain unsigned bytes.
*/
private final boolean binaryUnsigned;
protected CompareMode(String name, int strength, boolean binaryUnsigned) {
......@@ -228,4 +231,29 @@ public class CompareMode {
return binaryUnsigned;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (!(obj instanceof CompareMode)) {
return false;
}
CompareMode o = (CompareMode) obj;
if (!getName().equals(o.getName())) {
return false;
}
if (strength != o.strength) {
return false;
}
if (binaryUnsigned != o.binaryUnsigned) {
return false;
}
return true;
}
@Override
public int hashCode() {
return getName().hashCode() ^ strength ^ (binaryUnsigned ? -1 : 0);
}
}
......@@ -36,6 +36,15 @@ public class TestCollation extends TestBase {
stat.execute("set collation default_en");
assertThrows(ErrorCode.CLASS_NOT_FOUND_1, stat).
execute("set collation icu4j_en");
stat.execute("set collation ge");
stat.execute("create table test(id int)");
// the same as the current - ok
stat.execute("set collation ge");
// not allowed to change now
assertThrows(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, stat).
execute("set collation en");
conn.close();
deleteDb("collation");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论