Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a36a6634
提交
a36a6634
authored
2月 12, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use DbObject.getSQL(StringBuilder) where possible
上级
4f34f37d
显示空白字符变更
内嵌
并排
正在显示
39 个修改的文件
包含
166 行增加
和
107 行删除
+166
-107
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+3
-2
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+17
-8
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+2
-1
CreateDomain.java
h2/src/main/org/h2/command/ddl/CreateDomain.java
+3
-3
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+2
-2
Merge.java
h2/src/main/org/h2/command/dml/Merge.java
+2
-2
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+1
-1
Replace.java
h2/src/main/org/h2/command/dml/Replace.java
+2
-2
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+5
-5
Select.java
h2/src/main/org/h2/command/dml/Select.java
+4
-3
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+3
-4
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+20
-15
ConstraintUnique.java
h2/src/main/org/h2/constraint/ConstraintUnique.java
+3
-2
Comment.java
h2/src/main/org/h2/engine/Comment.java
+3
-1
Domain.java
h2/src/main/org/h2/engine/Domain.java
+6
-2
Right.java
h2/src/main/org/h2/engine/Right.java
+7
-4
Role.java
h2/src/main/org/h2/engine/Role.java
+1
-1
Session.java
h2/src/main/org/h2/engine/Session.java
+4
-2
Setting.java
h2/src/main/org/h2/engine/Setting.java
+1
-1
User.java
h2/src/main/org/h2/engine/User.java
+1
-1
UserAggregate.java
h2/src/main/org/h2/engine/UserAggregate.java
+6
-3
SequenceValue.java
h2/src/main/org/h2/expression/SequenceValue.java
+1
-1
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+9
-5
PageBtreeLeaf.java
h2/src/main/org/h2/index/PageBtreeLeaf.java
+1
-1
PageDataIndex.java
h2/src/main/org/h2/index/PageDataIndex.java
+5
-4
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+2
-1
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+1
-1
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+13
-9
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+3
-2
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+3
-3
Constant.java
h2/src/main/org/h2/schema/Constant.java
+2
-1
Schema.java
h2/src/main/org/h2/schema/Schema.java
+4
-2
Sequence.java
h2/src/main/org/h2/schema/Sequence.java
+3
-2
TriggerObject.java
h2/src/main/org/h2/schema/TriggerObject.java
+2
-1
Column.java
h2/src/main/org/h2/table/Column.java
+2
-1
TableBase.java
h2/src/main/org/h2/table/TableBase.java
+4
-2
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+2
-2
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+4
-2
TableSynonym.java
h2/src/main/org/h2/table/TableSynonym.java
+9
-2
没有找到文件。
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
a36a6634
...
@@ -208,8 +208,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
...
@@ -208,8 +208,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
}
}
session
.
getUser
().
checkRight
(
refTable
,
Right
.
ALL
);
session
.
getUser
().
checkRight
(
refTable
,
Right
.
ALL
);
if
(!
refTable
.
canReference
())
{
if
(!
refTable
.
canReference
())
{
throw
DbException
.
getUnsupportedException
(
"Reference "
+
StringBuilder
builder
=
new
StringBuilder
(
"Reference "
);
refTable
.
getSQL
());
refTable
.
getSQL
(
builder
);
throw
DbException
.
getUnsupportedException
(
builder
.
toString
());
}
}
boolean
isOwner
=
false
;
boolean
isOwner
=
false
;
IndexColumn
.
mapColumns
(
indexColumns
,
table
);
IndexColumn
.
mapColumns
(
indexColumns
,
table
);
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
a36a6634
...
@@ -296,7 +296,9 @@ public class AlterTableAlterColumn extends CommandWithColumns {
...
@@ -296,7 +296,9 @@ public class AlterTableAlterColumn extends CommandWithColumns {
// (because the column to drop is referenced or so)
// (because the column to drop is referenced or so)
checkViews
(
table
,
newTable
);
checkViews
(
table
,
newTable
);
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
execute
(
"DROP TABLE "
+
newTable
.
getSQL
(),
true
);
StringBuilder
builder
=
new
StringBuilder
(
"DROP TABLE "
);
newTable
.
getSQL
(
builder
);
execute
(
builder
.
toString
(),
true
);
throw
e
;
throw
e
;
}
}
String
tableName
=
table
.
getName
();
String
tableName
=
table
.
getName
();
...
@@ -304,7 +306,9 @@ public class AlterTableAlterColumn extends CommandWithColumns {
...
@@ -304,7 +306,9 @@ public class AlterTableAlterColumn extends CommandWithColumns {
for
(
TableView
view
:
dependentViews
)
{
for
(
TableView
view
:
dependentViews
)
{
table
.
removeDependentView
(
view
);
table
.
removeDependentView
(
view
);
}
}
execute
(
"DROP TABLE "
+
table
.
getSQL
()
+
" IGNORE"
,
true
);
StringBuilder
builder
=
new
StringBuilder
(
"DROP TABLE "
);
table
.
getSQL
(
builder
).
append
(
" IGNORE"
);
execute
(
builder
.
toString
(),
true
);
db
.
renameSchemaObject
(
session
,
newTable
,
tableName
);
db
.
renameSchemaObject
(
session
,
newTable
,
tableName
);
for
(
DbObject
child
:
newTable
.
getChildren
())
{
for
(
DbObject
child
:
newTable
.
getChildren
())
{
if
(
child
instanceof
Sequence
)
{
if
(
child
instanceof
Sequence
)
{
...
@@ -475,7 +479,8 @@ public class AlterTableAlterColumn extends CommandWithColumns {
...
@@ -475,7 +479,8 @@ public class AlterTableAlterColumn extends CommandWithColumns {
}
}
}
}
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"INSERT INTO "
).
append
(
newTable
.
getSQL
());
buff
.
append
(
"INSERT INTO "
);
newTable
.
getSQL
(
buff
);
buff
.
append
(
" SELECT "
);
buff
.
append
(
" SELECT "
);
if
(
columnList
.
length
()
==
0
)
{
if
(
columnList
.
length
()
==
0
)
{
// special case: insert into test select * from
// special case: insert into test select * from
...
@@ -483,13 +488,16 @@ public class AlterTableAlterColumn extends CommandWithColumns {
...
@@ -483,13 +488,16 @@ public class AlterTableAlterColumn extends CommandWithColumns {
}
else
{
}
else
{
buff
.
append
(
columnList
);
buff
.
append
(
columnList
);
}
}
buff
.
append
(
" FROM "
).
append
(
table
.
getSQL
());
buff
.
append
(
" FROM "
);
table
.
getSQL
(
buff
);
try
{
try
{
execute
(
buff
.
toString
(),
true
);
execute
(
buff
.
toString
(),
true
);
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
// data was not inserted due to data conversion error or some
// data was not inserted due to data conversion error or some
// unexpected reason
// unexpected reason
execute
(
"DROP TABLE "
+
newTable
.
getSQL
(),
true
);
StringBuilder
builder
=
new
StringBuilder
(
"DROP TABLE "
);
newTable
.
getSQL
(
builder
);
execute
(
builder
.
toString
(),
true
);
throw
t
;
throw
t
;
}
}
for
(
String
sql
:
children
)
{
for
(
String
sql
:
children
)
{
...
@@ -579,9 +587,10 @@ public class AlterTableAlterColumn extends CommandWithColumns {
...
@@ -579,9 +587,10 @@ public class AlterTableAlterColumn extends CommandWithColumns {
}
}
private
void
checkNoNullValues
(
Table
table
)
{
private
void
checkNoNullValues
(
Table
table
)
{
String
sql
=
"SELECT COUNT(*) FROM "
+
StringBuilder
builder
=
new
StringBuilder
(
"SELECT COUNT(*) FROM "
);
table
.
getSQL
()
+
" WHERE "
+
table
.
getSQL
(
builder
).
append
(
" WHERE "
);
oldColumn
.
getSQL
()
+
" IS NULL"
;
builder
.
append
(
oldColumn
.
getSQL
()).
append
(
" IS NULL"
);
String
sql
=
builder
.
toString
();
Prepared
command
=
session
.
prepare
(
sql
);
Prepared
command
=
session
.
prepare
(
sql
);
ResultInterface
result
=
command
.
query
(
0
);
ResultInterface
result
=
command
.
query
(
0
);
result
.
next
();
result
.
next
();
...
...
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
a36a6634
...
@@ -113,7 +113,8 @@ public class Analyze extends DefineCommand {
...
@@ -113,7 +113,8 @@ public class Analyze extends DefineCommand {
buff
.
append
(
"SELECTIVITY("
).
append
(
col
.
getSQL
()).
append
(
')'
);
buff
.
append
(
"SELECTIVITY("
).
append
(
col
.
getSQL
()).
append
(
')'
);
}
}
}
}
buff
.
append
(
" FROM "
).
append
(
table
.
getSQL
());
buff
.
append
(
" FROM "
);
table
.
getSQL
(
buff
.
builder
());
if
(
sample
>
0
)
{
if
(
sample
>
0
)
{
buff
.
append
(
" FETCH FIRST ROW ONLY SAMPLE_SIZE ? "
);
buff
.
append
(
" FETCH FIRST ROW ONLY SAMPLE_SIZE ? "
);
}
}
...
...
h2/src/main/org/h2/command/ddl/CreateDomain.java
浏览文件 @
a36a6634
...
@@ -64,9 +64,9 @@ public class CreateDomain extends DefineCommand {
...
@@ -64,9 +64,9 @@ public class CreateDomain extends DefineCommand {
}
}
Table
table
=
session
.
getDatabase
().
getFirstUserTable
();
Table
table
=
session
.
getDatabase
().
getFirstUserTable
();
if
(
table
!=
null
)
{
if
(
table
!=
null
)
{
throw
DbException
.
get
(
StringBuilder
builder
=
new
StringBuilder
(
typeName
).
append
(
" ("
);
ErrorCode
.
DOMAIN_ALREADY_EXISTS_1
,
table
.
getSQL
(
builder
).
append
(
')'
);
typeName
+
" ("
+
table
.
getSQL
()
+
")"
);
throw
DbException
.
get
(
ErrorCode
.
DOMAIN_ALREADY_EXISTS_1
,
builder
.
toString
()
);
}
}
}
}
int
id
=
getObjectId
();
int
id
=
getObjectId
();
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
a36a6634
...
@@ -270,7 +270,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
...
@@ -270,7 +270,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
buff
.
append
(
table
.
getSQL
()).
append
(
'('
);
table
.
getSQL
(
buff
.
builder
()).
append
(
'('
);
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
...
@@ -405,7 +405,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
...
@@ -405,7 +405,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
}
}
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
buff
.
append
(
table
.
getSQL
()).
append
(
" SET "
);
table
.
getSQL
(
buff
.
builder
()).
append
(
" SET "
);
for
(
Column
column
:
duplicateKeyAssignmentMap
.
keySet
())
{
for
(
Column
column
:
duplicateKeyAssignmentMap
.
keySet
())
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
Expression
ex
=
duplicateKeyAssignmentMap
.
get
(
column
);
Expression
ex
=
duplicateKeyAssignmentMap
.
get
(
column
);
...
...
h2/src/main/org/h2/command/dml/Merge.java
浏览文件 @
a36a6634
...
@@ -207,7 +207,7 @@ public class Merge extends CommandWithValues {
...
@@ -207,7 +207,7 @@ public class Merge extends CommandWithValues {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
buff
.
append
(
targetTable
.
getSQL
()).
append
(
'('
);
targetTable
.
getSQL
(
buff
.
builder
()).
append
(
'('
);
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
...
@@ -276,7 +276,7 @@ public class Merge extends CommandWithValues {
...
@@ -276,7 +276,7 @@ public class Merge extends CommandWithValues {
keys
=
idx
.
getColumns
();
keys
=
idx
.
getColumns
();
}
}
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
buff
.
append
(
targetTable
.
getSQL
()).
append
(
" SET "
);
targetTable
.
getSQL
(
buff
.
builder
()).
append
(
" SET "
);
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
...
...
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
a36a6634
...
@@ -390,7 +390,7 @@ public class MergeUsing extends Prepared {
...
@@ -390,7 +390,7 @@ public class MergeUsing extends Prepared {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StringBuilder
builder
=
new
StringBuilder
(
"MERGE INTO "
);
StringBuilder
builder
=
new
StringBuilder
(
"MERGE INTO "
);
builder
.
append
(
targetTable
.
getSQL
()
).
append
(
'\n'
).
append
(
"USING "
).
append
(
query
.
getPlanSQL
());
targetTable
.
getSQL
(
builder
).
append
(
'\n'
).
append
(
"USING "
).
append
(
query
.
getPlanSQL
());
// TODO add aliases and WHEN clauses to make plan SQL more like original SQL
// TODO add aliases and WHEN clauses to make plan SQL more like original SQL
return
builder
.
toString
();
return
builder
.
toString
();
}
}
...
...
h2/src/main/org/h2/command/dml/Replace.java
浏览文件 @
a36a6634
...
@@ -196,7 +196,7 @@ public class Replace extends CommandWithValues {
...
@@ -196,7 +196,7 @@ public class Replace extends CommandWithValues {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"REPLACE INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"REPLACE INTO "
);
buff
.
append
(
table
.
getSQL
()).
append
(
'('
);
table
.
getSQL
(
buff
.
builder
()).
append
(
'('
);
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
...
@@ -270,7 +270,7 @@ public class Replace extends CommandWithValues {
...
@@ -270,7 +270,7 @@ public class Replace extends CommandWithValues {
}
}
}
}
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
buff
.
append
(
table
.
getSQL
()).
append
(
" SET "
);
table
.
getSQL
(
buff
.
builder
()).
append
(
" SET "
);
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
a36a6634
...
@@ -291,10 +291,10 @@ public class ScriptCommand extends ScriptBase {
...
@@ -291,10 +291,10 @@ public class ScriptCommand extends ScriptBase {
}
}
if
(
TableType
.
TABLE
==
tableType
)
{
if
(
TableType
.
TABLE
==
tableType
)
{
if
(
table
.
canGetRowCount
())
{
if
(
table
.
canGetRowCount
())
{
String
rowcount
=
"-- "
+
String
Builder
builder
=
new
StringBuilder
(
"-- "
).
append
(
table
.
getRowCountApproximation
())
table
.
getRowCountApproximation
()
+
.
append
(
" +/- SELECT COUNT(*) FROM "
);
" +/- SELECT COUNT(*) FROM "
+
table
.
getSQL
(
);
table
.
getSQL
(
builder
);
add
(
rowcount
,
false
);
add
(
builder
.
toString
()
,
false
);
}
}
if
(
data
)
{
if
(
data
)
{
count
=
generateInsertValues
(
count
,
table
);
count
=
generateInsertValues
(
count
,
table
);
...
@@ -389,7 +389,7 @@ public class ScriptCommand extends ScriptBase {
...
@@ -389,7 +389,7 @@ public class ScriptCommand extends ScriptBase {
Cursor
cursor
=
index
.
find
(
session
,
null
,
null
);
Cursor
cursor
=
index
.
find
(
session
,
null
,
null
);
Column
[]
columns
=
table
.
getColumns
();
Column
[]
columns
=
table
.
getColumns
();
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
buff
.
append
(
table
.
getSQL
()).
append
(
'('
);
table
.
getSQL
(
buff
.
builder
()).
append
(
'('
);
for
(
Column
col
:
columns
)
{
for
(
Column
col
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
Parser
.
quoteIdentifier
(
buff
.
builder
(),
col
.
getName
());
Parser
.
quoteIdentifier
(
buff
.
builder
(),
col
.
getName
());
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
a36a6634
...
@@ -1474,8 +1474,8 @@ public class Select extends Query {
...
@@ -1474,8 +1474,8 @@ public class Select extends Query {
// since using a with statement will re-create the common table expression
// since using a with statement will re-create the common table expression
// views.
// views.
}
else
{
}
else
{
buff
.
append
(
"WITH RECURSIVE "
)
buff
.
append
(
"WITH RECURSIVE "
)
;
.
append
(
t
.
getSchema
().
getSQL
()).
append
(
'.'
);
t
.
getSchema
().
getSQL
(
buff
.
builder
()).
append
(
'.'
);
Parser
.
quoteIdentifier
(
buff
.
builder
(),
t
.
getName
())
Parser
.
quoteIdentifier
(
buff
.
builder
(),
t
.
getName
())
.
append
(
'('
);
.
append
(
'('
);
buff
.
resetCount
();
buff
.
resetCount
();
...
@@ -1483,7 +1483,8 @@ public class Select extends Query {
...
@@ -1483,7 +1483,8 @@ public class Select extends Query {
buff
.
appendExceptFirst
(
","
);
buff
.
appendExceptFirst
(
","
);
buff
.
append
(
c
.
getName
());
buff
.
append
(
c
.
getName
());
}
}
buff
.
append
(
") AS "
).
append
(
t
.
getSQL
()).
append
(
'\n'
);
buff
.
append
(
") AS "
);
t
.
getSQL
(
buff
.
builder
()).
append
(
'\n'
);
}
}
}
}
}
}
...
...
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
a36a6634
...
@@ -50,7 +50,7 @@ public class ConstraintCheck extends Constraint {
...
@@ -50,7 +50,7 @@ public class ConstraintCheck extends Constraint {
@Override
@Override
public
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
)
{
StringBuilder
buff
=
new
StringBuilder
(
"ALTER TABLE "
);
StringBuilder
buff
=
new
StringBuilder
(
"ALTER TABLE "
);
buff
.
append
(
forTable
.
getSQL
()
).
append
(
" ADD CONSTRAINT "
);
forTable
.
getSQL
(
buff
).
append
(
" ADD CONSTRAINT "
);
if
(
forTable
.
isHidden
())
{
if
(
forTable
.
isHidden
())
{
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
...
@@ -143,9 +143,8 @@ public class ConstraintCheck extends Constraint {
...
@@ -143,9 +143,8 @@ public class ConstraintCheck extends Constraint {
// don't check at startup
// don't check at startup
return
;
return
;
}
}
StringBuilder
builder
=
new
StringBuilder
().
append
(
"SELECT 1 FROM "
)
StringBuilder
builder
=
new
StringBuilder
().
append
(
"SELECT 1 FROM "
);
.
append
(
filter
.
getTable
().
getSQL
())
filter
.
getTable
().
getSQL
(
builder
).
append
(
" WHERE NOT("
);
.
append
(
" WHERE NOT("
);
expr
.
getSQL
(
builder
).
append
(
')'
);
expr
.
getSQL
(
builder
).
append
(
')'
);
String
sql
=
builder
.
toString
();
String
sql
=
builder
.
toString
();
ResultInterface
r
=
session
.
prepare
(
sql
).
query
(
1
);
ResultInterface
r
=
session
.
prepare
(
sql
).
query
(
1
);
...
...
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
a36a6634
...
@@ -80,8 +80,7 @@ public class ConstraintReferential extends Constraint {
...
@@ -80,8 +80,7 @@ public class ConstraintReferential extends Constraint {
public
String
getCreateSQLForCopy
(
Table
forTable
,
Table
forRefTable
,
public
String
getCreateSQLForCopy
(
Table
forTable
,
Table
forRefTable
,
String
quotedName
,
boolean
internalIndex
)
{
String
quotedName
,
boolean
internalIndex
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
String
mainTable
=
forTable
.
getSQL
();
forTable
.
getSQL
(
buff
.
builder
()).
append
(
" ADD CONSTRAINT "
);
buff
.
append
(
mainTable
).
append
(
" ADD CONSTRAINT "
);
if
(
forTable
.
isHidden
())
{
if
(
forTable
.
isHidden
())
{
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
...
@@ -99,17 +98,17 @@ public class ConstraintReferential extends Constraint {
...
@@ -99,17 +98,17 @@ public class ConstraintReferential extends Constraint {
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
if
(
internalIndex
&&
indexOwner
&&
forTable
==
this
.
table
)
{
if
(
internalIndex
&&
indexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
).
append
(
index
.
getSQL
());
buff
.
append
(
" INDEX "
);
index
.
getSQL
(
buff
.
builder
());
}
}
buff
.
append
(
" REFERENCES "
);
buff
.
append
(
" REFERENCES "
);
String
quotedRefTable
;
if
(
this
.
table
==
this
.
refTable
)
{
if
(
this
.
table
==
this
.
refTable
)
{
// self-referencing constraints: need to use new table
// self-referencing constraints: need to use new table
quotedRefTable
=
forTable
.
getSQL
(
);
forTable
.
getSQL
(
buff
.
builder
()
);
}
else
{
}
else
{
quotedRefTable
=
forRefTable
.
getSQL
(
);
forRefTable
.
getSQL
(
buff
.
builder
()
);
}
}
buff
.
append
(
quotedRefTable
).
append
(
'('
);
buff
.
append
(
'('
);
buff
.
resetCount
();
buff
.
resetCount
();
for
(
IndexColumn
r
:
refCols
)
{
for
(
IndexColumn
r
:
refCols
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
...
@@ -117,7 +116,8 @@ public class ConstraintReferential extends Constraint {
...
@@ -117,7 +116,8 @@ public class ConstraintReferential extends Constraint {
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
if
(
internalIndex
&&
refIndexOwner
&&
forTable
==
this
.
table
)
{
if
(
internalIndex
&&
refIndexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
).
append
(
refIndex
.
getSQL
());
buff
.
append
(
" INDEX "
);
refIndex
.
getSQL
(
buff
.
builder
());
}
}
if
(
deleteAction
!=
ConstraintActionType
.
RESTRICT
)
{
if
(
deleteAction
!=
ConstraintActionType
.
RESTRICT
)
{
buff
.
append
(
" ON DELETE "
).
append
(
deleteAction
.
getSqlName
());
buff
.
append
(
" ON DELETE "
).
append
(
deleteAction
.
getSqlName
());
...
@@ -139,12 +139,14 @@ public class ConstraintReferential extends Constraint {
...
@@ -139,12 +139,14 @@ public class ConstraintReferential extends Constraint {
*/
*/
private
String
getShortDescription
(
Index
searchIndex
,
SearchRow
check
)
{
private
String
getShortDescription
(
Index
searchIndex
,
SearchRow
check
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
getName
());
StatementBuilder
buff
=
new
StatementBuilder
(
getName
());
buff
.
append
(
": "
).
append
(
table
.
getSQL
()).
append
(
" FOREIGN KEY("
);
buff
.
append
(
": "
);
table
.
getSQL
(
buff
.
builder
()).
append
(
" FOREIGN KEY("
);
for
(
IndexColumn
c
:
columns
)
{
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
}
}
buff
.
append
(
") REFERENCES "
).
append
(
refTable
.
getSQL
()).
append
(
'('
);
buff
.
append
(
") REFERENCES "
);
refTable
.
getSQL
(
buff
.
builder
()).
append
(
'('
);
buff
.
resetCount
();
buff
.
resetCount
();
for
(
IndexColumn
r
:
refColumns
)
{
for
(
IndexColumn
r
:
refColumns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
...
@@ -491,7 +493,8 @@ public class ConstraintReferential extends Constraint {
...
@@ -491,7 +493,8 @@ public class ConstraintReferential extends Constraint {
}
}
StatementBuilder
buff
=
new
StatementBuilder
();
StatementBuilder
buff
=
new
StatementBuilder
();
if
(
deleteAction
==
ConstraintActionType
.
CASCADE
)
{
if
(
deleteAction
==
ConstraintActionType
.
CASCADE
)
{
buff
.
append
(
"DELETE FROM "
).
append
(
table
.
getSQL
());
buff
.
append
(
"DELETE FROM "
);
table
.
getSQL
(
buff
.
builder
());
}
else
{
}
else
{
appendUpdate
(
buff
);
appendUpdate
(
buff
);
}
}
...
@@ -567,7 +570,8 @@ public class ConstraintReferential extends Constraint {
...
@@ -567,7 +570,8 @@ public class ConstraintReferential extends Constraint {
}
}
private
void
appendUpdate
(
StatementBuilder
buff
)
{
private
void
appendUpdate
(
StatementBuilder
buff
)
{
buff
.
append
(
"UPDATE "
).
append
(
table
.
getSQL
()).
append
(
" SET "
);
buff
.
append
(
"UPDATE "
);
table
.
getSQL
(
buff
.
builder
()).
append
(
" SET "
);
buff
.
resetCount
();
buff
.
resetCount
();
for
(
IndexColumn
c
:
columns
)
{
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
...
@@ -622,7 +626,8 @@ public class ConstraintReferential extends Constraint {
...
@@ -622,7 +626,8 @@ public class ConstraintReferential extends Constraint {
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
}
}
buff
.
append
(
" FROM "
).
append
(
table
.
getSQL
()).
append
(
" WHERE "
);
buff
.
append
(
" FROM "
);
table
.
getSQL
(
buff
.
builder
()).
append
(
" WHERE "
);
buff
.
resetCount
();
buff
.
resetCount
();
for
(
IndexColumn
c
:
columns
)
{
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
appendExceptFirst
(
" AND "
);
...
@@ -634,8 +639,8 @@ public class ConstraintReferential extends Constraint {
...
@@ -634,8 +639,8 @@ public class ConstraintReferential extends Constraint {
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
buff
.
append
(
c
.
getSQL
());
}
}
buff
.
append
(
") C WHERE NOT EXISTS(SELECT 1 FROM "
)
.
buff
.
append
(
") C WHERE NOT EXISTS(SELECT 1 FROM "
)
;
append
(
refTable
.
getSQL
()).
append
(
" P WHERE "
);
refTable
.
getSQL
(
buff
.
builder
()).
append
(
" P WHERE "
);
buff
.
resetCount
();
buff
.
resetCount
();
int
i
=
0
;
int
i
=
0
;
for
(
IndexColumn
c
:
columns
)
{
for
(
IndexColumn
c
:
columns
)
{
...
...
h2/src/main/org/h2/constraint/ConstraintUnique.java
浏览文件 @
a36a6634
...
@@ -46,7 +46,7 @@ public class ConstraintUnique extends Constraint {
...
@@ -46,7 +46,7 @@ public class ConstraintUnique extends Constraint {
private
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
,
private
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
,
boolean
internalIndex
)
{
boolean
internalIndex
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
buff
.
append
(
forTable
.
getSQL
()).
append
(
" ADD CONSTRAINT "
);
forTable
.
getSQL
(
buff
.
builder
()).
append
(
" ADD CONSTRAINT "
);
if
(
forTable
.
isHidden
())
{
if
(
forTable
.
isHidden
())
{
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
...
@@ -62,7 +62,8 @@ public class ConstraintUnique extends Constraint {
...
@@ -62,7 +62,8 @@ public class ConstraintUnique extends Constraint {
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
if
(
internalIndex
&&
indexOwner
&&
forTable
==
this
.
table
)
{
if
(
internalIndex
&&
indexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
).
append
(
index
.
getSQL
());
buff
.
append
(
" INDEX "
);
index
.
getSQL
(
buff
.
builder
());
}
}
return
buff
.
toString
();
return
buff
.
toString
();
}
}
...
...
h2/src/main/org/h2/engine/Comment.java
浏览文件 @
a36a6634
...
@@ -102,7 +102,9 @@ public class Comment extends DbObjectBase {
...
@@ -102,7 +102,9 @@ public class Comment extends DbObjectBase {
* @return the key name
* @return the key name
*/
*/
static
String
getKey
(
DbObject
obj
)
{
static
String
getKey
(
DbObject
obj
)
{
return
getTypeName
(
obj
.
getType
())
+
" "
+
obj
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
getTypeName
(
obj
.
getType
())).
append
(
' '
);
obj
.
getSQL
(
builder
);
return
builder
.
toString
();
}
}
/**
/**
...
...
h2/src/main/org/h2/engine/Domain.java
浏览文件 @
a36a6634
...
@@ -28,12 +28,16 @@ public class Domain extends DbObjectBase {
...
@@ -28,12 +28,16 @@ public class Domain extends DbObjectBase {
@Override
@Override
public
String
getDropSQL
()
{
public
String
getDropSQL
()
{
return
"DROP DOMAIN IF EXISTS "
+
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"DROP DOMAIN IF EXISTS "
);
return
getSQL
(
builder
).
toString
();
}
}
@Override
@Override
public
String
getCreateSQL
()
{
public
String
getCreateSQL
()
{
return
"CREATE DOMAIN "
+
getSQL
()
+
" AS "
+
column
.
getCreateSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"CREATE DOMAIN "
);
getSQL
(
builder
).
append
(
" AS "
);
builder
.
append
(
column
.
getCreateSQL
());
return
builder
.
toString
();
}
}
public
Column
getColumn
()
{
public
Column
getColumn
()
{
...
...
h2/src/main/org/h2/engine/Right.java
浏览文件 @
a36a6634
...
@@ -135,18 +135,21 @@ public class Right extends DbObjectBase {
...
@@ -135,18 +135,21 @@ public class Right extends DbObjectBase {
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"GRANT "
);
buff
.
append
(
"GRANT "
);
if
(
grantedRole
!=
null
)
{
if
(
grantedRole
!=
null
)
{
buff
.
append
(
grantedRole
.
getSQL
()
);
grantedRole
.
getSQL
(
buff
);
}
else
{
}
else
{
buff
.
append
(
getRights
());
buff
.
append
(
getRights
());
if
(
object
!=
null
)
{
if
(
object
!=
null
)
{
if
(
object
instanceof
Schema
)
{
if
(
object
instanceof
Schema
)
{
buff
.
append
(
" ON SCHEMA "
).
append
(
object
.
getSQL
());
buff
.
append
(
" ON SCHEMA "
);
object
.
getSQL
(
buff
);
}
else
if
(
object
instanceof
Table
)
{
}
else
if
(
object
instanceof
Table
)
{
buff
.
append
(
" ON "
).
append
(
object
.
getSQL
());
buff
.
append
(
" ON "
);
object
.
getSQL
(
buff
);
}
}
}
}
}
}
buff
.
append
(
" TO "
).
append
(
grantee
.
getSQL
());
buff
.
append
(
" TO "
);
grantee
.
getSQL
(
buff
);
return
buff
.
toString
();
return
buff
.
toString
();
}
}
...
...
h2/src/main/org/h2/engine/Role.java
浏览文件 @
a36a6634
...
@@ -45,7 +45,7 @@ public class Role extends RightOwner {
...
@@ -45,7 +45,7 @@ public class Role extends RightOwner {
if
(
ifNotExists
)
{
if
(
ifNotExists
)
{
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
buff
.
append
(
getSQL
()
);
getSQL
(
buff
);
return
buff
.
toString
();
return
buff
.
toString
();
}
}
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
a36a6634
...
@@ -393,8 +393,10 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
...
@@ -393,8 +393,10 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
localTempTables
=
database
.
newStringMap
();
localTempTables
=
database
.
newStringMap
();
}
}
if
(
localTempTables
.
get
(
table
.
getName
())
!=
null
)
{
if
(
localTempTables
.
get
(
table
.
getName
())
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
StringBuilder
builder
=
new
StringBuilder
();
table
.
getSQL
()+
" AS "
+
table
.
getName
());
table
.
getSQL
(
builder
).
append
(
" AS "
);
Parser
.
quoteIdentifier
(
table
.
getName
());
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
builder
.
toString
());
}
}
modificationId
++;
modificationId
++;
localTempTables
.
put
(
table
.
getName
(),
table
);
localTempTables
.
put
(
table
.
getName
(),
table
);
...
...
h2/src/main/org/h2/engine/Setting.java
浏览文件 @
a36a6634
...
@@ -50,7 +50,7 @@ public class Setting extends DbObjectBase {
...
@@ -50,7 +50,7 @@ public class Setting extends DbObjectBase {
@Override
@Override
public
String
getCreateSQL
()
{
public
String
getCreateSQL
()
{
StringBuilder
buff
=
new
StringBuilder
(
"SET "
);
StringBuilder
buff
=
new
StringBuilder
(
"SET "
);
buff
.
append
(
getSQL
()
).
append
(
' '
);
getSQL
(
buff
).
append
(
' '
);
if
(
stringValue
!=
null
)
{
if
(
stringValue
!=
null
)
{
buff
.
append
(
stringValue
);
buff
.
append
(
stringValue
);
}
else
{
}
else
{
...
...
h2/src/main/org/h2/engine/User.java
浏览文件 @
a36a6634
...
@@ -157,7 +157,7 @@ public class User extends RightOwner {
...
@@ -157,7 +157,7 @@ public class User extends RightOwner {
*/
*/
public
String
getCreateSQL
(
boolean
password
)
{
public
String
getCreateSQL
(
boolean
password
)
{
StringBuilder
buff
=
new
StringBuilder
(
"CREATE USER IF NOT EXISTS "
);
StringBuilder
buff
=
new
StringBuilder
(
"CREATE USER IF NOT EXISTS "
);
buff
.
append
(
getSQL
()
);
getSQL
(
buff
);
if
(
comment
!=
null
)
{
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
" COMMENT "
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
...
...
h2/src/main/org/h2/engine/UserAggregate.java
浏览文件 @
a36a6634
...
@@ -59,13 +59,16 @@ public class UserAggregate extends DbObjectBase {
...
@@ -59,13 +59,16 @@ public class UserAggregate extends DbObjectBase {
@Override
@Override
public
String
getDropSQL
()
{
public
String
getDropSQL
()
{
return
"DROP AGGREGATE IF EXISTS "
+
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"DROP AGGREGATE IF EXISTS "
);
return
getSQL
(
builder
).
toString
();
}
}
@Override
@Override
public
String
getCreateSQL
()
{
public
String
getCreateSQL
()
{
return
"CREATE FORCE AGGREGATE "
+
getSQL
()
+
StringBuilder
builder
=
new
StringBuilder
(
"CREATE FORCE AGGREGATE "
);
" FOR "
+
Parser
.
quoteIdentifier
(
className
);
getSQL
(
builder
).
append
(
" FOR "
);
Parser
.
quoteIdentifier
(
builder
,
className
);
return
builder
.
toString
();
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/SequenceValue.java
浏览文件 @
a36a6634
...
@@ -55,7 +55,7 @@ public class SequenceValue extends Expression {
...
@@ -55,7 +55,7 @@ public class SequenceValue extends Expression {
@Override
@Override
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
"(NEXT VALUE FOR "
);
builder
.
append
(
"(NEXT VALUE FOR "
);
return
builder
.
append
(
sequence
.
getSQL
()
).
append
(
')'
);
return
sequence
.
getSQL
(
builder
).
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
a36a6634
...
@@ -93,12 +93,15 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -93,12 +93,15 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
* @return the exception
* @return the exception
*/
*/
protected
DbException
getDuplicateKeyException
(
String
key
)
{
protected
DbException
getDuplicateKeyException
(
String
key
)
{
String
sql
=
getName
()
+
" ON "
+
table
.
getSQL
()
+
StringBuilder
builder
=
new
StringBuilder
();
"("
+
getColumnListSQL
()
+
")"
;
getSQL
(
builder
).
append
(
" ON "
);
table
.
getSQL
(
builder
).
append
(
'('
);
builder
.
append
(
getColumnListSQL
());
builder
.
append
(
')'
);
if
(
key
!=
null
)
{
if
(
key
!=
null
)
{
sql
+=
" VALUES "
+
key
;
builder
.
append
(
" VALUES "
).
append
(
key
)
;
}
}
DbException
e
=
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
sql
);
DbException
e
=
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
builder
.
toString
()
);
e
.
setSource
(
this
);
e
.
setSource
(
this
);
return
e
;
return
e
;
}
}
...
@@ -426,7 +429,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -426,7 +429,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
buff
.
append
(
quotedName
);
buff
.
append
(
quotedName
);
buff
.
append
(
" ON "
).
append
(
targetTable
.
getSQL
());
buff
.
append
(
" ON "
);
targetTable
.
getSQL
(
buff
);
if
(
comment
!=
null
)
{
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
" COMMENT "
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
...
...
h2/src/main/org/h2/index/PageBtreeLeaf.java
浏览文件 @
a36a6634
...
@@ -229,7 +229,7 @@ public class PageBtreeLeaf extends PageBtree {
...
@@ -229,7 +229,7 @@ public class PageBtreeLeaf extends PageBtree {
SearchRow
delete
=
getRow
(
at
);
SearchRow
delete
=
getRow
(
at
);
if
(
index
.
compareRows
(
row
,
delete
)
!=
0
||
delete
.
getKey
()
!=
row
.
getKey
())
{
if
(
index
.
compareRows
(
row
,
delete
)
!=
0
||
delete
.
getKey
()
!=
row
.
getKey
())
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
index
.
getSQL
(
)
+
": "
+
row
);
index
.
getSQL
(
new
StringBuilder
()).
append
(
": "
).
append
(
row
).
toString
()
);
}
}
index
.
getPageStore
().
logUndo
(
this
,
data
);
index
.
getPageStore
().
logUndo
(
this
,
data
);
if
(
entryCount
==
1
)
{
if
(
entryCount
==
1
)
{
...
...
h2/src/main/org/h2/index/PageDataIndex.java
浏览文件 @
a36a6634
...
@@ -139,11 +139,12 @@ public class PageDataIndex extends PageIndex {
...
@@ -139,11 +139,12 @@ public class PageDataIndex extends PageIndex {
}
}
public
DbException
getNewDuplicateKeyException
()
{
public
DbException
getNewDuplicateKeyException
()
{
String
sql
=
"PRIMARY KEY ON "
+
table
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"PRIMARY KEY ON "
);
table
.
getSQL
(
builder
);
if
(
mainIndexColumn
>=
0
&&
mainIndexColumn
<
indexColumns
.
length
)
{
if
(
mainIndexColumn
>=
0
&&
mainIndexColumn
<
indexColumns
.
length
)
{
sql
+=
"("
+
indexColumns
[
mainIndexColumn
].
getSQL
()
+
")"
;
builder
.
append
(
'('
).
append
(
indexColumns
[
mainIndexColumn
].
getSQL
()).
append
(
')'
)
;
}
}
DbException
e
=
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
sql
);
DbException
e
=
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
builder
.
toString
()
);
e
.
setSource
(
this
);
e
.
setSource
(
this
);
return
e
;
return
e
;
}
}
...
@@ -478,7 +479,7 @@ public class PageDataIndex extends PageIndex {
...
@@ -478,7 +479,7 @@ public class PageDataIndex extends PageIndex {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
return
table
.
getSQL
(
)
+
".tableScan"
;
return
table
.
getSQL
(
new
StringBuilder
()).
append
(
".tableScan"
).
toString
()
;
}
}
int
getMemoryPerPage
()
{
int
getMemoryPerPage
()
{
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
a36a6634
...
@@ -416,7 +416,8 @@ public class PageDataLeaf extends PageData {
...
@@ -416,7 +416,8 @@ public class PageDataLeaf extends PageData {
int
i
=
find
(
key
);
int
i
=
find
(
key
);
if
(
keys
==
null
||
keys
[
i
]
!=
key
)
{
if
(
keys
==
null
||
keys
[
i
]
!=
key
)
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
index
.
getSQL
()
+
": "
+
key
+
" "
+
(
keys
==
null
?
-
1
:
keys
[
i
]));
index
.
getSQL
(
new
StringBuilder
()).
append
(
": "
).
append
(
key
).
append
(
' '
)
.
append
(
keys
==
null
?
-
1
:
keys
[
i
]).
toString
());
}
}
index
.
getPageStore
().
logUndo
(
this
,
data
);
index
.
getPageStore
().
logUndo
(
this
,
data
);
if
(
entryCount
==
1
)
{
if
(
entryCount
==
1
)
{
...
...
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
a36a6634
...
@@ -193,7 +193,7 @@ public class ScanIndex extends BaseIndex {
...
@@ -193,7 +193,7 @@ public class ScanIndex extends BaseIndex {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
return
table
.
getSQL
(
)
+
".tableScan"
;
return
table
.
getSQL
(
new
StringBuilder
()).
append
(
".tableScan"
).
toString
()
;
}
}
}
}
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
a36a6634
...
@@ -70,7 +70,7 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -70,7 +70,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
return
table
.
getSQL
(
)
+
".tableScan"
;
return
table
.
getSQL
(
new
StringBuilder
()).
append
(
".tableScan"
).
toString
()
;
}
}
public
void
setMainIndexColumn
(
int
mainIndexColumn
)
{
public
void
setMainIndexColumn
(
int
mainIndexColumn
)
{
...
@@ -116,16 +116,18 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -116,16 +116,18 @@ public class MVPrimaryIndex extends BaseIndex {
try
{
try
{
Value
oldValue
=
map
.
putIfAbsent
(
key
,
ValueArray
.
get
(
row
.
getValueList
()));
Value
oldValue
=
map
.
putIfAbsent
(
key
,
ValueArray
.
get
(
row
.
getValueList
()));
if
(
oldValue
!=
null
)
{
if
(
oldValue
!=
null
)
{
String
sql
=
"PRIMARY KEY ON "
+
table
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"PRIMARY KEY ON "
);
table
.
getSQL
(
builder
);
if
(
mainIndexColumn
>=
0
&&
mainIndexColumn
<
indexColumns
.
length
)
{
if
(
mainIndexColumn
>=
0
&&
mainIndexColumn
<
indexColumns
.
length
)
{
sql
+=
"("
+
indexColumns
[
mainIndexColumn
].
getSQL
()
+
")"
;
builder
.
append
(
'('
).
append
(
indexColumns
[
mainIndexColumn
].
getSQL
()).
append
(
')'
)
;
}
}
int
errorCode
=
ErrorCode
.
CONCURRENT_UPDATE_1
;
int
errorCode
=
ErrorCode
.
CONCURRENT_UPDATE_1
;
if
(
map
.
get
(
key
)
!=
null
)
{
if
(
map
.
get
(
key
)
!=
null
)
{
// committed
// committed
errorCode
=
ErrorCode
.
DUPLICATE_KEY_1
;
errorCode
=
ErrorCode
.
DUPLICATE_KEY_1
;
}
}
DbException
e
=
DbException
.
get
(
errorCode
,
sql
+
" "
+
oldValue
);
builder
.
append
(
' '
).
append
(
oldValue
);
DbException
e
=
DbException
.
get
(
errorCode
,
builder
.
toString
());
e
.
setSource
(
this
);
e
.
setSource
(
this
);
throw
e
;
throw
e
;
}
}
...
@@ -154,8 +156,9 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -154,8 +156,9 @@ public class MVPrimaryIndex extends BaseIndex {
try
{
try
{
Value
old
=
map
.
remove
(
ValueLong
.
get
(
row
.
getKey
()));
Value
old
=
map
.
remove
(
ValueLong
.
get
(
row
.
getKey
()));
if
(
old
==
null
)
{
if
(
old
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
StringBuilder
builder
=
new
StringBuilder
();
getSQL
()
+
": "
+
row
.
getKey
());
getSQL
(
builder
).
append
(
": "
).
append
(
row
.
getKey
());
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
builder
.
toString
());
}
}
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
throw
mvTable
.
convertException
(
e
);
throw
mvTable
.
convertException
(
e
);
...
@@ -194,8 +197,9 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -194,8 +197,9 @@ public class MVPrimaryIndex extends BaseIndex {
try
{
try
{
Value
existing
=
map
.
put
(
ValueLong
.
get
(
key
),
ValueArray
.
get
(
newRow
.
getValueList
()));
Value
existing
=
map
.
put
(
ValueLong
.
get
(
key
),
ValueArray
.
get
(
newRow
.
getValueList
()));
if
(
existing
==
null
)
{
if
(
existing
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
StringBuilder
builder
=
new
StringBuilder
();
getSQL
()
+
": "
+
key
);
getSQL
(
builder
).
append
(
": "
).
append
(
key
);
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
builder
.
toString
());
}
}
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
throw
mvTable
.
convertException
(
e
);
throw
mvTable
.
convertException
(
e
);
...
@@ -286,7 +290,7 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -286,7 +290,7 @@ public class MVPrimaryIndex extends BaseIndex {
return
getRow
(
session
,
key
,
(
ValueArray
)
v
);
return
getRow
(
session
,
key
,
(
ValueArray
)
v
);
}
}
private
Row
getRow
(
Session
session
,
long
key
,
ValueArray
array
)
{
private
static
Row
getRow
(
Session
session
,
long
key
,
ValueArray
array
)
{
Row
row
=
session
.
createRow
(
array
.
getList
(),
0
);
Row
row
=
session
.
createRow
(
array
.
getList
(),
0
);
row
.
setKey
(
key
);
row
.
setKey
(
key
);
return
row
;
return
row
;
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
a36a6634
...
@@ -231,8 +231,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
...
@@ -231,8 +231,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
try
{
try
{
Value
old
=
map
.
remove
(
array
);
Value
old
=
map
.
remove
(
array
);
if
(
old
==
null
)
{
if
(
old
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
StringBuilder
builder
=
new
StringBuilder
();
getSQL
()
+
": "
+
row
.
getKey
());
getSQL
(
builder
).
append
(
": "
).
append
(
row
.
getKey
());
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
builder
.
toString
());
}
}
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
throw
mvTable
.
convertException
(
e
);
throw
mvTable
.
convertException
(
e
);
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
a36a6634
...
@@ -183,9 +183,9 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -183,9 +183,9 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
try
{
try
{
Value
old
=
map
.
remove
(
key
);
Value
old
=
map
.
remove
(
key
);
if
(
old
==
null
)
{
if
(
old
==
null
)
{
old
=
map
.
remove
(
key
);
StringBuilder
builder
=
new
StringBuilder
(
);
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
getSQL
(
builder
).
append
(
": "
).
append
(
row
.
getKey
());
getSQL
()
+
": "
+
row
.
getKey
());
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
builder
.
toString
());
}
}
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
throw
mvTable
.
convertException
(
e
);
throw
mvTable
.
convertException
(
e
);
...
...
h2/src/main/org/h2/schema/Constant.java
浏览文件 @
a36a6634
...
@@ -38,7 +38,8 @@ public class Constant extends SchemaObjectBase {
...
@@ -38,7 +38,8 @@ public class Constant extends SchemaObjectBase {
@Override
@Override
public
String
getCreateSQL
()
{
public
String
getCreateSQL
()
{
StringBuilder
builder
=
new
StringBuilder
().
append
(
"CREATE CONSTANT "
).
append
(
getSQL
()).
append
(
" VALUE "
);
StringBuilder
builder
=
new
StringBuilder
(
"CREATE CONSTANT "
);
getSQL
(
builder
).
append
(
" VALUE "
);
return
value
.
getSQL
(
builder
).
toString
();
return
value
.
getSQL
(
builder
).
toString
();
}
}
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
a36a6634
...
@@ -110,8 +110,10 @@ public class Schema extends DbObjectBase {
...
@@ -110,8 +110,10 @@ public class Schema extends DbObjectBase {
if
(
system
)
{
if
(
system
)
{
return
null
;
return
null
;
}
}
return
"CREATE SCHEMA IF NOT EXISTS "
+
StringBuilder
builder
=
new
StringBuilder
(
"CREATE SCHEMA IF NOT EXISTS "
);
getSQL
()
+
" AUTHORIZATION "
+
owner
.
getSQL
();
getSQL
(
builder
).
append
(
" AUTHORIZATION "
);
owner
.
getSQL
(
builder
);
return
builder
.
toString
();
}
}
@Override
@Override
...
...
h2/src/main/org/h2/schema/Sequence.java
浏览文件 @
a36a6634
...
@@ -211,7 +211,8 @@ public class Sequence extends SchemaObjectBase {
...
@@ -211,7 +211,8 @@ public class Sequence extends SchemaObjectBase {
if
(
getBelongsToTable
())
{
if
(
getBelongsToTable
())
{
return
null
;
return
null
;
}
}
return
"DROP SEQUENCE IF EXISTS "
+
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"DROP SEQUENCE IF EXISTS "
);
return
getSQL
(
builder
).
toString
();
}
}
@Override
@Override
...
@@ -223,7 +224,7 @@ public class Sequence extends SchemaObjectBase {
...
@@ -223,7 +224,7 @@ public class Sequence extends SchemaObjectBase {
public
synchronized
String
getCreateSQL
()
{
public
synchronized
String
getCreateSQL
()
{
long
v
=
writeWithMargin
?
valueWithMargin
:
value
;
long
v
=
writeWithMargin
?
valueWithMargin
:
value
;
StringBuilder
buff
=
new
StringBuilder
(
"CREATE SEQUENCE "
);
StringBuilder
buff
=
new
StringBuilder
(
"CREATE SEQUENCE "
);
buff
.
append
(
getSQL
()
).
append
(
" START WITH "
).
append
(
v
);
getSQL
(
buff
).
append
(
" START WITH "
).
append
(
v
);
if
(
increment
!=
1
)
{
if
(
increment
!=
1
)
{
buff
.
append
(
" INCREMENT BY "
).
append
(
increment
);
buff
.
append
(
" INCREMENT BY "
).
append
(
increment
);
}
}
...
...
h2/src/main/org/h2/schema/TriggerObject.java
浏览文件 @
a36a6634
...
@@ -335,7 +335,8 @@ public class TriggerObject extends SchemaObjectBase {
...
@@ -335,7 +335,8 @@ public class TriggerObject extends SchemaObjectBase {
buff
.
append
(
" AFTER "
);
buff
.
append
(
" AFTER "
);
}
}
buff
.
append
(
getTypeNameList
());
buff
.
append
(
getTypeNameList
());
buff
.
append
(
" ON "
).
append
(
targetTable
.
getSQL
());
buff
.
append
(
" ON "
);
targetTable
.
getSQL
(
buff
);
if
(
rowBased
)
{
if
(
rowBased
)
{
buff
.
append
(
" FOR EACH ROW"
);
buff
.
append
(
" FOR EACH ROW"
);
}
}
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
a36a6634
...
@@ -490,7 +490,8 @@ public class Column {
...
@@ -490,7 +490,8 @@ public class Column {
buff
.
append
(
" NULL_TO_DEFAULT"
);
buff
.
append
(
" NULL_TO_DEFAULT"
);
}
}
if
(
sequence
!=
null
)
{
if
(
sequence
!=
null
)
{
buff
.
append
(
" SEQUENCE "
).
append
(
sequence
.
getSQL
());
buff
.
append
(
" SEQUENCE "
);
sequence
.
getSQL
(
buff
);
}
}
if
(
selectivity
!=
0
)
{
if
(
selectivity
!=
0
)
{
buff
.
append
(
" SELECTIVITY "
).
append
(
selectivity
);
buff
.
append
(
" SELECTIVITY "
).
append
(
selectivity
);
...
...
h2/src/main/org/h2/table/TableBase.java
浏览文件 @
a36a6634
...
@@ -79,7 +79,9 @@ public abstract class TableBase extends Table {
...
@@ -79,7 +79,9 @@ public abstract class TableBase extends Table {
@Override
@Override
public
String
getDropSQL
()
{
public
String
getDropSQL
()
{
return
"DROP TABLE IF EXISTS "
+
getSQL
()
+
" CASCADE"
;
StringBuilder
builder
=
new
StringBuilder
(
"DROP TABLE IF EXISTS "
);
getSQL
(
builder
).
append
(
" CASCADE"
);
return
builder
.
toString
();
}
}
@Override
@Override
...
@@ -106,7 +108,7 @@ public abstract class TableBase extends Table {
...
@@ -106,7 +108,7 @@ public abstract class TableBase extends Table {
if
(
isHidden
)
{
if
(
isHidden
)
{
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
buff
.
append
(
getSQL
());
getSQL
(
buff
.
builder
());
if
(
comment
!=
null
)
{
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
" COMMENT "
);
StringUtils
.
quoteStringSQL
(
buff
.
builder
(),
comment
);
StringUtils
.
quoteStringSQL
(
buff
.
builder
(),
comment
);
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
a36a6634
...
@@ -791,10 +791,10 @@ public class TableFilter implements ColumnResolver {
...
@@ -791,10 +791,10 @@ public class TableFilter implements ColumnResolver {
return
builder
;
return
builder
;
}
}
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isRecursive
())
{
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isRecursive
())
{
builder
.
append
(
table
.
getSchema
().
getSQL
()
).
append
(
'.'
);
table
.
getSchema
().
getSQL
(
builder
).
append
(
'.'
);
Parser
.
quoteIdentifier
(
builder
,
table
.
getName
());
Parser
.
quoteIdentifier
(
builder
,
table
.
getName
());
}
else
{
}
else
{
builder
.
append
(
table
.
getSQL
()
);
table
.
getSQL
(
builder
);
}
}
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isInvalid
())
{
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isInvalid
())
{
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
table
.
getName
(),
"not compiled"
);
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
table
.
getName
(),
"not compiled"
);
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
a36a6634
...
@@ -354,7 +354,8 @@ public class TableLink extends Table {
...
@@ -354,7 +354,8 @@ public class TableLink extends Table {
@Override
@Override
public
String
getDropSQL
()
{
public
String
getDropSQL
()
{
return
"DROP TABLE IF EXISTS "
+
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"DROP TABLE IF EXISTS "
);
return
getSQL
(
builder
).
toString
();
}
}
@Override
@Override
...
@@ -368,7 +369,8 @@ public class TableLink extends Table {
...
@@ -368,7 +369,8 @@ public class TableLink extends Table {
}
}
buff
.
append
(
"TEMPORARY "
);
buff
.
append
(
"TEMPORARY "
);
}
}
buff
.
append
(
"LINKED TABLE "
).
append
(
getSQL
());
buff
.
append
(
"LINKED TABLE "
);
getSQL
(
buff
);
if
(
comment
!=
null
)
{
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
" COMMENT "
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
...
...
h2/src/main/org/h2/table/TableSynonym.java
浏览文件 @
a36a6634
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
org
.
h2
.
table
;
package
org
.
h2
.
table
;
import
org.h2.command.Parser
;
import
org.h2.command.ddl.CreateSynonymData
;
import
org.h2.command.ddl.CreateSynonymData
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
...
@@ -67,12 +68,18 @@ public class TableSynonym extends SchemaObjectBase {
...
@@ -67,12 +68,18 @@ public class TableSynonym extends SchemaObjectBase {
@Override
@Override
public
String
getCreateSQL
()
{
public
String
getCreateSQL
()
{
return
"CREATE SYNONYM "
+
getSQL
()
+
" FOR "
+
data
.
synonymForSchema
.
getName
()
+
"."
+
data
.
synonymFor
;
StringBuilder
builder
=
new
StringBuilder
(
"CREATE SYNONYM "
);
getSQL
(
builder
).
append
(
" FOR "
);
Parser
.
quoteIdentifier
(
data
.
synonymForSchema
.
getName
());
builder
.
append
(
'.'
);
Parser
.
quoteIdentifier
(
data
.
synonymFor
);
return
builder
.
toString
();
}
}
@Override
@Override
public
String
getDropSQL
()
{
public
String
getDropSQL
()
{
return
"DROP SYNONYM "
+
getSQL
();
StringBuilder
builder
=
new
StringBuilder
(
"DROP SYNONYM "
);
return
getSQL
(
builder
).
toString
();
}
}
@Override
@Override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论