提交 967c3410 authored 作者: Thomas Mueller's avatar Thomas Mueller

CREATE DOMAIN: Built-in data types can now only be changed if no tables exist.

上级 55eb83f4
......@@ -14,6 +14,7 @@ import org.h2.engine.Session;
import org.h2.engine.UserDataType;
import org.h2.message.Message;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.value.DataType;
/**
......@@ -39,7 +40,6 @@ public class CreateUserDataType extends DefineCommand {
}
public void setIfNotExists(boolean ifNotExists) {
// TODO user data type: if exists - probably better use 'or replace'
this.ifNotExists = ifNotExists;
}
......@@ -55,8 +55,14 @@ public class CreateUserDataType extends DefineCommand {
throw Message.getSQLException(ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1, typeName);
}
DataType builtIn = DataType.getTypeByName(typeName);
if (builtIn != null && !builtIn.hidden) {
throw Message.getSQLException(ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1, typeName);
if (builtIn != null) {
if (!builtIn.hidden) {
throw Message.getSQLException(ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1, typeName);
}
Table table = session.getDatabase().getFirstUserTable();
if (table != null) {
throw Message.getSQLException(ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1, typeName + " (" + table.getSQL() + ")");
}
}
int id = getObjectId(false, true);
UserDataType type = new UserDataType(db, id, typeName);
......
......@@ -14,7 +14,6 @@ import org.h2.compress.Compressor;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Mode;
import org.h2.engine.Session;
import org.h2.engine.Setting;
......@@ -25,7 +24,6 @@ import org.h2.result.LocalResult;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.tools.CompressTool;
import org.h2.util.ObjectArray;
import org.h2.util.StringUtils;
import org.h2.value.CompareMode;
import org.h2.value.ValueInt;
......@@ -94,12 +92,9 @@ public class Set extends Prepared {
}
case SetTypes.COLLATION: {
session.getUser().checkAdmin();
ObjectArray array = database.getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
for (int i = 0; i < array.size(); i++) {
Table table = (Table) array.get(i);
if (table.getCreateSQL() != null) {
throw Message.getSQLException(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, table.getSQL());
}
Table table = database.getFirstUserTable();
if (table != null) {
throw Message.getSQLException(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, table.getSQL());
}
CompareMode compareMode;
StringBuffer buff = new StringBuffer(stringValue);
......
......@@ -2124,4 +2124,20 @@ public class Database implements DataHandler {
}
}
/**
* Get the first user defined table.
*
* @return the table or null if no table is defined
*/
public Table getFirstUserTable() {
ObjectArray array = getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
for (int i = 0; i < array.size(); i++) {
Table table = (Table) array.get(i);
if (table.getCreateSQL() != null) {
return table;
}
}
return null;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论