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

Aliases for built-in data types can now be re-mapped.

上级 78aab0c0
......@@ -3272,17 +3272,14 @@ public class Parser {
} else {
regular = true;
}
DataType dataType = DataType.getTypeByName(original);
long precision = -1;
int displaySize = -1;
int scale = -1;
String comment = null;
Column templateColumn = null;
if (dataType == null) {
UserDataType userDataType = database.findUserDataType(original);
if (userDataType == null) {
throw Message.getSQLException(ErrorCode.UNKNOWN_DATA_TYPE_1, currentToken);
}
DataType dataType;
UserDataType userDataType = database.findUserDataType(original);
if (userDataType != null) {
templateColumn = userDataType.getColumn();
dataType = DataType.getDataType(templateColumn.getType());
comment = templateColumn.getComment();
......@@ -3290,6 +3287,11 @@ public class Parser {
precision = templateColumn.getPrecision();
displaySize = templateColumn.getDisplaySize();
scale = templateColumn.getScale();
} else {
dataType = DataType.getTypeByName(original);
if (dataType == null) {
throw Message.getSQLException(ErrorCode.UNKNOWN_DATA_TYPE_1, currentToken);
}
}
if (database.getIgnoreCase() && dataType.type == Value.STRING && !"VARCHAR_CASESENSITIVE".equals(original)) {
original = "VARCHAR_IGNORECASE";
......
......@@ -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.value.DataType;
/**
* This class represents the statement
......@@ -53,6 +54,10 @@ 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);
}
int id = getObjectId(false, true);
UserDataType type = new UserDataType(db, id, typeName);
type.setColumn(column);
......
......@@ -1615,9 +1615,11 @@ public class ErrorCode {
/**
* The error with code <code>90119</code> is thrown when
* trying to create a domain if an object with this name already exists.
* trying to create a domain if an object with this name already exists,
* or when trying to overload a built-in data type.
* Example:
* <pre>
* CREATE DOMAIN INTEGER AS VARCHAR;
* CREATE DOMAIN EMAIL AS VARCHAR CHECK LOCATE('@', VALUE) > 0;
* CREATE DOMAIN EMAIL AS VARCHAR CHECK LOCATE('@', VALUE) > 0;
* </pre>
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create domain integer as varchar;
> exception
create domain int as varchar;
> ok
create domain bit as int;
> ok
create table test(id bit);
> ok
script nodata nopasswords nosettings;
> SCRIPT
> --------------------------------------------------
> -- 0 = SELECT COUNT(*) FROM PUBLIC.TEST;
> CREATE CACHED TABLE PUBLIC.TEST( ID VARCHAR );
> CREATE DOMAIN BIT AS VARCHAR;
> CREATE DOMAIN INT AS VARCHAR;
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> rows: 5
drop table test;
> ok
drop domain int;
> ok
drop domain bit;
> ok
create table test(id identity, parent bigint, foreign key(parent) references(id));
> ok
insert into test values(0, 0), (1, NULL), (2, 1), (3, 3), (4, 3);
> update count: 5
delete from test where id = 3;
> exception
delete from test where id = 0;
> update count: 1
delete from test where id = 1;
> exception
drop table test;
> ok
select iso_week('2006-12-31') w, iso_year('2007-12-31') y, iso_day_of_week('2007-12-31') w;
> W Y W
> -- ---- -
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create domain integer as varchar;
> exception
create domain int as varchar;
> ok
create domain bit as int;
> ok
create table test(id bit);
> ok
script nodata nopasswords nosettings;
> SCRIPT
> --------------------------------------------------
> -- 0 = SELECT COUNT(*) FROM PUBLIC.TEST;
> CREATE CACHED TABLE PUBLIC.TEST( ID VARCHAR );
> CREATE DOMAIN BIT AS VARCHAR;
> CREATE DOMAIN INT AS VARCHAR;
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> rows: 5
drop table test;
> ok
drop domain int;
> ok
drop domain bit;
> ok
create table test(id identity, parent bigint, foreign key(parent) references(id));
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论