Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d351a574
提交
d351a574
authored
7月 22, 2017
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue #539: Allow override of builtin functions/aliases
上级
233c1ce8
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
90 行增加
和
3 行删除
+90
-3
help.csv
h2/src/docsrc/help/help.csv
+13
-0
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+20
-3
Set.java
h2/src/main/org/h2/command/dml/Set.java
+10
-0
SetTypes.java
h2/src/main/org/h2/command/dml/SetTypes.java
+6
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+9
-0
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+30
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
d351a574
...
...
@@ -1165,6 +1165,19 @@ This setting is persistent.
SET BINARY_COLLATION SIGNED
"
"Commands (Other)","SET BUILTIN_ALIAS_OVERRIDE","
SET BUILTIN_ALIAS_OVERRIDE
{ TRUE | FALSE } ] }
","
Allows the overriding of the builtin system date/time functions
for unit testing purposes.
Admin rights are required to execute this command.
This command commits an open transaction in this connection.
","
SET BUILTIN_ALIAS_OVERRIDE TRUE
"
"Commands (Other)","SET COLLATION","
SET [ DATABASE ] COLLATION
{ OFF | collationName [ STRENGTH { PRIMARY | SECONDARY | TERTIARY | IDENTICAL } ] }
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
d351a574
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #539: Allow override of builtin functions/aliases
</li>
<li>
Issue #535: Allow explicit paths on Windows without drive letter
</li>
<li>
Issue #549: Removed UNION ALL requirements for CTE
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
d351a574
...
...
@@ -2707,10 +2707,17 @@ public class Parser {
return
function
;
}
private
Funct
ion
readFunctionWithoutParameters
(
String
name
)
{
private
Express
ion
readFunctionWithoutParameters
(
String
name
)
{
if
(
readIf
(
"("
))
{
read
(
")"
);
}
if
(
database
.
isAllowBuiltinAliasOverride
())
{
FunctionAlias
functionAlias
=
database
.
getSchema
(
session
.
getCurrentSchemaName
()).
findFunction
(
name
);
if
(
functionAlias
!=
null
)
{
JavaFunction
func
=
new
JavaFunction
(
functionAlias
,
new
Expression
[
0
]);
return
func
;
}
}
Function
function
=
Function
.
getFunction
(
database
,
name
);
function
.
doneWithParameters
();
return
function
;
...
...
@@ -4850,8 +4857,18 @@ public class Parser {
private
CreateFunctionAlias
parseCreateFunctionAlias
(
boolean
force
)
{
boolean
ifNotExists
=
readIfNotExists
();
String
aliasName
=
readIdentifierWithSchema
();
if
(
isKeyword
(
aliasName
)
||
final
boolean
newAliasSameNameAsBuiltin
=
Function
.
getFunction
(
database
,
currentToken
)
!=
null
;
String
aliasName
;
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
aliasName
=
currentToken
;
schemaName
=
session
.
getCurrentSchemaName
();
read
();
}
else
{
aliasName
=
readIdentifierWithSchema
();
}
if
(
database
.
isAllowBuiltinAliasOverride
()
&&
newAliasSameNameAsBuiltin
)
{
// fine
}
else
if
(
isKeyword
(
aliasName
)
||
Function
.
getFunction
(
database
,
aliasName
)
!=
null
||
getAggregateType
(
aliasName
)
>=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
...
...
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
d351a574
...
...
@@ -524,6 +524,16 @@ public class Set extends Prepared {
session
.
setLazyQueryExecution
(
value
==
1
);
break
;
}
case
SetTypes
.
BUILTIN_ALIAS_OVERRIDE
:
{
session
.
getUser
().
checkAdmin
();
int
value
=
getIntValue
();
if
(
value
!=
0
&&
value
!=
1
)
{
throw
DbException
.
getInvalidValueException
(
"BUILTIN_ALIAS_OVERRIDE"
,
value
);
}
database
.
setAllowBuiltinAliasOverride
(
value
==
1
);
break
;
}
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
}
...
...
h2/src/main/org/h2/command/dml/SetTypes.java
浏览文件 @
d351a574
...
...
@@ -243,6 +243,11 @@ public class SetTypes {
*/
public
static
final
int
LAZY_QUERY_EXECUTION
=
46
;
/**
* The type of SET BUILTIN_ALIAS_OVERRIDE statement.
*/
public
static
final
int
BUILTIN_ALIAS_OVERRIDE
=
47
;
private
static
final
ArrayList
<
String
>
TYPES
=
New
.
arrayList
();
private
SetTypes
()
{
...
...
@@ -298,6 +303,7 @@ public class SetTypes {
list
.
add
(
BATCH_JOINS
,
"BATCH_JOINS"
);
list
.
add
(
FORCE_JOIN_ORDER
,
"FORCE_JOIN_ORDER"
);
list
.
add
(
LAZY_QUERY_EXECUTION
,
"LAZY_QUERY_EXECUTION"
);
list
.
add
(
BUILTIN_ALIAS_OVERRIDE
,
"BUILTIN_ALIAS_OVERRIDE"
);
}
/**
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
d351a574
...
...
@@ -191,6 +191,7 @@ public class Database implements DataHandler {
private
int
logMode
;
private
MVTableEngine
.
Store
mvStore
;
private
int
retentionTime
;
private
boolean
allowBuiltinAliasOverride
;
private
DbException
backgroundException
;
private
JavaObjectSerializer
javaObjectSerializer
;
private
String
javaObjectSerializerName
;
...
...
@@ -1983,7 +1984,15 @@ public class Database implements DataHandler {
mvStore
.
getStore
().
setRetentionTime
(
value
);
}
}
public
void
setAllowBuiltinAliasOverride
(
boolean
b
)
{
allowBuiltinAliasOverride
=
b
;
}
public
boolean
isAllowBuiltinAliasOverride
()
{
return
allowBuiltinAliasOverride
;
}
/**
* Check if flush-on-each-commit is enabled.
*
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
d351a574
...
...
@@ -76,6 +76,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
@Override
public
void
test
()
throws
Exception
{
deleteDb
(
"functions"
);
testOverrideAlias
();
testIfNull
();
testToDate
();
testToDateException
();
...
...
@@ -1671,7 +1672,9 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
}
private
void
testIfNull
()
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
...
...
@@ -2113,6 +2116,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
}
private
void
testOverrideAlias
()
throws
SQLException
,
InterruptedException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
conn
.
setAutoCommit
(
true
);
Statement
stat
=
conn
.
createStatement
();
assertThrows
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
stat
).
execute
(
"create alias CURRENT_TIMESTAMP for \""
+
getClass
().
getName
()
+
".currentTimestamp\""
);
stat
.
execute
(
"set BUILTIN_ALIAS_OVERRIDE true"
);
stat
.
execute
(
"create alias CURRENT_TIMESTAMP for \""
+
getClass
().
getName
()
+
".currentTimestampOverride\""
);
assertCallResult
(
"3141"
,
stat
,
"CURRENT_TIMESTAMP"
);
conn
.
close
();
}
private
void
callCompiledFunction
(
String
functionName
)
throws
SQLException
{
deleteDb
(
"functions"
);
try
(
Connection
conn
=
getConnection
(
"functions"
))
{
...
...
@@ -2430,6 +2453,13 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
return
new
Object
[]
{
buff
.
toString
()
};
}
/**
* This method is called via reflection from the database.
*/
public
static
long
currentTimestampOverride
()
{
return
3141
;
}
@Override
public
void
add
(
Object
value
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论