Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
35062976
提交
35062976
authored
4月 01, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'h2database/master' into mv_nb
上级
3ec60bda
ea42b4a7
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
161 行增加
和
63 行删除
+161
-63
Parser.java
h2/src/main/org/h2/command/Parser.java
+21
-14
Database.java
h2/src/main/org/h2/engine/Database.java
+5
-1
Schema.java
h2/src/main/org/h2/schema/Schema.java
+6
-0
TestRights.java
h2/src/test/org/h2/test/db/TestRights.java
+19
-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
浏览文件 @
35062976
...
@@ -2707,7 +2707,7 @@ public class Parser {
...
@@ -2707,7 +2707,7 @@ public class Parser {
return
orderList
;
return
orderList
;
}
}
private
JavaFunction
readJavaFunction
(
Schema
schema
,
String
functionName
)
{
private
JavaFunction
readJavaFunction
(
Schema
schema
,
String
functionName
,
boolean
throwIfNotFound
)
{
FunctionAlias
functionAlias
=
null
;
FunctionAlias
functionAlias
=
null
;
if
(
schema
!=
null
)
{
if
(
schema
!=
null
)
{
functionAlias
=
schema
.
findFunction
(
functionName
);
functionAlias
=
schema
.
findFunction
(
functionName
);
...
@@ -2716,7 +2716,11 @@ public class Parser {
...
@@ -2716,7 +2716,11 @@ public class Parser {
functionName
);
functionName
);
}
}
if
(
functionAlias
==
null
)
{
if
(
functionAlias
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_NOT_FOUND_1
,
functionName
);
if
(
throwIfNotFound
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_NOT_FOUND_1
,
functionName
);
}
else
{
return
null
;
}
}
}
Expression
[]
args
;
Expression
[]
args
;
ArrayList
<
Expression
>
argList
=
New
.
arrayList
();
ArrayList
<
Expression
>
argList
=
New
.
arrayList
();
...
@@ -2761,7 +2765,14 @@ public class Parser {
...
@@ -2761,7 +2765,14 @@ public class Parser {
private
Expression
readFunction
(
Schema
schema
,
String
name
)
{
private
Expression
readFunction
(
Schema
schema
,
String
name
)
{
if
(
schema
!=
null
)
{
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
);
AggregateType
agg
=
getAggregateType
(
name
);
if
(
agg
!=
null
)
{
if
(
agg
!=
null
)
{
...
@@ -2773,7 +2784,10 @@ public class Parser {
...
@@ -2773,7 +2784,10 @@ public class Parser {
if
(
aggregate
!=
null
)
{
if
(
aggregate
!=
null
)
{
return
readJavaAggregate
(
aggregate
);
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
())
{
switch
(
function
.
getFunctionType
())
{
case
Function
.
CAST
:
{
case
Function
.
CAST
:
{
...
@@ -5114,19 +5128,12 @@ public class Parser {
...
@@ -5114,19 +5128,12 @@ public class Parser {
private
CreateFunctionAlias
parseCreateFunctionAlias
(
boolean
force
)
{
private
CreateFunctionAlias
parseCreateFunctionAlias
(
boolean
force
)
{
boolean
ifNotExists
=
readIfNotExists
();
boolean
ifNotExists
=
readIfNotExists
();
final
boolean
newAliasSameNameAsBuiltin
=
Function
.
getFunction
(
database
,
currentToken
)
!=
null
;
String
aliasName
=
readIdentifierWithSchema
();
String
aliasName
;
final
boolean
newAliasSameNameAsBuiltin
=
Function
.
getFunction
(
database
,
aliasName
)
!=
null
;
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
aliasName
=
currentToken
;
schemaName
=
session
.
getCurrentSchemaName
();
read
();
}
else
{
aliasName
=
readIdentifierWithSchema
();
}
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
// fine
// fine
}
else
if
(
isKeyword
(
aliasName
)
||
}
else
if
(
isKeyword
(
aliasName
)
||
Function
.
getFunction
(
database
,
aliasName
)
!=
null
||
newAliasSameNameAsBuiltin
||
getAggregateType
(
aliasName
)
!=
null
)
{
getAggregateType
(
aliasName
)
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
aliasName
);
aliasName
);
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
35062976
...
@@ -267,6 +267,8 @@ public class Database implements DataHandler {
...
@@ -267,6 +267,8 @@ public class Database implements DataHandler {
ci
.
getProperty
(
"JAVA_OBJECT_SERIALIZER"
,
null
);
ci
.
getProperty
(
"JAVA_OBJECT_SERIALIZER"
,
null
);
this
.
multiThreaded
=
this
.
multiThreaded
=
ci
.
getProperty
(
"MULTI_THREADED"
,
false
);
ci
.
getProperty
(
"MULTI_THREADED"
,
false
);
this
.
allowBuiltinAliasOverride
=
ci
.
getProperty
(
"BUILTIN_ALIAS_OVERRIDE"
,
false
);
boolean
closeAtVmShutdown
=
boolean
closeAtVmShutdown
=
dbSettings
.
dbCloseOnExit
;
dbSettings
.
dbCloseOnExit
;
int
traceLevelFile
=
int
traceLevelFile
=
...
@@ -1297,7 +1299,9 @@ public class Database implements DataHandler {
...
@@ -1297,7 +1299,9 @@ public class Database implements DataHandler {
closing
=
true
;
closing
=
true
;
}
}
}
}
removeOrphanedLobs
();
if
(!
this
.
isReadOnly
())
{
removeOrphanedLobs
();
}
try
{
try
{
if
(
systemSession
!=
null
)
{
if
(
systemSession
!=
null
)
{
if
(
powerOffCount
!=
-
1
)
{
if
(
powerOffCount
!=
-
1
)
{
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
35062976
...
@@ -18,6 +18,7 @@ import org.h2.engine.DbObject;
...
@@ -18,6 +18,7 @@ import org.h2.engine.DbObject;
import
org.h2.engine.DbObjectBase
;
import
org.h2.engine.DbObjectBase
;
import
org.h2.engine.DbSettings
;
import
org.h2.engine.DbSettings
;
import
org.h2.engine.FunctionAlias
;
import
org.h2.engine.FunctionAlias
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.engine.SysProperties
;
import
org.h2.engine.SysProperties
;
import
org.h2.engine.User
;
import
org.h2.engine.User
;
...
@@ -172,6 +173,11 @@ public class Schema extends DbObjectBase {
...
@@ -172,6 +173,11 @@ public class Schema extends DbObjectBase {
FunctionAlias
obj
=
(
FunctionAlias
)
functions
.
values
().
toArray
()[
0
];
FunctionAlias
obj
=
(
FunctionAlias
)
functions
.
values
().
toArray
()[
0
];
database
.
removeSchemaObject
(
session
,
obj
);
database
.
removeSchemaObject
(
session
,
obj
);
}
}
for
(
Right
right
:
database
.
getAllRights
())
{
if
(
right
.
getGrantedObject
()
==
this
)
{
database
.
removeDatabaseObject
(
session
,
right
);
}
}
database
.
removeMeta
(
session
,
getId
());
database
.
removeMeta
(
session
,
getId
());
owner
=
null
;
owner
=
null
;
invalidate
();
invalidate
();
...
...
h2/src/test/org/h2/test/db/TestRights.java
浏览文件 @
35062976
...
@@ -48,6 +48,7 @@ public class TestRights extends TestBase {
...
@@ -48,6 +48,7 @@ public class TestRights extends TestBase {
testSchemaRenameUser
();
testSchemaRenameUser
();
testAccessRights
();
testAccessRights
();
testSchemaAdminRole
();
testSchemaAdminRole
();
testSchemaDrop
();
deleteDb
(
"rights"
);
deleteDb
(
"rights"
);
}
}
...
@@ -491,6 +492,24 @@ public class TestRights extends TestBase {
...
@@ -491,6 +492,24 @@ public class TestRights extends TestBase {
conn
.
close
();
conn
.
close
();
}
}
private
void
testSchemaDrop
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"rights"
);
Connection
conn
=
getConnection
(
"rights"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create user test password '' admin"
);
stat
.
execute
(
"create schema b"
);
stat
.
execute
(
"grant select on schema b to test"
);
stat
.
execute
(
"drop schema b cascade"
);
conn
.
close
();
conn
=
getConnection
(
"rights"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop user test"
);
conn
.
close
();
}
private
void
testAccessRights
()
throws
SQLException
{
private
void
testAccessRights
()
throws
SQLException
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
35062976
...
@@ -103,7 +103,8 @@ public class TestScript extends TestBase {
...
@@ -103,7 +103,8 @@ public class TestScript extends TestBase {
"uuid"
,
"varchar"
,
"varchar-ignorecase"
})
{
"uuid"
,
"varchar"
,
"varchar-ignorecase"
})
{
testScript
(
"datatypes/"
+
s
+
".sql"
);
testScript
(
"datatypes/"
+
s
+
".sql"
);
}
}
for
(
String
s
:
new
String
[]
{
"alterTableAdd"
,
"alterTableDropColumn"
,
"createView"
,
"createTable"
,
for
(
String
s
:
new
String
[]
{
"alterTableAdd"
,
"alterTableDropColumn"
,
"createAlias"
,
"createView"
,
"createTable"
,
"dropSchema"
})
{
"dropSchema"
})
{
testScript
(
"ddl/"
+
s
+
".sql"
);
testScript
(
"ddl/"
+
s
+
".sql"
);
}
}
...
...
h2/src/test/org/h2/test/scripts/ddl/createAlias.sql
0 → 100644
浏览文件 @
35062976
-- 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
浏览文件 @
35062976
...
@@ -1689,15 +1689,6 @@ explain select * from test where id in(1, 2, null);
...
@@ -1689,15 +1689,6 @@ explain select * from test where id in(1, 2, null);
drop table test;
drop table test;
> ok
> 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));
CREATE TABLE PARENT(A INT, B INT, PRIMARY KEY(A, B));
> ok
> ok
...
@@ -5099,44 +5090,6 @@ SELECT count(*) FROM test_null WHERE not ('X'=null and 1=0);
...
@@ -5099,44 +5090,6 @@ SELECT count(*) FROM test_null WHERE not ('X'=null and 1=0);
drop table if exists test_null;
drop table if exists test_null;
> ok
> 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 ----------------------------------------------------------------------------------------------
--- schema ----------------------------------------------------------------------------------------------
SELECT DISTINCT TABLE_SCHEMA, TABLE_CATALOG FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_SCHEMA;
SELECT DISTINCT TABLE_SCHEMA, TABLE_CATALOG FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_SCHEMA;
> TABLE_SCHEMA TABLE_CATALOG
> TABLE_SCHEMA TABLE_CATALOG
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论