Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
507d02d0
提交
507d02d0
authored
9月 22, 2015
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/h2database/h2database
上级
67c8fd67
b2b7c44d
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
85 行增加
和
63 行删除
+85
-63
help.csv
h2/src/docsrc/help/help.csv
+3
-2
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+10
-5
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+24
-7
Table.java
h2/src/main/org/h2/table/Table.java
+34
-31
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+0
-5
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+0
-3
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+12
-1
TestLimit.java
h2/src/test/org/h2/test/synth/TestLimit.java
+0
-1
TestNestedJoins.java
h2/src/test/org/h2/test/synth/TestNestedJoins.java
+0
-4
TestOuterJoins.java
h2/src/test/org/h2/test/synth/TestOuterJoins.java
+0
-4
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
507d02d0
...
@@ -289,12 +289,13 @@ ALTER TABLE TEST ALTER COLUMN NAME SET NULL;
...
@@ -289,12 +289,13 @@ ALTER TABLE TEST ALTER COLUMN NAME SET NULL;
"
"
"Commands (DDL)","ALTER TABLE DROP COLUMN","
"Commands (DDL)","ALTER TABLE DROP COLUMN","
ALTER TABLE tableName DROP COLUMN [ IF EXISTS ]
columnName
ALTER TABLE tableName DROP COLUMN [ IF EXISTS ]
( columnName [,...] )
","
","
Removes
a column
from a table.
Removes
column(s)
from a table.
This command commits an open transaction in this connection.
This command commits an open transaction in this connection.
","
","
ALTER TABLE TEST DROP COLUMN NAME
ALTER TABLE TEST DROP COLUMN NAME
ALTER TABLE TEST DROP COLUMN NAME1, NAME2
"
"
"Commands (DDL)","ALTER TABLE DROP CONSTRAINT","
"Commands (DDL)","ALTER TABLE DROP CONSTRAINT","
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
507d02d0
...
@@ -28,6 +28,8 @@ Change Log
...
@@ -28,6 +28,8 @@ Change Log
<h2>
Version 1.4.189 Beta (2015-09-13)
</h2>
<h2>
Version 1.4.189 Beta (2015-09-13)
</h2>
<ul>
<ul>
<li>
Add support for dropping multiple columns in ALTER TABLE DROP COLUMN...
</li>
<li>
Fix bug in XA management when doing rollback after prepare. Patch by Stephane Lacoin.
<li>
Fix bug in XA management when doing rollback after prepare. Patch by Stephane Lacoin.
</li>
</li>
<li>
MVStore CLOB and BLOB: An exception with the message "Block not found" could be thrown
<li>
MVStore CLOB and BLOB: An exception with the message "Block not found" could be thrown
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
507d02d0
...
@@ -5415,12 +5415,17 @@ public class Parser {
...
@@ -5415,12 +5415,17 @@ public class Parser {
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
table
.
getSchema
());
session
,
table
.
getSchema
());
command
.
setType
(
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
);
command
.
setType
(
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
);
ArrayList
<
Column
>
columnsToRemove
=
New
.
arrayList
();
do
{
String
columnName
=
readColumnIdentifier
();
String
columnName
=
readColumnIdentifier
();
command
.
setTable
(
table
);
if
(
ifExists
&&
!
table
.
doesColumnExist
(
columnName
))
{
if
(
ifExists
&&
!
table
.
doesColumnExist
(
columnName
))
{
return
new
NoOperation
(
session
);
return
new
NoOperation
(
session
);
}
}
command
.
setOldColumn
(
table
.
getColumn
(
columnName
));
Column
column
=
table
.
getColumn
(
columnName
);
columnsToRemove
.
add
(
column
);
}
while
(
readIf
(
","
));
command
.
setTable
(
table
);
command
.
setColumnsToRemove
(
columnsToRemove
);
return
command
;
return
command
;
}
}
}
else
if
(
readIf
(
"CHANGE"
))
{
}
else
if
(
readIf
(
"CHANGE"
))
{
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
507d02d0
...
@@ -7,7 +7,7 @@ package org.h2.command.ddl;
...
@@ -7,7 +7,7 @@ package org.h2.command.ddl;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
...
@@ -57,6 +57,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -57,6 +57,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private
String
addAfter
;
private
String
addAfter
;
private
boolean
ifNotExists
;
private
boolean
ifNotExists
;
private
ArrayList
<
Column
>
columnsToAdd
;
private
ArrayList
<
Column
>
columnsToAdd
;
private
ArrayList
<
Column
>
columnsToRemove
;
public
AlterTableAlterColumn
(
Session
session
,
Schema
schema
)
{
public
AlterTableAlterColumn
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
super
(
session
,
schema
);
...
@@ -85,7 +86,6 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -85,7 +86,6 @@ public class AlterTableAlterColumn extends SchemaCommand {
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
table
.
checkSupportAlter
();
table
.
checkSupportAlter
();
table
.
lock
(
session
,
true
,
true
);
table
.
lock
(
session
,
true
,
true
);
Sequence
sequence
=
oldColumn
==
null
?
null
:
oldColumn
.
getSequence
();
if
(
newColumn
!=
null
)
{
if
(
newColumn
!=
null
)
{
checkDefaultReferencesTable
(
newColumn
.
getDefaultExpression
());
checkDefaultReferencesTable
(
newColumn
.
getDefaultExpression
());
}
}
...
@@ -116,6 +116,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -116,6 +116,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
break
;
break
;
}
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_DEFAULT
:
{
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_DEFAULT
:
{
Sequence
sequence
=
oldColumn
==
null
?
null
:
oldColumn
.
getSequence
();
checkDefaultReferencesTable
(
defaultExpression
);
checkDefaultReferencesTable
(
defaultExpression
);
oldColumn
.
setSequence
(
null
);
oldColumn
.
setSequence
(
null
);
oldColumn
.
setDefaultExpression
(
session
,
defaultExpression
);
oldColumn
.
setDefaultExpression
(
session
,
defaultExpression
);
...
@@ -162,11 +163,11 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -162,11 +163,11 @@ public class AlterTableAlterColumn extends SchemaCommand {
break
;
break
;
}
}
case
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
:
{
case
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
:
{
if
(
table
.
getColumns
().
length
==
1
)
{
if
(
table
.
getColumns
().
length
-
columnsToRemove
.
size
()
<
1
)
{
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_LAST_COLUMN
,
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_LAST_COLUMN
,
oldColumn
.
getSQL
());
columnsToRemove
.
get
(
0
)
.
getSQL
());
}
}
table
.
drop
SingleColumnConstraintsAndIndexes
(
session
,
oldColumn
);
table
.
drop
MultipleColumnsConstraintsAndIndexes
(
session
,
columnsToRemove
);
copyData
();
copyData
();
break
;
break
;
}
}
...
@@ -282,8 +283,20 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -282,8 +283,20 @@ public class AlterTableAlterColumn extends SchemaCommand {
newColumns
.
add
(
col
.
getClone
());
newColumns
.
add
(
col
.
getClone
());
}
}
if
(
type
==
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
)
{
if
(
type
==
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
)
{
int
position
=
oldColumn
.
getColumnId
();
for
(
Column
removeCol
:
columnsToRemove
)
{
newColumns
.
remove
(
position
);
Column
foundCol
=
null
;
for
(
Iterator
<
Column
>
iter
=
newColumns
.
iterator
();
iter
.
hasNext
();
)
{
Column
newCol
=
iter
.
next
();
if
(
newCol
.
getName
()
==
removeCol
.
getName
())
{
foundCol
=
newCol
;
break
;
}
}
if
(
foundCol
==
null
)
{
throw
DbException
.
throwInternalError
(
removeCol
.
getCreateSQL
());
}
newColumns
.
remove
(
foundCol
);
}
}
else
if
(
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
)
{
}
else
if
(
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
)
{
int
position
;
int
position
;
if
(
addBefore
!=
null
)
{
if
(
addBefore
!=
null
)
{
...
@@ -509,4 +522,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -509,4 +522,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
public
void
setNewColumns
(
ArrayList
<
Column
>
columnsToAdd
)
{
public
void
setNewColumns
(
ArrayList
<
Column
>
columnsToAdd
)
{
this
.
columnsToAdd
=
columnsToAdd
;
this
.
columnsToAdd
=
columnsToAdd
;
}
}
public
void
setColumnsToRemove
(
ArrayList
<
Column
>
columnsToRemove
)
{
this
.
columnsToRemove
=
columnsToRemove
;
}
}
}
h2/src/main/org/h2/table/Table.java
浏览文件 @
507d02d0
...
@@ -9,7 +9,6 @@ import java.util.ArrayList;
...
@@ -9,7 +9,6 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
...
@@ -531,19 +530,20 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -531,19 +530,20 @@ public abstract class Table extends SchemaObjectBase {
}
}
/**
/**
* Check that th
is column is
not referenced by a multi-column constraint or
* Check that th
ese columns are
not referenced by a multi-column constraint or
* multi-column index. If it is, an exception is thrown. Single-column
* multi-column index. If it is, an exception is thrown. Single-column
* references and indexes are dropped.
* references and indexes are dropped.
*
*
* @param session the session
* @param session the session
* @param col
the column
* @param col
umsToDrop the columns to drop
* @throws DbException if the column is referenced by multi-column
* @throws DbException if the column is referenced by multi-column
* constraints or indexes
* constraints or indexes
*/
*/
public
void
drop
SingleColumn
ConstraintsAndIndexes
(
Session
session
,
public
void
drop
MultipleColumns
ConstraintsAndIndexes
(
Session
session
,
Column
col
)
{
ArrayList
<
Column
>
columsToDrop
)
{
ArrayList
<
Constraint
>
constraintsToDrop
=
New
.
arrayLis
t
();
HashSet
<
Constraint
>
constraintsToDrop
=
New
.
hashSe
t
();
if
(
constraints
!=
null
)
{
if
(
constraints
!=
null
)
{
for
(
Column
col
:
columsToDrop
)
{
for
(
int
i
=
0
,
size
=
constraints
.
size
();
i
<
size
;
i
++)
{
for
(
int
i
=
0
,
size
=
constraints
.
size
();
i
<
size
;
i
++)
{
Constraint
constraint
=
constraints
.
get
(
i
);
Constraint
constraint
=
constraints
.
get
(
i
);
HashSet
<
Column
>
columns
=
constraint
.
getReferencedColumns
(
this
);
HashSet
<
Column
>
columns
=
constraint
.
getReferencedColumns
(
this
);
...
@@ -558,9 +558,11 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -558,9 +558,11 @@ public abstract class Table extends SchemaObjectBase {
}
}
}
}
}
}
ArrayList
<
Index
>
indexesToDrop
=
New
.
arrayList
();
}
HashSet
<
Index
>
indexesToDrop
=
New
.
hashSet
();
ArrayList
<
Index
>
indexes
=
getIndexes
();
ArrayList
<
Index
>
indexes
=
getIndexes
();
if
(
indexes
!=
null
)
{
if
(
indexes
!=
null
)
{
for
(
Column
col
:
columsToDrop
)
{
for
(
int
i
=
0
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
for
(
int
i
=
0
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
Index
index
=
indexes
.
get
(
i
);
if
(
index
.
getCreateSQL
()
==
null
)
{
if
(
index
.
getCreateSQL
()
==
null
)
{
...
@@ -577,6 +579,7 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -577,6 +579,7 @@ public abstract class Table extends SchemaObjectBase {
}
}
}
}
}
}
}
for
(
Constraint
c
:
constraintsToDrop
)
{
for
(
Constraint
c
:
constraintsToDrop
)
{
session
.
getDatabase
().
removeSchemaObject
(
session
,
c
);
session
.
getDatabase
().
removeSchemaObject
(
session
,
c
);
}
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
507d02d0
...
@@ -325,11 +325,6 @@ java org.h2.test.TestAll timer
...
@@ -325,11 +325,6 @@ java org.h2.test.TestAll timer
*/
*/
public
boolean
splitFileSystem
;
public
boolean
splitFileSystem
;
/**
* Support nested joins.
*/
public
boolean
nestedJoins
;
/**
/**
* If only fast tests should be run. If enabled, SSL is not tested.
* If only fast tests should be run. If enabled, SSL is not tested.
*/
*/
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
507d02d0
...
@@ -323,9 +323,6 @@ public abstract class TestBase {
...
@@ -323,9 +323,6 @@ public abstract class TestBase {
if
(
config
.
defrag
)
{
if
(
config
.
defrag
)
{
url
=
addOption
(
url
,
"DEFRAG_ALWAYS"
,
"TRUE"
);
url
=
addOption
(
url
,
"DEFRAG_ALWAYS"
,
"TRUE"
);
}
}
if
(
config
.
nestedJoins
)
{
url
=
addOption
(
url
,
"NESTED_JOINS"
,
"TRUE"
);
}
return
"jdbc:h2:"
+
url
;
return
"jdbc:h2:"
+
url
;
}
}
...
...
h2/src/test/org/h2/test/db/TestAlter.java
浏览文件 @
507d02d0
...
@@ -10,7 +10,6 @@ import java.sql.DatabaseMetaData;
...
@@ -10,7 +10,6 @@ import java.sql.DatabaseMetaData;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
...
@@ -38,6 +37,7 @@ public class TestAlter extends TestBase {
...
@@ -38,6 +37,7 @@ public class TestAlter extends TestBase {
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
testAlterTableAlterColumnAsSelfColumn
();
testAlterTableAlterColumnAsSelfColumn
();
testAlterTableDropColumnWithReferences
();
testAlterTableDropColumnWithReferences
();
testAlterTableDropMultipleColumns
();
testAlterTableAlterColumnWithConstraint
();
testAlterTableAlterColumnWithConstraint
();
testAlterTableAlterColumn
();
testAlterTableAlterColumn
();
testAlterTableAddColumnIdentity
();
testAlterTableAddColumnIdentity
();
...
@@ -108,6 +108,17 @@ public class TestAlter extends TestBase {
...
@@ -108,6 +108,17 @@ public class TestAlter extends TestBase {
}
}
private
void
testAlterTableDropMultipleColumns
()
throws
SQLException
{
stat
.
execute
(
"create table test(id int, name varchar, name2 varchar)"
);
stat
.
execute
(
"alter table test drop column name, name2"
);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"create table test(id int, name varchar, name2 varchar)"
);
assertThrows
(
ErrorCode
.
CANNOT_DROP_LAST_COLUMN
,
stat
).
execute
(
"alter table test drop column id, name, name2"
);
stat
.
execute
(
"drop table test"
);
}
/**
/**
* Tests a bug we used to have where altering the name of a column that had
* Tests a bug we used to have where altering the name of a column that had
* a check constraint that referenced itself would result in not being able
* a check constraint that referenced itself would result in not being able
...
...
h2/src/test/org/h2/test/synth/TestLimit.java
浏览文件 @
507d02d0
...
@@ -25,7 +25,6 @@ public class TestLimit extends TestBase {
...
@@ -25,7 +25,6 @@ public class TestLimit extends TestBase {
public
static
void
main
(
String
...
a
)
throws
Exception
{
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
test
=
TestBase
.
createCaller
().
init
();
TestBase
test
=
TestBase
.
createCaller
().
init
();
// test.config.traceTest = true;
// test.config.traceTest = true;
test
.
config
.
nestedJoins
=
true
;
test
.
test
();
test
.
test
();
}
}
...
...
h2/src/test/org/h2/test/synth/TestNestedJoins.java
浏览文件 @
507d02d0
...
@@ -36,15 +36,11 @@ public class TestNestedJoins extends TestBase {
...
@@ -36,15 +36,11 @@ public class TestNestedJoins extends TestBase {
public
static
void
main
(
String
...
a
)
throws
Exception
{
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
test
=
TestBase
.
createCaller
().
init
();
TestBase
test
=
TestBase
.
createCaller
().
init
();
// test.config.traceTest = true;
// test.config.traceTest = true;
test
.
config
.
nestedJoins
=
true
;
test
.
test
();
test
.
test
();
}
}
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(!
config
.
nestedJoins
)
{
return
;
}
deleteDb
(
"nestedJoins"
);
deleteDb
(
"nestedJoins"
);
// testCases2();
// testCases2();
testCases
();
testCases
();
...
...
h2/src/test/org/h2/test/synth/TestOuterJoins.java
浏览文件 @
507d02d0
...
@@ -35,15 +35,11 @@ public class TestOuterJoins extends TestBase {
...
@@ -35,15 +35,11 @@ public class TestOuterJoins extends TestBase {
public
static
void
main
(
String
...
a
)
throws
Exception
{
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
test
=
TestBase
.
createCaller
().
init
();
TestBase
test
=
TestBase
.
createCaller
().
init
();
test
.
config
.
traceTest
=
true
;
test
.
config
.
traceTest
=
true
;
test
.
config
.
nestedJoins
=
true
;
test
.
test
();
test
.
test
();
}
}
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(!
config
.
nestedJoins
)
{
return
;
}
deleteDb
(
"outerJoins"
);
deleteDb
(
"outerJoins"
);
testCases
();
testCases
();
testRandom
();
testRandom
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论