Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5288eafc
提交
5288eafc
authored
1月 16, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not use StatementBuilder in JDBC Client classes
上级
4ef44393
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
79 行增加
和
77 行删除
+79
-77
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+7
-6
Trace.java
h2/src/main/org/h2/message/Trace.java
+8
-16
UpdatableRow.java
h2/src/main/org/h2/result/UpdatableRow.java
+41
-39
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+23
-16
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
5288eafc
...
...
@@ -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
浏览文件 @
5288eafc
...
...
@@ -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
;
builder
.
append
(
i
==
0
?
" {"
:
", "
)
//
.
append
(++
i
).
append
(
": "
)
//
.
append
(
p
.
getParamValue
().
getTraceSQL
())
;
}
buff
.
appendExceptFirst
(
", "
);
Value
v
=
p
.
getParamValue
();
buff
.
append
(++
i
).
append
(
": "
).
append
(
v
.
getTraceSQL
());
}
if
(
i
!=
0
)
{
builder
.
append
(
'}'
);
}
if
(
params
)
{
buff
.
append
(
'}'
);
}
return
buff
.
toString
();
return
builder
.
toString
();
}
/**
...
...
h2/src/main/org/h2/result/UpdatableRow.java
浏览文件 @
5288eafc
...
...
@@ -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
浏览文件 @
5288eafc
...
...
@@ -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"
;
}
St
atementBuilder
buff
=
new
Statement
Builder
(
"new int[]{"
);
for
(
int
a
:
array
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
a
);
St
ringBuilder
builder
=
new
String
Builder
(
"new int[]{"
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++
)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
return
buff
.
append
(
'}'
).
toString
();
builder
.
append
(
array
[
i
]);
}
return
builder
.
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
();
}
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论