Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ea42b4a7
Unverified
提交
ea42b4a7
authored
3月 30, 2018
作者:
Noel Grandin
提交者:
GitHub
3月 30, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1033 from katzyn/alias
Fix issues with BUILTIN_ALIAS_OVERRIDE=1
上级
39592b66
6ec81e86
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
133 行增加
和
62 行删除
+133
-62
Parser.java
h2/src/main/org/h2/command/Parser.java
+21
-14
Database.java
h2/src/main/org/h2/engine/Database.java
+2
-0
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+2
-1
createAlias.sql
h2/src/test/org/h2/test/scripts/ddl/createAlias.sql
+108
-0
testScript.sql
h2/src/test/org/h2/test/scripts/testScript.sql
+0
-47
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
ea42b4a7
...
...
@@ -2707,7 +2707,7 @@ public class Parser {
return
orderList
;
}
private
JavaFunction
readJavaFunction
(
Schema
schema
,
String
functionName
)
{
private
JavaFunction
readJavaFunction
(
Schema
schema
,
String
functionName
,
boolean
throwIfNotFound
)
{
FunctionAlias
functionAlias
=
null
;
if
(
schema
!=
null
)
{
functionAlias
=
schema
.
findFunction
(
functionName
);
...
...
@@ -2716,7 +2716,11 @@ public class Parser {
functionName
);
}
if
(
functionAlias
==
null
)
{
if
(
throwIfNotFound
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_NOT_FOUND_1
,
functionName
);
}
else
{
return
null
;
}
}
Expression
[]
args
;
ArrayList
<
Expression
>
argList
=
New
.
arrayList
();
...
...
@@ -2761,7 +2765,14 @@ public class Parser {
private
Expression
readFunction
(
Schema
schema
,
String
name
)
{
if
(
schema
!=
null
)
{
return
readJavaFunction
(
schema
,
name
);
return
readJavaFunction
(
schema
,
name
,
true
);
}
boolean
allowOverride
=
database
.
isAllowBuiltinAliasOverride
();
if
(
allowOverride
)
{
JavaFunction
jf
=
readJavaFunction
(
null
,
name
,
false
);
if
(
jf
!=
null
)
{
return
jf
;
}
}
AggregateType
agg
=
getAggregateType
(
name
);
if
(
agg
!=
null
)
{
...
...
@@ -2773,7 +2784,10 @@ public class Parser {
if
(
aggregate
!=
null
)
{
return
readJavaAggregate
(
aggregate
);
}
return
readJavaFunction
(
null
,
name
);
if
(
allowOverride
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_NOT_FOUND_1
,
name
);
}
return
readJavaFunction
(
null
,
name
,
true
);
}
switch
(
function
.
getFunctionType
())
{
case
Function
.
CAST
:
{
...
...
@@ -5114,19 +5128,12 @@ public class Parser {
private
CreateFunctionAlias
parseCreateFunctionAlias
(
boolean
force
)
{
boolean
ifNotExists
=
readIfNotExists
();
final
boolean
newAliasSameNameAsBuiltin
=
Function
.
getFunction
(
database
,
currentToken
)
!=
null
;
String
aliasName
;
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
aliasName
=
currentToken
;
schemaName
=
session
.
getCurrentSchemaName
();
read
();
}
else
{
aliasName
=
readIdentifierWithSchema
();
}
String
aliasName
=
readIdentifierWithSchema
();
final
boolean
newAliasSameNameAsBuiltin
=
Function
.
getFunction
(
database
,
aliasName
)
!=
null
;
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
// fine
}
else
if
(
isKeyword
(
aliasName
)
||
Function
.
getFunction
(
database
,
aliasName
)
!=
null
||
newAliasSameNameAsBuiltin
||
getAggregateType
(
aliasName
)
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
aliasName
);
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
ea42b4a7
...
...
@@ -267,6 +267,8 @@ public class Database implements DataHandler {
ci
.
getProperty
(
"JAVA_OBJECT_SERIALIZER"
,
null
);
this
.
multiThreaded
=
ci
.
getProperty
(
"MULTI_THREADED"
,
false
);
this
.
allowBuiltinAliasOverride
=
ci
.
getProperty
(
"BUILTIN_ALIAS_OVERRIDE"
,
false
);
boolean
closeAtVmShutdown
=
dbSettings
.
dbCloseOnExit
;
int
traceLevelFile
=
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
ea42b4a7
...
...
@@ -103,7 +103,8 @@ public class TestScript extends TestBase {
"uuid"
,
"varchar"
,
"varchar-ignorecase"
})
{
testScript
(
"datatypes/"
+
s
+
".sql"
);
}
for
(
String
s
:
new
String
[]
{
"alterTableAdd"
,
"alterTableDropColumn"
,
"createView"
,
"createTable"
,
for
(
String
s
:
new
String
[]
{
"alterTableAdd"
,
"alterTableDropColumn"
,
"createAlias"
,
"createView"
,
"createTable"
,
"dropSchema"
})
{
testScript
(
"ddl/"
+
s
+
".sql"
);
}
...
...
h2/src/test/org/h2/test/scripts/ddl/createAlias.sql
0 → 100644
浏览文件 @
ea42b4a7
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
create
alias
"SYSDATE"
for
"java.lang.Integer.parseInt(java.lang.String)"
;
>
exception
create
alias
"MIN"
for
"java.lang.Integer.parseInt(java.lang.String)"
;
>
exception
create
alias
"CAST"
for
"java.lang.Integer.parseInt(java.lang.String)"
;
>
exception
--- function alias ---------------------------------------------------------------------------------------------
CREATE
ALIAS
MY_SQRT
FOR
"java.lang.Math.sqrt"
;
>
ok
SELECT
MY_SQRT
(
2
.
0
)
MS
,
SQRT
(
2
.
0
);
>
MS
1
.
4142135623730951
>
------------------ ------------------
>
1
.
4142135623730951
1
.
4142135623730951
>
rows
:
1
SELECT
MY_SQRT
(
SUM
(
X
)),
SUM
(
X
),
MY_SQRT
(
55
)
FROM
SYSTEM_RANGE
(
1
,
10
);
>
PUBLIC
.
MY_SQRT
(
SUM
(
X
))
SUM
(
X
)
PUBLIC
.
MY_SQRT
(
55
)
>
---------------------- ------ ------------------
>
7
.
416198487095663
55
7
.
416198487095663
>
rows
:
1
SELECT
MY_SQRT
(
-
1
.
0
)
MS
,
SQRT
(
NULL
)
S
;
>
MS
S
>
--- ----
>
NaN
null
>
rows
:
1
SCRIPT
NOPASSWORDS
NOSETTINGS
;
>
SCRIPT
>
------------------------------------------------------------
>
CREATE
FORCE
ALIAS
PUBLIC
.
MY_SQRT
FOR
"java.lang.Math.sqrt"
;
>
CREATE
USER
IF
NOT
EXISTS
SA
PASSWORD
''
ADMIN
;
>
rows
:
2
SELECT
ALIAS_NAME
,
JAVA_CLASS
,
JAVA_METHOD
,
DATA_TYPE
,
COLUMN_COUNT
,
RETURNS_RESULT
,
REMARKS
FROM
INFORMATION_SCHEMA
.
FUNCTION_ALIASES
;
>
ALIAS_NAME
JAVA_CLASS
JAVA_METHOD
DATA_TYPE
COLUMN_COUNT
RETURNS_RESULT
REMARKS
>
---------- -------------- ----------- --------- ------------ -------------- -------
>
MY_SQRT
java
.
lang
.
Math
sqrt
8
1
2
>
rows
:
1
DROP
ALIAS
MY_SQRT
;
>
ok
CREATE
SCHEMA
TEST_SCHEMA
;
>
ok
CREATE
ALIAS
TRUNC
FOR
"java.lang.Math.floor(double)"
;
>
exception
CREATE
ALIAS
PUBLIC
.
TRUNC
FOR
"java.lang.Math.floor(double)"
;
>
exception
CREATE
ALIAS
TEST_SCHEMA
.
TRUNC
FOR
"java.lang.Math.round(double)"
;
>
exception
SET
BUILTIN_ALIAS_OVERRIDE
=
1
;
>
ok
CREATE
ALIAS
TRUNC
FOR
"java.lang.Math.floor(double)"
;
>
ok
SELECT
TRUNC
(
1
.
5
);
>>
1
.
0
SELECT
TRUNC
(
-
1
.
5
);
>>
-
2
.
0
DROP
ALIAS
TRUNC
;
>
ok
CREATE
ALIAS
PUBLIC
.
TRUNC
FOR
"java.lang.Math.floor(double)"
;
>
ok
CREATE
ALIAS
TEST_SCHEMA
.
TRUNC
FOR
"java.lang.Math.round(double)"
;
>
ok
SELECT
PUBLIC
.
TRUNC
(
1
.
5
);
>>
1
.
0
SELECT
PUBLIC
.
TRUNC
(
-
1
.
5
);
>>
-
2
.
0
SELECT
TEST_SCHEMA
.
TRUNC
(
1
.
5
);
>>
2
SELECT
TEST_SCHEMA
.
TRUNC
(
-
1
.
5
);
>>
-
1
DROP
ALIAS
PUBLIC
.
TRUNC
;
>
ok
DROP
ALIAS
TEST_SCHEMA
.
TRUNC
;
>
ok
SET
BUILTIN_ALIAS_OVERRIDE
=
0
;
>
ok
DROP
SCHEMA
TEST_SCHEMA
RESTRICT
;
>
ok
h2/src/test/org/h2/test/scripts/testScript.sql
浏览文件 @
ea42b4a7
...
...
@@ -1689,15 +1689,6 @@ explain select * from test where id in(1, 2, null);
drop table test;
> ok
create alias "SYSDATE" for "java.lang.Integer.parseInt(java.lang.String)";
> exception
create alias "MIN" for "java.lang.Integer.parseInt(java.lang.String)";
> exception
create alias "CAST" for "java.lang.Integer.parseInt(java.lang.String)";
> exception
CREATE TABLE PARENT(A INT, B INT, PRIMARY KEY(A, B));
> ok
...
...
@@ -5099,44 +5090,6 @@ SELECT count(*) FROM test_null WHERE not ('X'=null and 1=0);
drop table if exists test_null;
> ok
--- function alias ---------------------------------------------------------------------------------------------
CREATE ALIAS MY_SQRT FOR "java.lang.Math.sqrt";
> ok
SELECT MY_SQRT(2.0) MS, SQRT(2.0);
> MS 1.4142135623730951
> ------------------ ------------------
> 1.4142135623730951 1.4142135623730951
> rows: 1
SELECT MY_SQRT(SUM(X)), SUM(X), MY_SQRT(55) FROM SYSTEM_RANGE(1, 10);
> PUBLIC.MY_SQRT(SUM(X)) SUM(X) PUBLIC.MY_SQRT(55)
> ---------------------- ------ ------------------
> 7.416198487095663 55 7.416198487095663
> rows: 1
SELECT MY_SQRT(-1.0) MS, SQRT(NULL) S;
> MS S
> --- ----
> NaN null
> rows: 1
SCRIPT NOPASSWORDS NOSETTINGS;
> SCRIPT
> ------------------------------------------------------------
> CREATE FORCE ALIAS PUBLIC.MY_SQRT FOR "java.lang.Math.sqrt";
> CREATE USER IF NOT EXISTS SA PASSWORD
''
ADMIN;
> rows: 2
SELECT ALIAS_NAME, JAVA_CLASS, JAVA_METHOD, DATA_TYPE, COLUMN_COUNT, RETURNS_RESULT, REMARKS FROM INFORMATION_SCHEMA.FUNCTION_ALIASES;
> ALIAS_NAME JAVA_CLASS JAVA_METHOD DATA_TYPE COLUMN_COUNT RETURNS_RESULT REMARKS
> ---------- -------------- ----------- --------- ------------ -------------- -------
> MY_SQRT java.lang.Math sqrt 8 1 2
> rows: 1
DROP ALIAS MY_SQRT;
> ok
--- schema ----------------------------------------------------------------------------------------------
SELECT DISTINCT TABLE_SCHEMA, TABLE_CATALOG FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_SCHEMA;
> TABLE_SCHEMA TABLE_CATALOG
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论