Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d071f831
提交
d071f831
authored
8月 11, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add NEWID() as alias to RANDOM_UUID() in SQL Server compatibility mode
上级
5e5e6b00
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
109 行增加
和
20 行删除
+109
-20
Mode.java
h2/src/main/org/h2/engine/Mode.java
+11
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+20
-10
FunctionInfo.java
h2/src/main/org/h2/expression/FunctionInfo.java
+60
-10
random-uuid.sql
...est/org/h2/test/scripts/functions/numeric/random-uuid.sql
+18
-0
没有找到文件。
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
d071f831
...
@@ -10,6 +10,8 @@ import java.util.Collections;
...
@@ -10,6 +10,8 @@ import java.util.Collections;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
org.h2.expression.Function
;
import
org.h2.expression.FunctionInfo
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -204,6 +206,8 @@ public class Mode {
...
@@ -204,6 +206,8 @@ public class Mode {
*/
*/
public
HashMap
<
String
,
DataType
>
typeByNameMap
=
new
HashMap
<>();
public
HashMap
<
String
,
DataType
>
typeByNameMap
=
new
HashMap
<>();
public
HashMap
<
String
,
FunctionInfo
>
functionAliases
;
private
final
String
name
;
private
final
String
name
;
private
final
ModeEnum
modeEnum
;
private
final
ModeEnum
modeEnum
;
...
@@ -269,6 +273,9 @@ public class Mode {
...
@@ -269,6 +273,9 @@ public class Mode {
dt
.
sqlType
=
Types
.
NUMERIC
;
dt
.
sqlType
=
Types
.
NUMERIC
;
dt
.
name
=
"SMALLMONEY"
;
dt
.
name
=
"SMALLMONEY"
;
mode
.
typeByNameMap
.
put
(
"SMALLMONEY"
,
dt
);
mode
.
typeByNameMap
.
put
(
"SMALLMONEY"
,
dt
);
HashMap
<
String
,
FunctionInfo
>
functions
=
new
HashMap
<>();
copyFunction
(
functions
,
"RANDOM_UUID"
,
"NEWID"
);
mode
.
functionAliases
=
functions
;
add
(
mode
);
add
(
mode
);
mode
=
new
Mode
(
ModeEnum
.
MySQL
);
mode
=
new
Mode
(
ModeEnum
.
MySQL
);
...
@@ -342,6 +349,10 @@ public class Mode {
...
@@ -342,6 +349,10 @@ public class Mode {
add
(
mode
);
add
(
mode
);
}
}
static
void
copyFunction
(
HashMap
<
String
,
FunctionInfo
>
functions
,
String
stdName
,
String
newName
)
{
functions
.
put
(
newName
,
new
FunctionInfo
(
Function
.
getFunctionInfo
(
stdName
),
newName
));
}
private
Mode
(
ModeEnum
modeEnum
)
{
private
Mode
(
ModeEnum
modeEnum
)
{
this
.
name
=
modeEnum
.
name
();
this
.
name
=
modeEnum
.
name
();
this
.
modeEnum
=
modeEnum
;
this
.
modeEnum
=
modeEnum
;
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
d071f831
...
@@ -487,15 +487,8 @@ public class Function extends Expression implements FunctionCall {
...
@@ -487,15 +487,8 @@ public class Function extends Expression implements FunctionCall {
private
static
void
addFunction
(
String
name
,
int
type
,
int
parameterCount
,
private
static
void
addFunction
(
String
name
,
int
type
,
int
parameterCount
,
int
returnDataType
,
boolean
nullIfParameterIsNull
,
boolean
deterministic
,
int
returnDataType
,
boolean
nullIfParameterIsNull
,
boolean
deterministic
,
boolean
bufferResultSetToLocalTemp
)
{
boolean
bufferResultSetToLocalTemp
)
{
FunctionInfo
info
=
new
FunctionInfo
();
FUNCTIONS
.
put
(
name
,
new
FunctionInfo
(
name
,
type
,
parameterCount
,
returnDataType
,
nullIfParameterIsNull
,
info
.
name
=
name
;
deterministic
,
bufferResultSetToLocalTemp
));
info
.
type
=
type
;
info
.
parameterCount
=
parameterCount
;
info
.
returnDataType
=
returnDataType
;
info
.
nullIfParameterIsNull
=
nullIfParameterIsNull
;
info
.
deterministic
=
deterministic
;
info
.
bufferResultSetToLocalTemp
=
bufferResultSetToLocalTemp
;
FUNCTIONS
.
put
(
name
,
info
);
}
}
private
static
void
addFunctionNotDeterministic
(
String
name
,
int
type
,
private
static
void
addFunctionNotDeterministic
(
String
name
,
int
type
,
...
@@ -528,7 +521,14 @@ public class Function extends Expression implements FunctionCall {
...
@@ -528,7 +521,14 @@ public class Function extends Expression implements FunctionCall {
}
}
FunctionInfo
info
=
FUNCTIONS
.
get
(
name
);
FunctionInfo
info
=
FUNCTIONS
.
get
(
name
);
if
(
info
==
null
)
{
if
(
info
==
null
)
{
return
null
;
HashMap
<
String
,
FunctionInfo
>
aliases
=
database
.
getMode
().
functionAliases
;
if
(
aliases
==
null
)
{
return
null
;
}
info
=
aliases
.
get
(
name
);
if
(
info
==
null
)
{
return
null
;
}
}
}
switch
(
info
.
type
)
{
switch
(
info
.
type
)
{
case
TABLE:
case
TABLE:
...
@@ -539,6 +539,16 @@ public class Function extends Expression implements FunctionCall {
...
@@ -539,6 +539,16 @@ public class Function extends Expression implements FunctionCall {
}
}
}
}
/**
* Returns function information for the specified function name.
*
* @param upperName the function name in upper case
* @return the function information or {@code null}
*/
public
static
FunctionInfo
getFunctionInfo
(
String
upperName
)
{
return
FUNCTIONS
.
get
(
upperName
);
}
/**
/**
* Set the parameter expression at the given index.
* Set the parameter expression at the given index.
*
*
...
...
h2/src/main/org/h2/expression/FunctionInfo.java
浏览文件 @
d071f831
...
@@ -8,41 +8,91 @@ package org.h2.expression;
...
@@ -8,41 +8,91 @@ package org.h2.expression;
/**
/**
* This class contains information about a built-in function.
* This class contains information about a built-in function.
*/
*/
class
FunctionInfo
{
public
final
class
FunctionInfo
{
/**
/**
* The name of the function.
* The name of the function.
*/
*/
String
name
;
final
String
name
;
/**
/**
* The function type.
* The function type.
*/
*/
int
type
;
final
int
type
;
/**
/**
* The
data type of the return value
.
* The
number of parameters
.
*/
*/
int
returnDataType
;
final
int
parameterCount
;
/**
/**
* The
number of parameters
.
* The
data type of the return value
.
*/
*/
int
parameterCount
;
final
int
returnDataType
;
/**
/**
* If the result of the function is NULL if any of the parameters is NULL.
* If the result of the function is NULL if any of the parameters is NULL.
*/
*/
boolean
nullIfParameterIsNull
;
final
boolean
nullIfParameterIsNull
;
/**
/**
* If this function always returns the same value for the same parameters.
* If this function always returns the same value for the same parameters.
*/
*/
boolean
deterministic
;
final
boolean
deterministic
;
/**
/**
* Should the return value ResultSet be buffered in a local temporary file?
* Should the return value ResultSet be buffered in a local temporary file?
*/
*/
boolean
bufferResultSetToLocalTemp
=
true
;
final
boolean
bufferResultSetToLocalTemp
;
/**
* Creates new instance of built-in function information.
*
* @param name
* the name of the function
* @param type
* the function type
* @param parameterCount
* the number of parameters
* @param returnDataType
* the data type of the return value
* @param nullIfParameterIsNull
* if the result of the function is NULL if any of the parameters
* is NULL
* @param deterministic
* if this function always returns the same value for the same
* parameters
* @param bufferResultSetToLocalTemp
* should the return value ResultSet be buffered in a local
* temporary file?
*/
FunctionInfo
(
String
name
,
int
type
,
int
parameterCount
,
int
returnDataType
,
boolean
nullIfParameterIsNull
,
boolean
deterministic
,
boolean
bufferResultSetToLocalTemp
)
{
this
.
name
=
name
;
this
.
type
=
type
;
this
.
parameterCount
=
parameterCount
;
this
.
returnDataType
=
returnDataType
;
this
.
nullIfParameterIsNull
=
nullIfParameterIsNull
;
this
.
deterministic
=
deterministic
;
this
.
bufferResultSetToLocalTemp
=
bufferResultSetToLocalTemp
;
}
/**
* Creates a copy of built-in function information with a different name.
*
* @param source
* the source information
* @param name
* the new name
*/
public
FunctionInfo
(
FunctionInfo
source
,
String
name
)
{
this
.
name
=
name
;
type
=
source
.
type
;
returnDataType
=
source
.
returnDataType
;
parameterCount
=
source
.
parameterCount
;
nullIfParameterIsNull
=
source
.
nullIfParameterIsNull
;
deterministic
=
source
.
deterministic
;
bufferResultSetToLocalTemp
=
source
.
bufferResultSetToLocalTemp
;
}
}
}
h2/src/test/org/h2/test/scripts/functions/numeric/random-uuid.sql
浏览文件 @
d071f831
...
@@ -2,3 +2,21 @@
...
@@ -2,3 +2,21 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
-- Initial Developer: H2 Group
--
--
SELECT
LENGTH
(
CAST
(
RANDOM_UUID
()
AS
VARCHAR
));
>>
36
SELECT
RANDOM_UUID
()
=
RANDOM_UUID
();
>>
FALSE
SELECT
NEWID
();
>
exception
FUNCTION_NOT_FOUND_1
SET
MODE
MSSQLServer
;
>
ok
SELECT
LENGTH
(
CAST
(
NEWID
()
AS
VARCHAR
));
>>
36
SET
MODE
Regular
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论