Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
477fbaf0
提交
477fbaf0
authored
7月 23, 2017
作者:
andrei
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'h2database/master' into full_text_mt
上级
e1a91d29
d351a574
显示空白字符变更
内嵌
并排
正在显示
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
浏览文件 @
477fbaf0
...
@@ -1165,6 +1165,19 @@ This setting is persistent.
...
@@ -1165,6 +1165,19 @@ This setting is persistent.
SET BINARY_COLLATION SIGNED
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","
"Commands (Other)","SET COLLATION","
SET [ DATABASE ] COLLATION
SET [ DATABASE ] COLLATION
{ OFF | collationName [ STRENGTH { PRIMARY | SECONDARY | TERTIARY | IDENTICAL } ] }
{ OFF | collationName [ STRENGTH { PRIMARY | SECONDARY | TERTIARY | IDENTICAL } ] }
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
477fbaf0
...
@@ -21,6 +21,8 @@ Change Log
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul>
<ul>
<li>
Issue #539: Allow override of builtin functions/aliases
</li>
<li>
Issue #535: Allow explicit paths on Windows without drive letter
<li>
Issue #535: Allow explicit paths on Windows without drive letter
</li>
</li>
<li>
Issue #549: Removed UNION ALL requirements for CTE
<li>
Issue #549: Removed UNION ALL requirements for CTE
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
477fbaf0
...
@@ -2707,10 +2707,17 @@ public class Parser {
...
@@ -2707,10 +2707,17 @@ public class Parser {
return
function
;
return
function
;
}
}
private
Funct
ion
readFunctionWithoutParameters
(
String
name
)
{
private
Express
ion
readFunctionWithoutParameters
(
String
name
)
{
if
(
readIf
(
"("
))
{
if
(
readIf
(
"("
))
{
read
(
")"
);
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
function
=
Function
.
getFunction
(
database
,
name
);
function
.
doneWithParameters
();
function
.
doneWithParameters
();
return
function
;
return
function
;
...
@@ -4850,8 +4857,18 @@ public class Parser {
...
@@ -4850,8 +4857,18 @@ public class Parser {
private
CreateFunctionAlias
parseCreateFunctionAlias
(
boolean
force
)
{
private
CreateFunctionAlias
parseCreateFunctionAlias
(
boolean
force
)
{
boolean
ifNotExists
=
readIfNotExists
();
boolean
ifNotExists
=
readIfNotExists
();
String
aliasName
=
readIdentifierWithSchema
();
final
boolean
newAliasSameNameAsBuiltin
=
Function
.
getFunction
(
database
,
currentToken
)
!=
null
;
if
(
isKeyword
(
aliasName
)
||
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
||
Function
.
getFunction
(
database
,
aliasName
)
!=
null
||
getAggregateType
(
aliasName
)
>=
0
)
{
getAggregateType
(
aliasName
)
>=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
throw
DbException
.
get
(
ErrorCode
.
FUNCTION_ALIAS_ALREADY_EXISTS_1
,
...
...
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
477fbaf0
...
@@ -524,6 +524,16 @@ public class Set extends Prepared {
...
@@ -524,6 +524,16 @@ public class Set extends Prepared {
session
.
setLazyQueryExecution
(
value
==
1
);
session
.
setLazyQueryExecution
(
value
==
1
);
break
;
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
:
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
DbException
.
throwInternalError
(
"type="
+
type
);
}
}
...
...
h2/src/main/org/h2/command/dml/SetTypes.java
浏览文件 @
477fbaf0
...
@@ -243,6 +243,11 @@ public class SetTypes {
...
@@ -243,6 +243,11 @@ public class SetTypes {
*/
*/
public
static
final
int
LAZY_QUERY_EXECUTION
=
46
;
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
static
final
ArrayList
<
String
>
TYPES
=
New
.
arrayList
();
private
SetTypes
()
{
private
SetTypes
()
{
...
@@ -298,6 +303,7 @@ public class SetTypes {
...
@@ -298,6 +303,7 @@ public class SetTypes {
list
.
add
(
BATCH_JOINS
,
"BATCH_JOINS"
);
list
.
add
(
BATCH_JOINS
,
"BATCH_JOINS"
);
list
.
add
(
FORCE_JOIN_ORDER
,
"FORCE_JOIN_ORDER"
);
list
.
add
(
FORCE_JOIN_ORDER
,
"FORCE_JOIN_ORDER"
);
list
.
add
(
LAZY_QUERY_EXECUTION
,
"LAZY_QUERY_EXECUTION"
);
list
.
add
(
LAZY_QUERY_EXECUTION
,
"LAZY_QUERY_EXECUTION"
);
list
.
add
(
BUILTIN_ALIAS_OVERRIDE
,
"BUILTIN_ALIAS_OVERRIDE"
);
}
}
/**
/**
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
477fbaf0
...
@@ -191,6 +191,7 @@ public class Database implements DataHandler {
...
@@ -191,6 +191,7 @@ public class Database implements DataHandler {
private
int
logMode
;
private
int
logMode
;
private
MVTableEngine
.
Store
mvStore
;
private
MVTableEngine
.
Store
mvStore
;
private
int
retentionTime
;
private
int
retentionTime
;
private
boolean
allowBuiltinAliasOverride
;
private
DbException
backgroundException
;
private
DbException
backgroundException
;
private
JavaObjectSerializer
javaObjectSerializer
;
private
JavaObjectSerializer
javaObjectSerializer
;
private
String
javaObjectSerializerName
;
private
String
javaObjectSerializerName
;
...
@@ -1984,6 +1985,14 @@ public class Database implements DataHandler {
...
@@ -1984,6 +1985,14 @@ public class Database implements DataHandler {
}
}
}
}
public
void
setAllowBuiltinAliasOverride
(
boolean
b
)
{
allowBuiltinAliasOverride
=
b
;
}
public
boolean
isAllowBuiltinAliasOverride
()
{
return
allowBuiltinAliasOverride
;
}
/**
/**
* Check if flush-on-each-commit is enabled.
* Check if flush-on-each-commit is enabled.
*
*
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
477fbaf0
...
@@ -76,6 +76,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -76,6 +76,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
testOverrideAlias
();
testIfNull
();
testIfNull
();
testToDate
();
testToDate
();
testToDateException
();
testToDateException
();
...
@@ -1671,7 +1672,9 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1671,7 +1672,9 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
conn
.
close
();
}
}
private
void
testIfNull
()
throws
SQLException
{
private
void
testIfNull
()
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
(
Statement
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
...
@@ -2113,6 +2116,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -2113,6 +2116,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
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
{
private
void
callCompiledFunction
(
String
functionName
)
throws
SQLException
{
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
try
(
Connection
conn
=
getConnection
(
"functions"
))
{
try
(
Connection
conn
=
getConnection
(
"functions"
))
{
...
@@ -2431,6 +2454,13 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -2431,6 +2454,13 @@ public class TestFunctions extends TestBase implements AggregateFunction {
return
new
Object
[]
{
buff
.
toString
()
};
return
new
Object
[]
{
buff
.
toString
()
};
}
}
/**
* This method is called via reflection from the database.
*/
public
static
long
currentTimestampOverride
()
{
return
3141
;
}
@Override
@Override
public
void
add
(
Object
value
)
{
public
void
add
(
Object
value
)
{
// ignore
// ignore
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论