Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
734f8029
Unverified
提交
734f8029
authored
1月 16, 2019
作者:
Evgenij Ryazanov
提交者:
GitHub
1月 16, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1671 from katzyn/misc
Assorted changes
上级
e5893ae6
c183915b
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
216 行增加
和
139 行删除
+216
-139
help.csv
h2/src/docsrc/help/help.csv
+3
-2
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+31
-9
Parser.java
h2/src/main/org/h2/command/Parser.java
+51
-24
Select.java
h2/src/main/org/h2/command/dml/Select.java
+5
-3
SelectUnion.java
h2/src/main/org/h2/command/dml/SelectUnion.java
+3
-1
WindowFunction.java
h2/src/main/org/h2/expression/analysis/WindowFunction.java
+3
-0
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+7
-6
Trace.java
h2/src/main/org/h2/message/Trace.java
+8
-16
LocalResult.java
h2/src/main/org/h2/result/LocalResult.java
+11
-3
LocalResultImpl.java
h2/src/main/org/h2/result/LocalResultImpl.java
+10
-17
ResultTarget.java
h2/src/main/org/h2/result/ResultTarget.java
+3
-3
UpdatableRow.java
h2/src/main/org/h2/result/UpdatableRow.java
+41
-39
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+23
-16
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+7
-0
with.sql
h2/src/test/org/h2/test/scripts/dml/with.sql
+6
-0
ratio_to_report.sql
.../org/h2/test/scripts/functions/window/ratio_to_report.sql
+3
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
734f8029
...
...
@@ -41,7 +41,8 @@ of H2 please use parentheses.
If FOR UPDATE is specified, the tables or rows are locked for writing.
This clause is not allowed in DISTINCT queries and in queries with non-window aggregates, GROUP BY, or HAVING clauses.
When using default MVStore engine only the selected rows are locked as in an UPDATE statement.
When using default MVStore engine only the selected rows are locked as in an UPDATE statement;
locking behavior for rows that were excluded from result using OFFSET / FETCH is undefined.
With PageStore engine the whole tables are locked.
","
SELECT * FROM TEST;
...
...
@@ -5559,7 +5560,7 @@ OVER windowNameOrSpecification
","
Returns the ratio of a value to the sum of all values.
If argument is NULL or sum of all values is 0, then the value of function is NULL.
Window
frame clause is
not allowed for this function.
Window
ordering and window frame clauses are
not allowed for this function.
Window functions are currently experimental in H2 and should be used with caution.
They also may require a lot of memory for large queries.
...
...
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
734f8029
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
command
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.command.dml.Explain
;
import
org.h2.command.dml.Query
;
...
...
@@ -27,6 +28,35 @@ public class CommandContainer extends Command {
private
boolean
readOnlyKnown
;
private
boolean
readOnly
;
/**
* Clears CTE views for a specified statement.
*
* @param session the session
* @param prepared prepared statement
*/
static
void
clearCTE
(
Session
session
,
Prepared
prepared
)
{
List
<
TableView
>
cteCleanups
=
prepared
.
getCteCleanups
();
if
(
cteCleanups
!=
null
)
{
clearCTE
(
session
,
cteCleanups
);
}
}
/**
* Clears CTE views.
*
* @param session the session
* @param views list of view
*/
static
void
clearCTE
(
Session
session
,
List
<
TableView
>
views
)
{
for
(
TableView
view
:
views
)
{
// check if view was previously deleted as their name is set to
// null
if
(
view
.
getName
()
!=
null
)
{
session
.
removeLocalTempTable
(
view
);
}
}
}
CommandContainer
(
Session
session
,
String
sql
,
Prepared
prepared
)
{
super
(
session
,
sql
);
prepared
.
setCommand
(
this
);
...
...
@@ -123,15 +153,7 @@ public class CommandContainer extends Command {
super
.
stop
();
// Clean up after the command was run in the session.
// Must restart query (and dependency construction) to reuse.
if
(
prepared
.
getCteCleanups
()
!=
null
)
{
for
(
TableView
view
:
prepared
.
getCteCleanups
())
{
// check if view was previously deleted as their name is set to
// null
if
(
view
.
getName
()
!=
null
)
{
session
.
removeLocalTempTable
(
view
);
}
}
}
clearCTE
(
session
,
prepared
);
}
@Override
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
734f8029
...
...
@@ -672,7 +672,12 @@ public class Parser {
if
(!
hasMore
&&
currentTokenType
!=
END
)
{
throw
getSyntaxError
();
}
p
.
prepare
();
try
{
p
.
prepare
();
}
catch
(
Throwable
t
)
{
CommandContainer
.
clearCTE
(
session
,
p
);
throw
t
;
}
Command
c
=
new
CommandContainer
(
session
,
sql
,
p
);
if
(
hasMore
)
{
String
remaining
=
originalSQL
.
substring
(
parseIndex
);
...
...
@@ -4533,14 +4538,20 @@ public class Parser {
parseIndex
=
i
;
return
;
case
CHAR_VALUE:
if
(
c
==
'0'
&&
chars
[
i
]
==
'X'
)
{
if
(
c
==
'0'
&&
(
chars
[
i
]
==
'X'
||
chars
[
i
]
==
'x'
)
)
{
// hex number
long
number
=
0
;
start
+=
2
;
i
++;
while
(
true
)
{
c
=
chars
[
i
];
if
((
c
<
'0'
||
c
>
'9'
)
&&
(
c
<
'A'
||
c
>
'F'
))
{
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
number
=
(
number
<<
4
)
+
c
-
'0'
;
}
else
if
(
c
>=
'A'
&&
c
<=
'F'
)
{
number
=
(
number
<<
4
)
+
c
-
(
'A'
-
10
);
}
else
if
(
c
>=
'a'
&&
c
<=
'f'
)
{
number
=
(
number
<<
4
)
+
c
-
(
'a'
-
10
);
}
else
{
checkLiterals
(
false
);
currentValue
=
ValueInt
.
get
((
int
)
number
);
currentTokenType
=
VALUE
;
...
...
@@ -4548,8 +4559,6 @@ public class Parser {
parseIndex
=
i
;
return
;
}
number
=
(
number
<<
4
)
+
c
-
(
c
>=
'A'
?
(
'A'
-
0xa
)
:
(
'0'
));
if
(
number
>
Integer
.
MAX_VALUE
)
{
readHexDecimal
(
start
,
i
);
return
;
...
...
@@ -4558,12 +4567,19 @@ public class Parser {
}
}
long
number
=
c
-
'0'
;
while
(
true
)
{
loop:
while
(
true
)
{
c
=
chars
[
i
];
if
(
c
<
'0'
||
c
>
'9'
)
{
if
(
c
==
'.'
||
c
==
'E'
||
c
==
'L'
)
{
readDecimal
(
start
,
i
);
break
;
switch
(
c
)
{
case
'.'
:
case
'E'
:
case
'e'
:
readDecimal
(
start
,
i
,
false
);
break
loop
;
case
'L'
:
case
'l'
:
readDecimal
(
start
,
i
,
true
);
break
loop
;
}
checkLiterals
(
false
);
currentValue
=
ValueInt
.
get
((
int
)
number
);
...
...
@@ -4574,7 +4590,7 @@ public class Parser {
}
number
=
number
*
10
+
(
c
-
'0'
);
if
(
number
>
Integer
.
MAX_VALUE
)
{
readDecimal
(
start
,
i
);
readDecimal
(
start
,
i
,
true
);
break
;
}
i
++;
...
...
@@ -4587,7 +4603,7 @@ public class Parser {
parseIndex
=
i
;
return
;
}
readDecimal
(
i
-
1
,
i
);
readDecimal
(
i
-
1
,
i
,
false
);
return
;
case
CHAR_STRING:
{
String
result
=
null
;
...
...
@@ -4684,22 +4700,24 @@ public class Parser {
currentTokenType
=
VALUE
;
}
private
void
readDecimal
(
int
start
,
int
i
)
{
private
void
readDecimal
(
int
start
,
int
i
,
boolean
integer
)
{
char
[]
chars
=
sqlCommandChars
;
int
[]
types
=
characterTypes
;
// go until the first non-number
while
(
true
)
{
int
t
=
types
[
i
];
if
(
t
!=
CHAR_DOT
&&
t
!=
CHAR_VALUE
)
{
if
(
t
==
CHAR_DOT
)
{
integer
=
false
;
}
else
if
(
t
!=
CHAR_VALUE
)
{
break
;
}
i
++;
}
boolean
containsE
=
false
;
if
(
c
hars
[
i
]
==
'E'
||
chars
[
i
]
==
'e'
)
{
containsE
=
tru
e
;
i
++
;
if
(
c
hars
[
i
]
==
'+'
||
chars
[
i
]
==
'-'
)
{
char
c
=
chars
[
i
]
;
if
(
c
==
'E'
||
c
==
'e'
)
{
integer
=
fals
e
;
c
=
chars
[++
i
]
;
if
(
c
==
'+'
||
c
==
'-'
)
{
i
++;
}
if
(
types
[
i
]
!=
CHAR_VALUE
)
{
...
...
@@ -4710,14 +4728,14 @@ public class Parser {
}
}
parseIndex
=
i
;
String
sub
=
sqlCommand
.
substring
(
start
,
i
);
checkLiterals
(
false
);
BigDecimal
bd
;
if
(
!
containsE
&&
sub
.
indexOf
(
'.'
)
<
0
)
{
BigInteger
bi
=
new
BigInteger
(
s
ub
);
if
(
integer
&&
i
-
start
<=
19
)
{
BigInteger
bi
=
new
BigInteger
(
s
qlCommand
.
substring
(
start
,
i
)
);
if
(
bi
.
compareTo
(
ValueLong
.
MAX_BI
)
<=
0
)
{
// parse constants like "10000000L"
if
(
chars
[
i
]
==
'L'
)
{
c
=
chars
[
i
];
if
(
c
==
'L'
||
c
==
'l'
)
{
parseIndex
++;
}
currentValue
=
ValueLong
.
get
(
bi
.
longValue
());
...
...
@@ -4727,9 +4745,9 @@ public class Parser {
bd
=
new
BigDecimal
(
bi
);
}
else
{
try
{
bd
=
new
BigDecimal
(
s
ub
);
bd
=
new
BigDecimal
(
s
qlCommandChars
,
start
,
i
-
start
);
}
catch
(
NumberFormatException
e
)
{
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
,
s
ub
);
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
,
s
qlCommand
.
substring
(
start
,
i
)
);
}
}
currentValue
=
ValueDecimal
.
get
(
bd
);
...
...
@@ -6127,6 +6145,15 @@ public class Parser {
private
Prepared
parseWith
()
{
List
<
TableView
>
viewsCreated
=
new
ArrayList
<>();
try
{
return
parseWith1
(
viewsCreated
);
}
catch
(
Throwable
t
)
{
CommandContainer
.
clearCTE
(
session
,
viewsCreated
);
throw
t
;
}
}
private
Prepared
parseWith1
(
List
<
TableView
>
viewsCreated
)
{
readIf
(
"RECURSIVE"
);
// This WITH statement is not a temporary view - it is part of a persistent view
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
734f8029
...
...
@@ -774,7 +774,7 @@ public class Select extends Query {
}
boolean
fetchPercent
=
this
.
fetchPercent
;
if
(
fetchPercent
)
{
// Need to check it
r
ow, because negative limit has special treatment later
// Need to check it
n
ow, because negative limit has special treatment later
if
(
limitRows
<
0
||
limitRows
>
100
)
{
throw
DbException
.
getInvalidValueException
(
"FETCH PERCENT"
,
limitRows
);
}
...
...
@@ -803,7 +803,7 @@ public class Select extends Query {
}
// Do not add rows before OFFSET to result if possible
boolean
quickOffset
=
!
fetchPercent
;
if
(
sort
!=
null
&&
(!
sortUsingIndex
||
isAnyDistinct
()
||
withTies
))
{
if
(
sort
!=
null
&&
(!
sortUsingIndex
||
isAnyDistinct
()))
{
result
=
createLocalResult
(
result
);
result
.
setSortOrder
(
sort
);
if
(!
sortUsingIndex
)
{
...
...
@@ -886,7 +886,9 @@ public class Select extends Query {
if
(
limitRows
>=
0
)
{
result
.
setLimit
(
limitRows
);
result
.
setFetchPercent
(
fetchPercent
);
result
.
setWithTies
(
withTies
);
if
(
withTies
)
{
result
.
setWithTies
(
sort
);
}
}
if
(
result
!=
null
)
{
result
.
done
();
...
...
h2/src/main/org/h2/command/dml/SelectUnion.java
浏览文件 @
734f8029
...
...
@@ -264,7 +264,9 @@ public class SelectUnion extends Query {
if
(
v
!=
ValueNull
.
INSTANCE
)
{
result
.
setLimit
(
v
.
getInt
());
result
.
setFetchPercent
(
fetchPercent
);
result
.
setWithTies
(
withTies
);
if
(
withTies
)
{
result
.
setWithTies
(
sort
);
}
}
}
l
.
close
();
...
...
h2/src/main/org/h2/expression/analysis/WindowFunction.java
浏览文件 @
734f8029
...
...
@@ -451,6 +451,9 @@ public class WindowFunction extends DataAnalysisOperation {
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
,
"ORDER BY"
);
default
:
}
}
else
if
(
type
==
WindowFunctionType
.
RATIO_TO_REPORT
)
{
String
sql
=
getSQL
();
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
);
}
super
.
optimize
(
session
);
if
(
args
!=
null
)
{
...
...
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
734f8029
...
...
@@ -25,7 +25,6 @@ import org.h2.message.DbException;
import
org.h2.message.Trace
;
import
org.h2.message.TraceObject
;
import
org.h2.result.SimpleResult
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueString
;
...
...
@@ -1616,25 +1615,27 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+
"FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?"
);
prep
.
setString
(
1
,
section
);
ResultSet
rs
=
prep
.
executeQuery
();
St
atementBuilder
buff
=
new
Statement
Builder
();
St
ringBuilder
builder
=
new
String
Builder
();
while
(
rs
.
next
())
{
String
s
=
rs
.
getString
(
1
).
trim
();
String
[]
array
=
StringUtils
.
arraySplit
(
s
,
','
,
true
);
for
(
String
a
:
array
)
{
buff
.
appendExceptFirst
(
","
);
if
(
builder
.
length
()
!=
0
)
{
builder
.
append
(
','
);
}
String
f
=
a
.
trim
();
int
spaceIndex
=
f
.
indexOf
(
' '
);
if
(
spaceIndex
>=
0
)
{
// remove 'Function' from 'INSERT Function'
StringUtils
.
trimSubstring
(
bu
ff
.
builder
()
,
f
,
0
,
spaceIndex
);
StringUtils
.
trimSubstring
(
bu
ilder
,
f
,
0
,
spaceIndex
);
}
else
{
bu
ff
.
append
(
f
);
bu
ilder
.
append
(
f
);
}
}
}
rs
.
close
();
prep
.
close
();
return
bu
ff
.
toString
();
return
bu
ilder
.
toString
();
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
h2/src/main/org/h2/message/Trace.java
浏览文件 @
734f8029
...
...
@@ -10,9 +10,7 @@ import java.util.ArrayList;
import
org.h2.engine.SysProperties
;
import
org.h2.expression.ParameterInterface
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
/**
* This class represents a trace module.
...
...
@@ -239,29 +237,23 @@ public class Trace {
* @param parameters the parameter list
* @return the formatted text
*/
public
static
String
formatParams
(
ArrayList
<?
extends
ParameterInterface
>
parameters
)
{
public
static
String
formatParams
(
ArrayList
<?
extends
ParameterInterface
>
parameters
)
{
if
(
parameters
.
isEmpty
())
{
return
""
;
}
St
atementBuilder
buff
=
new
Statement
Builder
();
St
ringBuilder
builder
=
new
String
Builder
();
int
i
=
0
;
boolean
params
=
false
;
for
(
ParameterInterface
p
:
parameters
)
{
if
(
p
.
isValueSet
())
{
if
(!
params
)
{
buff
.
append
(
" {"
);
params
=
true
;
}
buff
.
appendExceptFirst
(
", "
);
Value
v
=
p
.
getParamValue
();
buff
.
append
(++
i
).
append
(
": "
).
append
(
v
.
getTraceSQL
());
builder
.
append
(
i
==
0
?
" {"
:
", "
)
//
.
append
(++
i
).
append
(
": "
)
//
.
append
(
p
.
getParamValue
().
getTraceSQL
());
}
}
if
(
params
)
{
bu
ff
.
append
(
'}'
);
if
(
i
!=
0
)
{
bu
ilder
.
append
(
'}'
);
}
return
bu
ff
.
toString
();
return
bu
ilder
.
toString
();
}
/**
...
...
h2/src/main/org/h2/result/LocalResult.java
浏览文件 @
734f8029
...
...
@@ -25,7 +25,10 @@ public interface LocalResult extends ResultInterface, ResultTarget {
public
void
setMaxMemoryRows
(
int
maxValue
);
/**
* @param sort Sort order.
* Sets sort order to be used by this result. When rows are presorted by the
* query this method should not be used.
*
* @param sort the sort order
*/
public
void
setSortOrder
(
SortOrder
sort
);
...
...
@@ -82,9 +85,14 @@ public interface LocalResult extends ResultInterface, ResultTarget {
public
void
setFetchPercent
(
boolean
fetchPercent
);
/**
* @param withTies whether tied rows should be included in result too
* Enables inclusion of tied rows to result and sets the sort order for tied
* rows. The specified sort order must be the same as sort order if sort
* order was set. Passed value will be used if sort order was not set that
* is possible when rows are presorted.
*
* @param withTiesSortOrder the sort order for tied rows
*/
public
void
setWithTies
(
boolean
withTies
);
public
void
setWithTies
(
SortOrder
withTiesSortOrder
);
/**
* Set the offset of the first row to return.
...
...
h2/src/main/org/h2/result/LocalResultImpl.java
浏览文件 @
734f8029
...
...
@@ -38,7 +38,7 @@ public class LocalResultImpl implements LocalResult {
private
int
offset
;
private
int
limit
=
-
1
;
private
boolean
fetchPercent
;
private
boolean
withTies
;
private
SortOrder
withTiesSortOrder
;
private
boolean
limitsWereApplied
;
private
ResultExternal
external
;
private
boolean
distinct
;
...
...
@@ -132,11 +132,6 @@ public class LocalResultImpl implements LocalResult {
return
copy
;
}
/**
* Set the sort order.
*
* @param sort the sort order
*/
@Override
public
void
setSortOrder
(
SortOrder
sort
)
{
this
.
sort
=
sort
;
...
...
@@ -365,8 +360,8 @@ public class LocalResultImpl implements LocalResult {
if
(
isAnyDistinct
())
{
rows
=
distinctRows
.
values
();
}
if
(
sort
!=
null
&&
limit
!=
0
)
{
boolean
withLimit
=
limit
>
0
&&
!
withTies
;
if
(
sort
!=
null
&&
limit
!=
0
&&
!
limitsWereApplied
)
{
boolean
withLimit
=
limit
>
0
&&
withTiesSortOrder
==
null
;
if
(
offset
>
0
||
withLimit
)
{
sort
.
sort
(
rows
,
offset
,
withLimit
?
limit
:
rows
.
size
());
}
else
{
...
...
@@ -412,9 +407,9 @@ public class LocalResultImpl implements LocalResult {
return
;
}
int
to
=
offset
+
limit
;
if
(
withTies
&&
sort
!=
null
)
{
if
(
withTies
SortOrder
!=
null
)
{
Value
[]
expected
=
rows
.
get
(
to
-
1
);
while
(
to
<
rows
.
size
()
&&
sort
.
compare
(
expected
,
rows
.
get
(
to
))
==
0
)
{
while
(
to
<
rows
.
size
()
&&
withTiesSortOrder
.
compare
(
expected
,
rows
.
get
(
to
))
==
0
)
{
to
++;
rowCount
++;
}
...
...
@@ -448,9 +443,9 @@ public class LocalResultImpl implements LocalResult {
addRowsToDisk
();
}
}
if
(
withTies
&&
sort
!=
null
&&
row
!=
null
)
{
if
(
withTies
SortOrder
!=
null
&&
row
!=
null
)
{
Value
[]
expected
=
row
;
while
((
row
=
temp
.
next
())
!=
null
&&
sort
.
compare
(
expected
,
row
)
==
0
)
{
while
((
row
=
temp
.
next
())
!=
null
&&
withTiesSortOrder
.
compare
(
expected
,
row
)
==
0
)
{
rows
.
add
(
row
);
rowCount
++;
if
(
rows
.
size
()
>
maxMemoryRows
)
{
...
...
@@ -497,12 +492,10 @@ public class LocalResultImpl implements LocalResult {
this
.
fetchPercent
=
fetchPercent
;
}
/**
* @param withTies whether tied rows should be included in result too
*/
@Override
public
void
setWithTies
(
boolean
withTies
)
{
this
.
withTies
=
withTies
;
public
void
setWithTies
(
SortOrder
withTiesSortOrder
)
{
assert
sort
==
null
||
sort
==
withTiesSortOrder
;
this
.
withTiesSortOrder
=
withTiesSortOrder
;
}
@Override
...
...
h2/src/main/org/h2/result/ResultTarget.java
浏览文件 @
734f8029
...
...
@@ -27,9 +27,9 @@ public interface ResultTarget {
int
getRowCount
();
/**
* A hint that
offset and limit may be ignored by this result because they
*
were applied during the query. This is useful for WITH TIES clause
* because result may contain tied rows above limit.
* A hint that
sorting, offset and limit may be ignored by this result
*
because they were applied during the query. This is useful for WITH TIES
*
clause
because result may contain tied rows above limit.
*/
void
limitsWereApplied
();
...
...
h2/src/main/org/h2/result/UpdatableRow.java
浏览文件 @
734f8029
...
...
@@ -14,7 +14,6 @@ import java.util.ArrayList;
import
org.h2.api.ErrorCode
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.DbException
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
import
org.h2.value.DataType
;
...
...
@@ -156,24 +155,26 @@ public class UpdatableRow {
return
index
;
}
private
void
appendColumnList
(
StatementBuilder
buff
,
boolean
set
)
{
buff
.
resetCount
();
private
void
appendColumnList
(
StringBuilder
builder
,
boolean
set
)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
buff
.
appendExceptFirst
(
","
);
if
(
i
>
0
)
{
builder
.
append
(
','
);
}
String
col
=
result
.
getColumnName
(
i
);
StringUtils
.
quoteIdentifier
(
bu
ff
.
builder
()
,
col
);
StringUtils
.
quoteIdentifier
(
bu
ilder
,
col
);
if
(
set
)
{
bu
ff
.
append
(
"=? "
);
bu
ilder
.
append
(
"=? "
);
}
}
}
private
void
appendKeyCondition
(
StatementBuilder
buff
)
{
buff
.
append
(
" WHERE "
);
buff
.
resetCount
();
for
(
String
k
:
key
)
{
buff
.
appendExceptFirst
(
" AND "
);
StringUtils
.
quoteIdentifier
(
buff
.
builder
(),
k
).
append
(
"=?"
);
private
void
appendKeyCondition
(
StringBuilder
builder
)
{
builder
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
key
.
size
();
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
" AND "
);
}
StringUtils
.
quoteIdentifier
(
builder
,
key
.
get
(
i
)).
append
(
"=?"
);
}
}
...
...
@@ -218,12 +219,12 @@ public class UpdatableRow {
* @return the row
*/
public
Value
[]
readRow
(
Value
[]
row
)
throws
SQLException
{
St
atementBuilder
buff
=
new
Statement
Builder
(
"SELECT "
);
appendColumnList
(
bu
ff
,
false
);
bu
ff
.
append
(
" FROM "
);
appendTableName
(
bu
ff
.
builder
()
);
appendKeyCondition
(
bu
ff
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ff
.
toString
());
St
ringBuilder
builder
=
new
String
Builder
(
"SELECT "
);
appendColumnList
(
bu
ilder
,
false
);
bu
ilder
.
append
(
" FROM "
);
appendTableName
(
bu
ilder
);
appendKeyCondition
(
bu
ilder
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ilder
.
toString
());
setKey
(
prep
,
1
,
row
);
ResultSet
rs
=
prep
.
executeQuery
();
if
(!
rs
.
next
())
{
...
...
@@ -244,10 +245,10 @@ public class UpdatableRow {
* @throws SQLException if this row has already been deleted
*/
public
void
deleteRow
(
Value
[]
current
)
throws
SQLException
{
St
atementBuilder
buff
=
new
Statement
Builder
(
"DELETE FROM "
);
appendTableName
(
bu
ff
.
builder
()
);
appendKeyCondition
(
bu
ff
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ff
.
toString
());
St
ringBuilder
builder
=
new
String
Builder
(
"DELETE FROM "
);
appendTableName
(
bu
ilder
);
appendKeyCondition
(
bu
ilder
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ilder
.
toString
());
setKey
(
prep
,
1
,
current
);
int
count
=
prep
.
executeUpdate
();
if
(
count
!=
1
)
{
...
...
@@ -264,15 +265,15 @@ public class UpdatableRow {
* @throws SQLException if the row has been deleted
*/
public
void
updateRow
(
Value
[]
current
,
Value
[]
updateRow
)
throws
SQLException
{
St
atementBuilder
buff
=
new
Statement
Builder
(
"UPDATE "
);
appendTableName
(
bu
ff
.
builder
()
);
bu
ff
.
append
(
" SET "
);
appendColumnList
(
bu
ff
,
true
);
St
ringBuilder
builder
=
new
String
Builder
(
"UPDATE "
);
appendTableName
(
bu
ilder
);
bu
ilder
.
append
(
" SET "
);
appendColumnList
(
bu
ilder
,
true
);
// TODO updatable result set: we could add all current values to the
// where clause
// - like this optimistic ('no') locking is possible
appendKeyCondition
(
bu
ff
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ff
.
toString
());
appendKeyCondition
(
bu
ilder
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ilder
.
toString
());
int
j
=
1
;
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
Value
v
=
updateRow
[
i
];
...
...
@@ -296,23 +297,24 @@ public class UpdatableRow {
* @throws SQLException if the row could not be inserted
*/
public
void
insertRow
(
Value
[]
row
)
throws
SQLException
{
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
appendTableName
(
buff
.
builder
());
buff
.
append
(
'('
);
appendColumnList
(
buff
,
false
);
buff
.
append
(
")VALUES("
);
buff
.
resetCount
();
StringBuilder
builder
=
new
StringBuilder
(
"INSERT INTO "
);
appendTableName
(
builder
);
builder
.
append
(
'('
);
appendColumnList
(
builder
,
false
);
builder
.
append
(
")VALUES("
);
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
buff
.
appendExceptFirst
(
","
);
if
(
i
>
0
)
{
builder
.
append
(
','
);
}
Value
v
=
row
[
i
];
if
(
v
==
null
)
{
bu
ff
.
append
(
"DEFAULT"
);
bu
ilder
.
append
(
"DEFAULT"
);
}
else
{
bu
ff
.
append
(
'?'
);
bu
ilder
.
append
(
'?'
);
}
}
bu
ff
.
append
(
')'
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ff
.
toString
());
bu
ilder
.
append
(
')'
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
bu
ilder
.
toString
());
for
(
int
i
=
0
,
j
=
0
;
i
<
columnCount
;
i
++)
{
Value
v
=
row
[
i
];
if
(
v
!=
null
)
{
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
734f8029
...
...
@@ -370,10 +370,12 @@ public class StringUtils {
if
(
array
==
null
)
{
return
"null"
;
}
StatementBuilder
buff
=
new
StatementBuilder
(
"new String[]{"
);
for
(
String
a
:
array
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
quoteJavaString
(
a
));
StringBuilder
buff
=
new
StringBuilder
(
"new String[]{"
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
quoteJavaString
(
array
[
i
]));
}
return
buff
.
append
(
'}'
).
toString
();
}
...
...
@@ -389,12 +391,14 @@ public class StringUtils {
if
(
array
==
null
)
{
return
"null"
;
}
StatementBuilder
buff
=
new
StatementBuilder
(
"new int[]{"
);
for
(
int
a
:
array
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
a
);
StringBuilder
builder
=
new
StringBuilder
(
"new int[]{"
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
builder
.
append
(
array
[
i
]);
}
return
bu
ff
.
append
(
'}'
).
toString
();
return
bu
ilder
.
append
(
'}'
).
toString
();
}
/**
...
...
@@ -498,21 +502,24 @@ public class StringUtils {
* @return the combined string
*/
public
static
String
arrayCombine
(
String
[]
list
,
char
separatorChar
)
{
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
String
s
:
list
)
{
buff
.
appendExceptFirst
(
String
.
valueOf
(
separatorChar
));
StringBuilder
builder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
separatorChar
);
}
String
s
=
list
[
i
];
if
(
s
==
null
)
{
s
=
""
;
continue
;
}
for
(
int
j
=
0
,
length
=
s
.
length
();
j
<
length
;
j
++)
{
char
c
=
s
.
charAt
(
j
);
if
(
c
==
'\\'
||
c
==
separatorChar
)
{
bu
ff
.
append
(
'\\'
);
bu
ilder
.
append
(
'\\'
);
}
bu
ff
.
append
(
c
);
bu
ilder
.
append
(
c
);
}
}
return
bu
ff
.
toString
();
return
bu
ilder
.
toString
();
}
/**
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
734f8029
...
...
@@ -110,6 +110,13 @@ public class TestCompatibility extends TestDb {
stat
.
execute
(
"select id from test t group by T.ID"
);
stat
.
execute
(
"drop table test"
);
rs
=
stat
.
executeQuery
(
"select 1e10, 1000000000000000000000e10, 0xfAfBl"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
e10
,
rs
.
getDouble
(
1
));
assertEquals
(
1000000000000000000000
e10
,
rs
.
getDouble
(
2
));
assertEquals
(
0xfafb
L
,
rs
.
getLong
(
3
));
assertFalse
(
rs
.
next
());
c
.
close
();
}
...
...
h2/src/test/org/h2/test/scripts/dml/with.sql
浏览文件 @
734f8029
...
...
@@ -146,5 +146,11 @@ WITH CTE_TEST AS (TABLE TEST) ((TABLE CTE_TEST));
>
1
2
>
rows
:
1
WITH
CTE_TEST
AS
(
TABLE
TEST
)
((
SELECT
A
,
B
FROM
CTE_TEST2
));
>
exception
TABLE_OR_VIEW_NOT_FOUND_1
WITH
CTE_TEST
AS
(
TABLE
TEST
)
((
SELECT
A
,
B
,
C
FROM
CTE_TEST
));
>
exception
COLUMN_NOT_FOUND_1
DROP
TABLE
TEST
;
>
ok
h2/src/test/org/h2/test/scripts/functions/window/ratio_to_report.sql
浏览文件 @
734f8029
...
...
@@ -31,5 +31,8 @@ SELECT ID, N, RATIO_TO_REPORT(N) OVER() R2R FROM TEST;
>
5
-
8
null
>
rows
:
5
SELECT
RATIO_TO_REPORT
(
N
)
OVER
(
ORDER
BY
N
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
DROP
TABLE
TEST
;
>
ok
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
734f8029
...
...
@@ -806,3 +806,4 @@ econd irst bcef ordinality nord unnest
analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan
corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes
preserves masking holder unboxing avert iae transformed subtle reevaluate exclusions subclause ftbl rgr
presorted inclusion
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论