Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e9571b3c
提交
e9571b3c
authored
3月 07, 2011
作者:
noelgrandin@gmail.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue 292: Support for modulus operator
Added support for modulus operator in expressions
上级
6140fcaa
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
135 行增加
和
6 行删除
+135
-6
help.csv
h2/src/docsrc/help/help.csv
+1
-1
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
roadmap.html
h2/src/docsrc/html/roadmap.html
+0
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+4
-1
Operation.java
h2/src/main/org/h2/expression/Operation.java
+13
-0
help.csv
h2/src/main/org/h2/res/help.csv
+1
-1
Value.java
h2/src/main/org/h2/value/Value.java
+10
-0
ValueByte.java
h2/src/main/org/h2/value/ValueByte.java
+8
-0
ValueDecimal.java
h2/src/main/org/h2/value/ValueDecimal.java
+9
-0
ValueDouble.java
h2/src/main/org/h2/value/ValueDouble.java
+8
-0
ValueFloat.java
h2/src/main/org/h2/value/ValueFloat.java
+8
-0
ValueInt.java
h2/src/main/org/h2/value/ValueInt.java
+8
-0
ValueLong.java
h2/src/main/org/h2/value/ValueLong.java
+8
-0
ValueShort.java
h2/src/main/org/h2/value/ValueShort.java
+8
-0
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+45
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
e9571b3c
...
@@ -1748,7 +1748,7 @@ ID=1 OR NAME='Hi'
...
@@ -1748,7 +1748,7 @@ ID=1 OR NAME='Hi'
"
"
"Other Grammar","Factor","
"Other Grammar","Factor","
term [ { { * | / } term } [...] ]
term [ { { * | /
| %
} term } [...] ]
","
","
A value or a numeric factor.
A value or a numeric factor.
","
","
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
e9571b3c
...
@@ -18,7 +18,9 @@ Change Log
...
@@ -18,7 +18,9 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
Issue 288: Some right outer join queries failed to produce the correct result or
<ul>
<li>
Support for the % operator (modulo) thanks to Noel Grandin.
</li><li>
Issue 288: Some right outer join queries failed to produce the correct result or
threw exceptions such as "column x must be in the group by list".
threw exceptions such as "column x must be in the group by list".
</li><li>
Some right outer joins with invalid column referenced (typos) threw a NullPointerException instead of
</li><li>
Some right outer joins with invalid column referenced (typos) threw a NullPointerException instead of
"column not found" exception.
"column not found" exception.
...
...
h2/src/docsrc/html/roadmap.html
浏览文件 @
e9571b3c
...
@@ -181,7 +181,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
...
@@ -181,7 +181,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>
Compatibility with Derby and PostgreSQL: VALUES(1), (2); SELECT * FROM (VALUES (1), (2)) AS myTable(c1). Issue 221.
</li><li>
Compatibility with Derby and PostgreSQL: VALUES(1), (2); SELECT * FROM (VALUES (1), (2)) AS myTable(c1). Issue 221.
</li><li>
Allow execution time prepare for SELECT * FROM CSVREAD(?, 'columnNameString')
</li><li>
Allow execution time prepare for SELECT * FROM CSVREAD(?, 'columnNameString')
</li><li>
Support data type INTERVAL
</li><li>
Support data type INTERVAL
</li><li>
Support % operator (modulo).
</li><li>
Support nested transactions (possibly using savepoints internally).
</li><li>
Support nested transactions (possibly using savepoints internally).
</li><li>
Add a benchmark for bigger databases, and one for many users.
</li><li>
Add a benchmark for bigger databases, and one for many users.
</li><li>
Compression in the result set over TCP/IP.
</li><li>
Compression in the result set over TCP/IP.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e9571b3c
...
@@ -123,8 +123,8 @@ import org.h2.table.IndexColumn;
...
@@ -123,8 +123,8 @@ import org.h2.table.IndexColumn;
import
org.h2.table.RangeTable
;
import
org.h2.table.RangeTable
;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter.TableFilterVisitor
;
import
org.h2.table.TableView
;
import
org.h2.table.TableView
;
import
org.h2.table.TableFilter.TableFilterVisitor
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StatementBuilder
;
...
@@ -1996,6 +1996,8 @@ public class Parser {
...
@@ -1996,6 +1996,8 @@ public class Parser {
r
=
new
Operation
(
Operation
.
MULTIPLY
,
r
,
readTerm
());
r
=
new
Operation
(
Operation
.
MULTIPLY
,
r
,
readTerm
());
}
else
if
(
readIf
(
"/"
))
{
}
else
if
(
readIf
(
"/"
))
{
r
=
new
Operation
(
Operation
.
DIVIDE
,
r
,
readTerm
());
r
=
new
Operation
(
Operation
.
DIVIDE
,
r
,
readTerm
());
}
else
if
(
readIf
(
"%"
))
{
r
=
new
Operation
(
Operation
.
MODULUS
,
r
,
readTerm
());
}
else
{
}
else
{
return
r
;
return
r
;
}
}
...
@@ -3237,6 +3239,7 @@ public class Parser {
...
@@ -3237,6 +3239,7 @@ public class Parser {
case
'}'
:
case
'}'
:
case
'*'
:
case
'*'
:
case
'/'
:
case
'/'
:
case
'%'
:
case
';'
:
case
';'
:
case
','
:
case
','
:
case
':'
:
case
':'
:
...
...
h2/src/main/org/h2/expression/Operation.java
浏览文件 @
e9571b3c
...
@@ -53,6 +53,11 @@ public class Operation extends Expression {
...
@@ -53,6 +53,11 @@ public class Operation extends Expression {
*/
*/
public
static
final
int
NEGATE
=
5
;
public
static
final
int
NEGATE
=
5
;
/**
* This operation represents a modulus as in 5 % 2.
*/
public
static
final
int
MODULUS
=
6
;
private
int
opType
;
private
int
opType
;
private
Expression
left
,
right
;
private
Expression
left
,
right
;
private
int
dataType
;
private
int
dataType
;
...
@@ -92,6 +97,8 @@ public class Operation extends Expression {
...
@@ -92,6 +97,8 @@ public class Operation extends Expression {
return
"*"
;
return
"*"
;
case
DIVIDE:
case
DIVIDE:
return
"/"
;
return
"/"
;
case
MODULUS:
return
"%"
;
default
:
default
:
throw
DbException
.
throwInternalError
(
"opType="
+
opType
);
throw
DbException
.
throwInternalError
(
"opType="
+
opType
);
}
}
...
@@ -149,6 +156,11 @@ public class Operation extends Expression {
...
@@ -149,6 +156,11 @@ public class Operation extends Expression {
return
ValueNull
.
INSTANCE
;
return
ValueNull
.
INSTANCE
;
}
}
return
l
.
divide
(
r
);
return
l
.
divide
(
r
);
case
MODULUS:
if
(
l
==
ValueNull
.
INSTANCE
||
r
==
ValueNull
.
INSTANCE
)
{
return
ValueNull
.
INSTANCE
;
}
return
l
.
modulus
(
r
);
default
:
default
:
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
}
}
...
@@ -181,6 +193,7 @@ public class Operation extends Expression {
...
@@ -181,6 +193,7 @@ public class Operation extends Expression {
case
MINUS:
case
MINUS:
case
MULTIPLY:
case
MULTIPLY:
case
DIVIDE:
case
DIVIDE:
case
MODULUS:
right
=
right
.
optimize
(
session
);
right
=
right
.
optimize
(
session
);
int
l
=
left
.
getType
();
int
l
=
left
.
getType
();
int
r
=
right
.
getType
();
int
r
=
right
.
getType
();
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
e9571b3c
...
@@ -582,7 +582,7 @@ andCondition [ { OR andCondition } [...] ]
...
@@ -582,7 +582,7 @@ andCondition [ { OR andCondition } [...] ]
","
","
Value or condition."
Value or condition."
"Other Grammar","Factor","
"Other Grammar","Factor","
term [ { { * | / } term } [...] ]
term [ { { * | /
| %
} term } [...] ]
","
","
A value or a numeric factor."
A value or a numeric factor."
"Other Grammar","Hex","
"Other Grammar","Hex","
...
...
h2/src/main/org/h2/value/Value.java
浏览文件 @
e9571b3c
...
@@ -485,6 +485,16 @@ public abstract class Value {
...
@@ -485,6 +485,16 @@ public abstract class Value {
throw
throwUnsupportedExceptionForType
(
"*"
);
throw
throwUnsupportedExceptionForType
(
"*"
);
}
}
/**
* Take the modulus with a value and return the result.
*
* @param v the value to take the modulus with
* @return the result
*/
public
Value
modulus
(
Value
v
)
{
throw
throwUnsupportedExceptionForType
(
"%"
);
}
/**
/**
* Compare a value to the specified type.
* Compare a value to the specified type.
*
*
...
...
h2/src/main/org/h2/value/ValueByte.java
浏览文件 @
e9571b3c
...
@@ -72,6 +72,14 @@ public class ValueByte extends Value {
...
@@ -72,6 +72,14 @@ public class ValueByte extends Value {
return
ValueByte
.
get
((
byte
)
(
value
/
other
.
value
));
return
ValueByte
.
get
((
byte
)
(
value
/
other
.
value
));
}
}
public
Value
modulus
(
Value
v
)
{
ValueByte
other
=
(
ValueByte
)
v
;
if
(
other
.
value
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
return
ValueByte
.
get
((
byte
)
(
value
%
other
.
value
));
}
public
String
getSQL
()
{
public
String
getSQL
()
{
return
getString
();
return
getString
();
}
}
...
...
h2/src/main/org/h2/value/ValueDecimal.java
浏览文件 @
e9571b3c
...
@@ -104,6 +104,15 @@ public class ValueDecimal extends Value {
...
@@ -104,6 +104,15 @@ public class ValueDecimal extends Value {
return
ValueDecimal
.
get
(
bd
);
return
ValueDecimal
.
get
(
bd
);
}
}
public
ValueDecimal
modulus
(
Value
v
)
{
ValueDecimal
dec
=
(
ValueDecimal
)
v
;
if
(
dec
.
value
.
signum
()
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
BigDecimal
bd
=
value
.
remainder
(
dec
.
value
);
return
ValueDecimal
.
get
(
bd
);
}
public
String
getSQL
()
{
public
String
getSQL
()
{
return
getString
();
return
getString
();
}
}
...
...
h2/src/main/org/h2/value/ValueDouble.java
浏览文件 @
e9571b3c
...
@@ -69,6 +69,14 @@ public class ValueDouble extends Value {
...
@@ -69,6 +69,14 @@ public class ValueDouble extends Value {
return
ValueDouble
.
get
(
value
/
v2
.
value
);
return
ValueDouble
.
get
(
value
/
v2
.
value
);
}
}
public
ValueDouble
modulus
(
Value
v
)
{
ValueDouble
other
=
(
ValueDouble
)
v
;
if
(
other
.
value
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
return
ValueDouble
.
get
(
value
%
other
.
value
);
}
public
String
getSQL
()
{
public
String
getSQL
()
{
if
(
value
==
Double
.
POSITIVE_INFINITY
)
{
if
(
value
==
Double
.
POSITIVE_INFINITY
)
{
return
"POWER(0, -1)"
;
return
"POWER(0, -1)"
;
...
...
h2/src/main/org/h2/value/ValueFloat.java
浏览文件 @
e9571b3c
...
@@ -68,6 +68,14 @@ public class ValueFloat extends Value {
...
@@ -68,6 +68,14 @@ public class ValueFloat extends Value {
return
ValueFloat
.
get
(
value
/
v2
.
value
);
return
ValueFloat
.
get
(
value
/
v2
.
value
);
}
}
public
Value
modulus
(
Value
v
)
{
ValueFloat
other
=
(
ValueFloat
)
v
;
if
(
other
.
value
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
return
ValueFloat
.
get
(
value
%
other
.
value
);
}
public
String
getSQL
()
{
public
String
getSQL
()
{
if
(
value
==
Float
.
POSITIVE_INFINITY
)
{
if
(
value
==
Float
.
POSITIVE_INFINITY
)
{
return
"POWER(0, -1)"
;
return
"POWER(0, -1)"
;
...
...
h2/src/main/org/h2/value/ValueInt.java
浏览文件 @
e9571b3c
...
@@ -102,6 +102,14 @@ public class ValueInt extends Value {
...
@@ -102,6 +102,14 @@ public class ValueInt extends Value {
return
ValueInt
.
get
(
value
/
other
.
value
);
return
ValueInt
.
get
(
value
/
other
.
value
);
}
}
public
Value
modulus
(
Value
v
)
{
ValueInt
other
=
(
ValueInt
)
v
;
if
(
other
.
value
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
return
ValueInt
.
get
(
value
%
other
.
value
);
}
public
String
getSQL
()
{
public
String
getSQL
()
{
return
getString
();
return
getString
();
}
}
...
...
h2/src/main/org/h2/value/ValueLong.java
浏览文件 @
e9571b3c
...
@@ -137,6 +137,14 @@ public class ValueLong extends Value {
...
@@ -137,6 +137,14 @@ public class ValueLong extends Value {
return
ValueLong
.
get
(
value
/
other
.
value
);
return
ValueLong
.
get
(
value
/
other
.
value
);
}
}
public
Value
modulus
(
Value
v
)
{
ValueLong
other
=
(
ValueLong
)
v
;
if
(
other
.
value
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
return
ValueLong
.
get
(
this
.
value
%
other
.
value
);
}
public
String
getSQL
()
{
public
String
getSQL
()
{
return
getString
();
return
getString
();
}
}
...
...
h2/src/main/org/h2/value/ValueShort.java
浏览文件 @
e9571b3c
...
@@ -72,6 +72,14 @@ public class ValueShort extends Value {
...
@@ -72,6 +72,14 @@ public class ValueShort extends Value {
return
ValueShort
.
get
((
short
)
(
value
/
other
.
value
));
return
ValueShort
.
get
((
short
)
(
value
/
other
.
value
));
}
}
public
Value
modulus
(
Value
v
)
{
ValueShort
other
=
(
ValueShort
)
v
;
if
(
other
.
value
==
0
)
{
throw
DbException
.
get
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
getSQL
());
}
return
ValueShort
.
get
((
short
)
(
value
%
other
.
value
));
}
public
String
getSQL
()
{
public
String
getSQL
()
{
return
getString
();
return
getString
();
}
}
...
...
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
e9571b3c
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
test
.
unit
;
package
org
.
h2
.
test
.
unit
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.Date
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
...
@@ -14,10 +15,13 @@ import java.sql.Time;
...
@@ -14,10 +15,13 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.UUID
;
import
java.util.UUID
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueDecimal
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueResultSet
;
import
org.h2.value.ValueResultSet
;
...
@@ -43,6 +47,9 @@ public class TestValue extends TestBase {
...
@@ -43,6 +47,9 @@ public class TestValue extends TestBase {
testUUID
();
testUUID
();
testDouble
(
false
);
testDouble
(
false
);
testDouble
(
true
);
testDouble
(
true
);
testModulusDouble
();
testModulusDecimal
();
testModulusOperator
();
}
}
private
void
testValueResultSet
()
throws
SQLException
{
private
void
testValueResultSet
()
throws
SQLException
{
...
@@ -159,4 +166,42 @@ public class TestValue extends TestBase {
...
@@ -159,4 +166,42 @@ public class TestValue extends TestBase {
assertEquals
(
"00000000-0000-4000-8000-000000000000"
,
min
.
getString
());
assertEquals
(
"00000000-0000-4000-8000-000000000000"
,
min
.
getString
());
}
}
private
void
testModulusDouble
()
{
ValueDouble
vd1
=
ValueDouble
.
get
(
12
);
ValueDouble
vd2
=
ValueDouble
.
get
(
10
);
ValueDouble
vd3
=
vd1
.
modulus
(
vd2
);
assertEquals
(
2
,
vd3
.
getDouble
());
try
{
vd1
.
modulus
(
ValueDouble
.
get
(
0
));
fail
();
}
catch
(
DbException
e
)
{
assertEquals
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
e
.
getErrorCode
());
}
}
private
void
testModulusDecimal
()
{
ValueDecimal
vd1
=
ValueDecimal
.
get
(
new
BigDecimal
(
12
));
ValueDecimal
vd2
=
ValueDecimal
.
get
(
new
BigDecimal
(
10
));
ValueDecimal
vd3
=
vd1
.
modulus
(
vd2
);
assertEquals
(
2
,
vd3
.
getDouble
());
try
{
vd1
.
modulus
(
ValueDecimal
.
get
(
new
BigDecimal
(
0
)));
fail
();
}
catch
(
DbException
e
)
{
assertEquals
(
ErrorCode
.
DIVISION_BY_ZERO_1
,
e
.
getErrorCode
());
}
}
private
void
testModulusOperator
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"modulus"
);
try
{
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"CALL 12 % 10"
);
rs
.
next
();
assertEquals
(
2
,
rs
.
getInt
(
1
));
}
finally
{
conn
.
close
();
deleteDb
(
"modulus"
);
}
}
}
}
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
e9571b3c
...
@@ -678,5 +678,5 @@ clip upgrades demonstrate inspectors
...
@@ -678,5 +678,5 @@ clip upgrades demonstrate inspectors
exceed identities differentiate inherited tracks strip suggestions
exceed identities differentiate inherited tracks strip suggestions
registration sanity improperly annotate inheritance composite inspected
registration sanity improperly annotate inheritance composite inspected
hurt imposes marshal policy upgrader configurations dark varray xlint executor
hurt imposes marshal policy upgrader configurations dark varray xlint executor
completion inactivity exports maintains backside schwietzke rene rectangular
completion inactivity exports maintains backside schwietzke rene rectangular
grandin noel
sine cosine tangent cotangent trigonometric
sine cosine tangent cotangent trigonometric
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论