Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7dc0d946
Unverified
提交
7dc0d946
authored
8月 09, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
8月 09, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1362 from katzyn/mode
Add limited support for MONEY and SMALLMONEY in compatibility modes
上级
07e4ef94
0927d1ac
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
99 行增加
和
8 行删除
+99
-8
features.html
h2/src/docsrc/html/features.html
+4
-1
Mode.java
h2/src/main/org/h2/engine/Mode.java
+21
-1
DataType.java
h2/src/main/org/h2/value/DataType.java
+24
-2
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+46
-0
TestCompatibilityOracle.java
h2/src/test/org/h2/test/db/TestCompatibilityOracle.java
+4
-4
没有找到文件。
h2/src/docsrc/html/features.html
浏览文件 @
7dc0d946
...
@@ -1096,6 +1096,8 @@ or the SQL statement <code>SET MODE MSSQLServer</code>.
...
@@ -1096,6 +1096,8 @@ or the SQL statement <code>SET MODE MSSQLServer</code>.
</li><li>
Concatenating
<code>
NULL
</code>
with another value
</li><li>
Concatenating
<code>
NULL
</code>
with another value
results in the other value.
results in the other value.
</li><li>
Text can be concatenated using '+'.
</li><li>
Text can be concatenated using '+'.
</li><li>
MONEY data type is treated like NUMERIC(19, 4) data type. SMALLMONEY data type is treated like NUMERIC(10, 4)
data type.
</li></ul>
</li></ul>
<h3>
MySQL Compatibility Mode
</h3>
<h3>
MySQL Compatibility Mode
</h3>
...
@@ -1141,7 +1143,7 @@ or the SQL statement <code>SET MODE Oracle</code>.
...
@@ -1141,7 +1143,7 @@ or the SQL statement <code>SET MODE Oracle</code>.
results in the other value.
results in the other value.
</li><li>
Empty strings are treated like
<code>
NULL
</code>
values.
</li><li>
Empty strings are treated like
<code>
NULL
</code>
values.
</li><li>
REGEXP_REPLACE() uses \ for back-references.
</li><li>
REGEXP_REPLACE() uses \ for back-references.
</li><li>
DATE data type is treated like TIMESTAMP data type.
</li><li>
DATE data type is treated like TIMESTAMP
(0)
data type.
</li></ul>
</li></ul>
<h3>
PostgreSQL Compatibility Mode
</h3>
<h3>
PostgreSQL Compatibility Mode
</h3>
...
@@ -1159,6 +1161,7 @@ or the SQL statement <code>SET MODE PostgreSQL</code>.
...
@@ -1159,6 +1161,7 @@ or the SQL statement <code>SET MODE PostgreSQL</code>.
</li><li>
LOG(x) is base 10 in this mode.
</li><li>
LOG(x) is base 10 in this mode.
</li><li>
REGEXP_REPLACE() uses \ for back-references.
</li><li>
REGEXP_REPLACE() uses \ for back-references.
</li><li>
Fixed-width strings are padded with spaces.
</li><li>
Fixed-width strings are padded with spaces.
</li><li>
MONEY data type is treated like NUMERIC(19, 2) data type.
</li></ul>
</li></ul>
<h3>
Ignite Compatibility Mode
</h3>
<h3>
Ignite Compatibility Mode
</h3>
...
...
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
7dc0d946
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
org
.
h2
.
engine
;
package
org
.
h2
.
engine
;
import
java.sql.Types
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -258,6 +259,16 @@ public class Mode {
...
@@ -258,6 +259,16 @@ public class Mode {
// MS SQL Server does not support client info properties. See
// MS SQL Server does not support client info properties. See
// https://msdn.microsoft.com/en-Us/library/dd571296%28v=sql.110%29.aspx
// https://msdn.microsoft.com/en-Us/library/dd571296%28v=sql.110%29.aspx
mode
.
supportedClientInfoPropertiesRegEx
=
null
;
mode
.
supportedClientInfoPropertiesRegEx
=
null
;
DataType
dt
=
DataType
.
createDecimal
(
19
,
19
,
4
,
21
,
false
,
false
);
dt
.
type
=
Value
.
DECIMAL
;
dt
.
sqlType
=
Types
.
NUMERIC
;
dt
.
name
=
"MONEY"
;
mode
.
typeByNameMap
.
put
(
"MONEY"
,
dt
);
dt
=
DataType
.
createDecimal
(
10
,
10
,
4
,
12
,
false
,
false
);
dt
.
type
=
Value
.
DECIMAL
;
dt
.
sqlType
=
Types
.
NUMERIC
;
dt
.
name
=
"SMALLMONEY"
;
mode
.
typeByNameMap
.
put
(
"SMALLMONEY"
,
dt
);
add
(
mode
);
add
(
mode
);
mode
=
new
Mode
(
ModeEnum
.
MySQL
);
mode
=
new
Mode
(
ModeEnum
.
MySQL
);
...
@@ -289,7 +300,11 @@ public class Mode {
...
@@ -289,7 +300,11 @@ public class Mode {
mode
.
supportedClientInfoPropertiesRegEx
=
mode
.
supportedClientInfoPropertiesRegEx
=
Pattern
.
compile
(
".*\\..*"
);
Pattern
.
compile
(
".*\\..*"
);
mode
.
prohibitEmptyInPredicate
=
true
;
mode
.
prohibitEmptyInPredicate
=
true
;
mode
.
typeByNameMap
.
put
(
"DATE"
,
DataType
.
getDataType
(
Value
.
TIMESTAMP
));
dt
=
DataType
.
createDate
(
/* 2001-01-01 23:59:59 */
19
,
19
,
"DATE"
,
false
,
0
,
0
);
dt
.
type
=
Value
.
TIMESTAMP
;
dt
.
sqlType
=
Types
.
TIMESTAMP
;
dt
.
name
=
"DATE"
;
mode
.
typeByNameMap
.
put
(
"DATE"
,
dt
);
add
(
mode
);
add
(
mode
);
mode
=
new
Mode
(
ModeEnum
.
PostgreSQL
);
mode
=
new
Mode
(
ModeEnum
.
PostgreSQL
);
...
@@ -313,6 +328,11 @@ public class Mode {
...
@@ -313,6 +328,11 @@ public class Mode {
disallowedTypes
.
add
(
"TINYINT"
);
disallowedTypes
.
add
(
"TINYINT"
);
disallowedTypes
.
add
(
"BLOB"
);
disallowedTypes
.
add
(
"BLOB"
);
mode
.
disallowedTypes
=
disallowedTypes
;
mode
.
disallowedTypes
=
disallowedTypes
;
dt
=
DataType
.
createDecimal
(
19
,
19
,
2
,
21
,
false
,
false
);
dt
.
type
=
Value
.
DECIMAL
;
dt
.
sqlType
=
Types
.
NUMERIC
;
dt
.
name
=
"MONEY"
;
mode
.
typeByNameMap
.
put
(
"MONEY"
,
dt
);
add
(
mode
);
add
(
mode
);
mode
=
new
Mode
(
ModeEnum
.
Ignite
);
mode
=
new
Mode
(
ModeEnum
.
Ignite
);
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
7dc0d946
...
@@ -448,7 +448,18 @@ public class DataType {
...
@@ -448,7 +448,18 @@ public class DataType {
}
}
}
}
private
static
DataType
createDecimal
(
int
maxPrecision
,
/**
* Create a numeric data type.
*
* @param maxPrecision maximum supported precision
* @param defaultPrecision default precision
* @param defaultScale default scale
* @param defaultDisplaySize default display size
* @param needsPrecisionAndScale where precision and scale are supported
* @param autoInc whether the data type is an auto-increment type
* @return data type
*/
public
static
DataType
createDecimal
(
int
maxPrecision
,
int
defaultPrecision
,
int
defaultScale
,
int
defaultDisplaySize
,
int
defaultPrecision
,
int
defaultScale
,
int
defaultDisplaySize
,
boolean
needsPrecisionAndScale
,
boolean
autoInc
)
{
boolean
needsPrecisionAndScale
,
boolean
autoInc
)
{
DataType
dataType
=
new
DataType
();
DataType
dataType
=
new
DataType
();
...
@@ -466,7 +477,18 @@ public class DataType {
...
@@ -466,7 +477,18 @@ public class DataType {
return
dataType
;
return
dataType
;
}
}
private
static
DataType
createDate
(
int
maxPrecision
,
int
precision
,
String
prefix
,
/**
* Create a date-time data type.
*
* @param maxPrecision maximum supported precision
* @param precision default precision
* @param prefix the prefix for SQL literal representation
* @param supportsScale whether the scale parameter is supported
* @param scale default scale
* @param maxScale highest possible scale
* @return data type
*/
public
static
DataType
createDate
(
int
maxPrecision
,
int
precision
,
String
prefix
,
boolean
supportsScale
,
int
scale
,
int
maxScale
)
{
boolean
supportsScale
,
int
scale
,
int
maxScale
)
{
DataType
dataType
=
new
DataType
();
DataType
dataType
=
new
DataType
();
dataType
.
prefix
=
prefix
+
" '"
;
dataType
.
prefix
=
prefix
+
" '"
;
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
7dc0d946
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
org
.
h2
.
test
.
db
;
package
org
.
h2
.
test
.
db
;
import
java.math.BigDecimal
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.DatabaseMetaData
;
...
@@ -276,6 +277,21 @@ public class TestCompatibility extends TestDb {
...
@@ -276,6 +277,21 @@ public class TestCompatibility extends TestDb {
/* Expected! */
/* Expected! */
}
}
}
}
/* Test MONEY data type */
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(M MONEY)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (-92233720368547758.08)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (0.11111)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (92233720368547758.07)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT M FROM TEST ORDER BY M"
);
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"-92233720368547758.08"
),
rs
.
getBigDecimal
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"0.11"
),
rs
.
getBigDecimal
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"92233720368547758.07"
),
rs
.
getBigDecimal
(
1
));
assertFalse
(
rs
.
next
());
}
}
private
void
testMySQL
()
throws
SQLException
{
private
void
testMySQL
()
throws
SQLException
{
...
@@ -496,6 +512,36 @@ public class TestCompatibility extends TestDb {
...
@@ -496,6 +512,36 @@ public class TestCompatibility extends TestDb {
// UNIQUEIDENTIFIER is MSSQL's equivalent of UUID
// UNIQUEIDENTIFIER is MSSQL's equivalent of UUID
stat
.
execute
(
"create table test3 (id UNIQUEIDENTIFIER)"
);
stat
.
execute
(
"create table test3 (id UNIQUEIDENTIFIER)"
);
/* Test MONEY data type */
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(M MONEY)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (-922337203685477.5808)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (0.11111)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (922337203685477.5807)"
);
rs
=
stat
.
executeQuery
(
"SELECT M FROM TEST ORDER BY M"
);
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"-922337203685477.5808"
),
rs
.
getBigDecimal
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"0.1111"
),
rs
.
getBigDecimal
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"922337203685477.5807"
),
rs
.
getBigDecimal
(
1
));
assertFalse
(
rs
.
next
());
/* Test SMALLMONEY data type */
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(M SMALLMONEY)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (-214748.3648)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (0.11111)"
);
stat
.
execute
(
"INSERT INTO TEST(M) VALUES (214748.3647)"
);
rs
=
stat
.
executeQuery
(
"SELECT M FROM TEST ORDER BY M"
);
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"-214748.3648"
),
rs
.
getBigDecimal
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"0.1111"
),
rs
.
getBigDecimal
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
new
BigDecimal
(
"214748.3647"
),
rs
.
getBigDecimal
(
1
));
assertFalse
(
rs
.
next
());
}
}
private
void
testDB2
()
throws
SQLException
{
private
void
testDB2
()
throws
SQLException
{
...
...
h2/src/test/org/h2/test/db/TestCompatibilityOracle.java
浏览文件 @
7dc0d946
...
@@ -263,12 +263,12 @@ public class TestCompatibilityOracle extends TestDb {
...
@@ -263,12 +263,12 @@ public class TestCompatibilityOracle extends TestDb {
Timestamp
t4
=
Timestamp
.
valueOf
(
"2018-01-10 22:10:01"
);
Timestamp
t4
=
Timestamp
.
valueOf
(
"2018-01-10 22:10:01"
);
stat
.
execute
(
"CREATE TABLE TEST (ID INT PRIMARY KEY, D DATE)"
);
stat
.
execute
(
"CREATE TABLE TEST (ID INT PRIMARY KEY, D DATE)"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(1, TIMESTAMP '2011-02-03 12:11:10')"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(1, TIMESTAMP '2011-02-03 12:11:10
.1
')"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(2, CAST ('1999-10-15 13:14:15' AS DATE))"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(2, CAST ('1999-10-15 13:14:15
.1
' AS DATE))"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(3, '2030-11-22 11:22:33')"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(3, '2030-11-22 11:22:33
.1
')"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES (?, ?)"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES (?, ?)"
);
ps
.
setInt
(
1
,
4
);
ps
.
setInt
(
1
,
4
);
ps
.
setTimestamp
(
2
,
t4
);
ps
.
setTimestamp
(
2
,
Timestamp
.
valueOf
(
"2018-01-10 22:10:01.1"
)
);
ps
.
executeUpdate
();
ps
.
executeUpdate
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT D FROM TEST ORDER BY ID"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT D FROM TEST ORDER BY ID"
);
rs
.
next
();
rs
.
next
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论