Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
42086958
提交
42086958
authored
10月 16, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
IF [NOT] EXISTS is supported for named constraints.
上级
7345f4fc
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
34 行增加
和
15 行删除
+34
-15
Parser.java
h2/src/main/org/h2/command/Parser.java
+13
-9
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+6
-1
AlterTableDropConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableDropConstraint.java
+15
-5
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
42086958
...
@@ -4271,9 +4271,11 @@ public class Parser {
...
@@ -4271,9 +4271,11 @@ public class Parser {
return
command
;
return
command
;
}
else
if
(
readIf
(
"DROP"
))
{
}
else
if
(
readIf
(
"DROP"
))
{
if
(
readIf
(
"CONSTRAINT"
))
{
if
(
readIf
(
"CONSTRAINT"
))
{
boolean
ifExists
=
readIfExists
(
false
);
String
constraintName
=
readIdentifierWithSchema
(
table
.
getSchema
().
getName
());
String
constraintName
=
readIdentifierWithSchema
(
table
.
getSchema
().
getName
());
ifExists
=
readIfExists
(
ifExists
);
checkSchema
(
table
.
getSchema
());
checkSchema
(
table
.
getSchema
());
AlterTableDropConstraint
command
=
new
AlterTableDropConstraint
(
session
,
getSchema
());
AlterTableDropConstraint
command
=
new
AlterTableDropConstraint
(
session
,
getSchema
()
,
ifExists
);
command
.
setConstraintName
(
constraintName
);
command
.
setConstraintName
(
constraintName
);
return
command
;
return
command
;
}
else
if
(
readIf
(
"PRIMARY"
))
{
}
else
if
(
readIf
(
"PRIMARY"
))
{
...
@@ -4393,14 +4395,16 @@ public class Parser {
...
@@ -4393,14 +4395,16 @@ public class Parser {
private
Prepared
parseAlterTableAddConstraintIf
(
String
tableName
,
Schema
schema
)
throws
SQLException
{
private
Prepared
parseAlterTableAddConstraintIf
(
String
tableName
,
Schema
schema
)
throws
SQLException
{
String
constraintName
=
null
,
comment
=
null
;
String
constraintName
=
null
,
comment
=
null
;
boolean
ifNotExists
=
false
;
if
(
readIf
(
"CONSTRAINT"
))
{
if
(
readIf
(
"CONSTRAINT"
))
{
ifNotExists
=
readIfNoExists
();
constraintName
=
readIdentifierWithSchema
(
schema
.
getName
());
constraintName
=
readIdentifierWithSchema
(
schema
.
getName
());
checkSchema
(
schema
);
checkSchema
(
schema
);
comment
=
readCommentIf
();
comment
=
readCommentIf
();
}
}
if
(
readIf
(
"PRIMARY"
))
{
if
(
readIf
(
"PRIMARY"
))
{
read
(
"KEY"
);
read
(
"KEY"
);
AlterTableAddConstraint
command
=
new
AlterTableAddConstraint
(
session
,
schema
);
AlterTableAddConstraint
command
=
new
AlterTableAddConstraint
(
session
,
schema
,
ifNotExists
);
command
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
command
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
command
.
setComment
(
comment
);
command
.
setComment
(
comment
);
command
.
setConstraintName
(
constraintName
);
command
.
setConstraintName
(
constraintName
);
...
@@ -4429,12 +4433,12 @@ public class Parser {
...
@@ -4429,12 +4433,12 @@ public class Parser {
}
}
AlterTableAddConstraint
command
;
AlterTableAddConstraint
command
;
if
(
readIf
(
"CHECK"
))
{
if
(
readIf
(
"CHECK"
))
{
command
=
new
AlterTableAddConstraint
(
session
,
schema
);
command
=
new
AlterTableAddConstraint
(
session
,
schema
,
ifNotExists
);
command
.
setType
(
AlterTableAddConstraint
.
CHECK
);
command
.
setType
(
AlterTableAddConstraint
.
CHECK
);
command
.
setCheckExpression
(
readExpression
());
command
.
setCheckExpression
(
readExpression
());
}
else
if
(
readIf
(
"UNIQUE"
))
{
}
else
if
(
readIf
(
"UNIQUE"
))
{
readIf
(
"INDEX"
);
readIf
(
"INDEX"
);
command
=
new
AlterTableAddConstraint
(
session
,
schema
);
command
=
new
AlterTableAddConstraint
(
session
,
schema
,
ifNotExists
);
command
.
setType
(
AlterTableAddConstraint
.
UNIQUE
);
command
.
setType
(
AlterTableAddConstraint
.
UNIQUE
);
if
(!
readIf
(
"("
))
{
if
(!
readIf
(
"("
))
{
constraintName
=
readUniqueIdentifier
();
constraintName
=
readUniqueIdentifier
();
...
@@ -4446,7 +4450,7 @@ public class Parser {
...
@@ -4446,7 +4450,7 @@ public class Parser {
command
.
setIndex
(
getSchema
().
findIndex
(
session
,
indexName
));
command
.
setIndex
(
getSchema
().
findIndex
(
session
,
indexName
));
}
}
}
else
if
(
readIf
(
"FOREIGN"
))
{
}
else
if
(
readIf
(
"FOREIGN"
))
{
command
=
new
AlterTableAddConstraint
(
session
,
schema
);
command
=
new
AlterTableAddConstraint
(
session
,
schema
,
ifNotExists
);
command
.
setType
(
AlterTableAddConstraint
.
REFERENTIAL
);
command
.
setType
(
AlterTableAddConstraint
.
REFERENTIAL
);
read
(
"KEY"
);
read
(
"KEY"
);
read
(
"("
);
read
(
"("
);
...
@@ -4574,7 +4578,7 @@ public class Parser {
...
@@ -4574,7 +4578,7 @@ public class Parser {
column
.
setPrimaryKey
(
false
);
column
.
setPrimaryKey
(
false
);
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
cols
[
0
].
columnName
=
column
.
getName
();
cols
[
0
].
columnName
=
column
.
getName
();
AlterTableAddConstraint
pk
=
new
AlterTableAddConstraint
(
session
,
schema
);
AlterTableAddConstraint
pk
=
new
AlterTableAddConstraint
(
session
,
schema
,
false
);
pk
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
pk
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
pk
.
setTableName
(
tableName
);
pk
.
setTableName
(
tableName
);
pk
.
setIndexColumns
(
cols
);
pk
.
setIndexColumns
(
cols
);
...
@@ -4590,7 +4594,7 @@ public class Parser {
...
@@ -4590,7 +4594,7 @@ public class Parser {
boolean
hash
=
readIf
(
"HASH"
);
boolean
hash
=
readIf
(
"HASH"
);
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
cols
[
0
].
columnName
=
column
.
getName
();
cols
[
0
].
columnName
=
column
.
getName
();
AlterTableAddConstraint
pk
=
new
AlterTableAddConstraint
(
session
,
schema
);
AlterTableAddConstraint
pk
=
new
AlterTableAddConstraint
(
session
,
schema
,
false
);
pk
.
setPrimaryKeyHash
(
hash
);
pk
.
setPrimaryKeyHash
(
hash
);
pk
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
pk
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
pk
.
setTableName
(
tableName
);
pk
.
setTableName
(
tableName
);
...
@@ -4600,7 +4604,7 @@ public class Parser {
...
@@ -4600,7 +4604,7 @@ public class Parser {
parseAutoIncrement
(
column
);
parseAutoIncrement
(
column
);
}
}
}
else
if
(
readIf
(
"UNIQUE"
))
{
}
else
if
(
readIf
(
"UNIQUE"
))
{
AlterTableAddConstraint
unique
=
new
AlterTableAddConstraint
(
session
,
schema
);
AlterTableAddConstraint
unique
=
new
AlterTableAddConstraint
(
session
,
schema
,
false
);
unique
.
setConstraintName
(
constraintName
);
unique
.
setConstraintName
(
constraintName
);
unique
.
setType
(
AlterTableAddConstraint
.
UNIQUE
);
unique
.
setType
(
AlterTableAddConstraint
.
UNIQUE
);
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
...
@@ -4614,7 +4618,7 @@ public class Parser {
...
@@ -4614,7 +4618,7 @@ public class Parser {
column
.
addCheckConstraint
(
session
,
expr
);
column
.
addCheckConstraint
(
session
,
expr
);
}
}
if
(
readIf
(
"REFERENCES"
))
{
if
(
readIf
(
"REFERENCES"
))
{
AlterTableAddConstraint
ref
=
new
AlterTableAddConstraint
(
session
,
schema
);
AlterTableAddConstraint
ref
=
new
AlterTableAddConstraint
(
session
,
schema
,
false
);
ref
.
setConstraintName
(
constraintName
);
ref
.
setConstraintName
(
constraintName
);
ref
.
setType
(
AlterTableAddConstraint
.
REFERENTIAL
);
ref
.
setType
(
AlterTableAddConstraint
.
REFERENTIAL
);
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
...
...
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
42086958
...
@@ -69,9 +69,11 @@ public class AlterTableAddConstraint extends SchemaCommand {
...
@@ -69,9 +69,11 @@ public class AlterTableAddConstraint extends SchemaCommand {
private
String
comment
;
private
String
comment
;
private
boolean
checkExisting
;
private
boolean
checkExisting
;
private
boolean
primaryKeyHash
;
private
boolean
primaryKeyHash
;
private
boolean
ifNotExists
;
public
AlterTableAddConstraint
(
Session
session
,
Schema
schema
)
{
public
AlterTableAddConstraint
(
Session
session
,
Schema
schema
,
boolean
ifNotExists
)
{
super
(
session
,
schema
);
super
(
session
,
schema
);
this
.
ifNotExists
=
ifNotExists
;
}
}
private
String
generateConstraintName
(
Table
table
)
{
private
String
generateConstraintName
(
Table
table
)
{
...
@@ -99,6 +101,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
...
@@ -99,6 +101,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
if
(
getSchema
().
findConstraint
(
constraintName
)
!=
null
)
{
if
(
getSchema
().
findConstraint
(
constraintName
)
!=
null
)
{
if
(
ifNotExists
)
{
return
0
;
}
throw
Message
.
getSQLException
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
constraintName
);
throw
Message
.
getSQLException
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
constraintName
);
}
}
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
...
...
h2/src/main/org/h2/command/ddl/AlterTableDropConstraint.java
浏览文件 @
42086958
...
@@ -8,9 +8,11 @@ package org.h2.command.ddl;
...
@@ -8,9 +8,11 @@ package org.h2.command.ddl;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.engine.Right
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
/**
/**
...
@@ -20,9 +22,11 @@ import org.h2.schema.Schema;
...
@@ -20,9 +22,11 @@ import org.h2.schema.Schema;
public
class
AlterTableDropConstraint
extends
SchemaCommand
{
public
class
AlterTableDropConstraint
extends
SchemaCommand
{
private
String
constraintName
;
private
String
constraintName
;
private
boolean
ifExists
;
public
AlterTableDropConstraint
(
Session
session
,
Schema
schema
)
{
public
AlterTableDropConstraint
(
Session
session
,
Schema
schema
,
boolean
ifExists
)
{
super
(
session
,
schema
);
super
(
session
,
schema
);
this
.
ifExists
=
ifExists
;
}
}
public
void
setConstraintName
(
String
string
)
{
public
void
setConstraintName
(
String
string
)
{
...
@@ -31,10 +35,16 @@ public class AlterTableDropConstraint extends SchemaCommand {
...
@@ -31,10 +35,16 @@ public class AlterTableDropConstraint extends SchemaCommand {
public
int
update
()
throws
SQLException
{
public
int
update
()
throws
SQLException
{
session
.
commit
(
true
);
session
.
commit
(
true
);
Constraint
constraint
=
getSchema
().
getConstraint
(
constraintName
);
Constraint
constraint
=
getSchema
().
findConstraint
(
constraintName
);
if
(
constraint
==
null
)
{
if
(!
ifExists
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
CONSTRAINT_NOT_FOUND_1
,
constraintName
);
}
}
else
{
session
.
getUser
().
checkRight
(
constraint
.
getTable
(),
Right
.
ALL
);
session
.
getUser
().
checkRight
(
constraint
.
getTable
(),
Right
.
ALL
);
session
.
getUser
().
checkRight
(
constraint
.
getRefTable
(),
Right
.
ALL
);
session
.
getUser
().
checkRight
(
constraint
.
getRefTable
(),
Right
.
ALL
);
session
.
getDatabase
().
removeSchemaObject
(
session
,
constraint
);
session
.
getDatabase
().
removeSchemaObject
(
session
,
constraint
);
}
return
0
;
return
0
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论