Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7c9d6bad
Unverified
提交
7c9d6bad
authored
11月 04, 2017
作者:
Noel Grandin
提交者:
GitHub
11月 04, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #661 from plus33/master
Support drop-columns using brackets (Oracle syntax style)
上级
6a205da9
eab3251b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
51 行增加
和
6 行删除
+51
-6
Parser.java
h2/src/main/org/h2/command/Parser.java
+19
-1
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+13
-3
TestCompatibilityOracle.java
h2/src/test/org/h2/test/db/TestCompatibilityOracle.java
+19
-2
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
7c9d6bad
...
...
@@ -3486,6 +3486,20 @@ public class Parser {
addExpected
(
token
);
return
false
;
}
/*
* Reads passed token in list, in order and returns true on first match.
* If none of the token matches returns false
*/
private
boolean
readIfOr
(
String
...
tokens
)
{
for
(
String
token:
tokens
)
{
if
(
readIf
(
token
))
{
return
true
;
}
}
return
false
;
}
/*
* Reads every token in list, in order - returns true if all are found.
* If any are not found, returns false - AND resets parsing back to state when called.
...
...
@@ -4466,7 +4480,7 @@ public class Parser {
}
original
+=
"("
+
p
;
// Oracle syntax
readIf
(
"CHAR
"
);
readIf
Or
(
"CHAR"
,
"BYTE
"
);
if
(
dataType
.
supportsScale
)
{
if
(
readIf
(
","
))
{
scale
=
readInt
();
...
...
@@ -6073,6 +6087,7 @@ public class Parser {
command
.
setType
(
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
);
ArrayList
<
Column
>
columnsToRemove
=
New
.
arrayList
();
Table
table
=
tableIfTableExists
(
schema
,
tableName
,
ifTableExists
);
boolean
openingBracketDetected
=
readIf
(
"("
);
// For Oracle compatibility - open bracket required
do
{
String
columnName
=
readColumnIdentifier
();
if
(
table
==
null
)
{
...
...
@@ -6084,6 +6099,9 @@ public class Parser {
Column
column
=
table
.
getColumn
(
columnName
);
columnsToRemove
.
add
(
column
);
}
while
(
readIf
(
","
));
if
(
openingBracketDetected
)
{
read
(
")"
);
// For Oracle compatibility - close bracket
}
command
.
setTableName
(
tableName
);
command
.
setIfTableExists
(
ifTableExists
);
command
.
setColumnsToRemove
(
columnsToRemove
);
...
...
h2/src/test/org/h2/test/db/TestAlter.java
浏览文件 @
7c9d6bad
...
...
@@ -113,10 +113,18 @@ 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
(
"create table test(id int, b varchar, c int, d int)"
);
stat
.
execute
(
"alter table test drop column b, c"
);
stat
.
execute
(
"alter table test drop d"
);
stat
.
execute
(
"drop table test"
);
// Test-Case: Same as above but using brackets (Oracle style)
stat
.
execute
(
"create table test(id int, b varchar, c int, d int)"
);
stat
.
execute
(
"alter table test drop column (b, c)"
);
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
stat
).
execute
(
"alter table test drop column b"
);
stat
.
execute
(
"alter table test drop (d)"
);
stat
.
execute
(
"drop table test"
);
// Test-Case: Error if dropping all columns
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"
);
...
...
@@ -209,6 +217,8 @@ public class TestAlter extends TestBase {
stat
.
execute
(
"drop table t"
);
}
// column and field names must be upper-case due to getMetaData sensitivity
private
void
testAlterTableAddMultipleColumnsBefore
()
throws
SQLException
{
stat
.
execute
(
"create table T(X varchar)"
);
...
...
h2/src/test/org/h2/test/db/TestCompatibilityOracle.java
浏览文件 @
7c9d6bad
...
...
@@ -40,6 +40,7 @@ public class TestCompatibilityOracle extends TestBase {
testPoundSymbolInColumnName
();
testToDate
();
testForbidEmptyInClause
();
testSpecialTypes
();
}
private
void
testNotNullSyntax
()
throws
SQLException
{
...
...
@@ -86,12 +87,28 @@ public class TestCompatibilityOracle extends TestBase {
conn
.
close
();
}
private
void
testSpecialTypes
()
throws
SQLException
{
// Test VARCHAR, VARCHAR2 with CHAR and BYTE
deleteDb
(
"oracle"
);
Connection
conn
=
getConnection
(
"oracle;MODE=Oracle"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table T (ID NUMBER)"
);
stat
.
execute
(
"alter table T add A_1 VARCHAR(1)"
);
stat
.
execute
(
"alter table T add A_2 VARCHAR2(1)"
);
stat
.
execute
(
"alter table T add B_1 VARCHAR(1 byte)"
);
// with BYTE
stat
.
execute
(
"alter table T add B_2 VARCHAR2(1 byte)"
);
stat
.
execute
(
"alter table T add C_1 VARCHAR(1 char)"
);
// with CHAR
stat
.
execute
(
"alter table T add C_2 VARCHAR2(1 char)"
);
stat
.
execute
(
"alter table T add B_255 VARCHAR(255 byte)"
);
stat
.
execute
(
"alter table T add C_255 VARCHAR(255 char)"
);
stat
.
execute
(
"drop table T"
);
conn
.
close
();
}
private
void
testTreatEmptyStringsAsNull
()
throws
SQLException
{
deleteDb
(
"oracle"
);
Connection
conn
=
getConnection
(
"oracle;MODE=Oracle"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE A (ID NUMBER, X VARCHAR2(1))"
);
stat
.
execute
(
"INSERT INTO A VALUES (1, 'a')"
);
stat
.
execute
(
"INSERT INTO A VALUES (2, '')"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论