Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
237dda41
提交
237dda41
authored
3月 15, 2017
作者:
Sergey Kalashnikov
提交者:
Sergi Vladykin
3月 15, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added support for invisible columns (like in Oracle) (#464)
上级
237bbf86
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
132 行增加
和
5 行删除
+132
-5
help.csv
h2/src/docsrc/help/help.csv
+13
-2
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
CommandInterface.java
h2/src/main/org/h2/command/CommandInterface.java
+5
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+13
-0
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+17
-0
Select.java
h2/src/main/org/h2/command/dml/Select.java
+3
-0
help.csv
h2/src/main/org/h2/res/help.csv
+4
-2
Column.java
h2/src/main/org/h2/table/Column.java
+15
-0
testScript.sql
h2/src/test/org/h2/test/testScript.sql
+59
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
237dda41
...
...
@@ -258,13 +258,14 @@ ALTER TABLE TEST RENAME CONSTRAINT FOO TO BAR
"Commands (DDL)","ALTER TABLE ALTER COLUMN","
ALTER TABLE [ IF EXISTS ] tableName ALTER COLUMN columnName
{ { dataType [ DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
{ { dataType [
VISIBLE | INVISIBLE ] [
DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
| { RENAME TO name }
| { RESTART WITH long }
| { SELECTIVITY int }
| { SET DEFAULT expression }
| { SET NULL }
| { SET NOT NULL } }
| { SET NOT NULL }
| { SET { VISIBLE | INVISIBLE } } }
","
Changes the data type of a column, rename a column,
change the identity value, or change the selectivity.
...
...
@@ -287,6 +288,9 @@ Single column indexes on this column are dropped.
SET NOT NULL sets a column to not allow NULL. Rows may not contains NULL in this column.
SET INVISIBLE makes the column hidden, i.e. it will not appear in SELECT * results.
SET VISIBLE has the reverse effect.
This command commits an open transaction in this connection.
","
ALTER TABLE TEST ALTER COLUMN NAME CLOB;
...
...
@@ -296,6 +300,8 @@ ALTER TABLE TEST ALTER COLUMN NAME SELECTIVITY 100;
ALTER TABLE TEST ALTER COLUMN NAME SET DEFAULT '';
ALTER TABLE TEST ALTER COLUMN NAME SET NOT NULL;
ALTER TABLE TEST ALTER COLUMN NAME SET NULL;
ALTER TABLE TEST ALTER COLUMN NAME SET VISIBLE;
ALTER TABLE TEST ALTER COLUMN NAME SET INVISIBLE;
"
"Commands (DDL)","ALTER TABLE DROP COLUMN","
...
...
@@ -1759,6 +1765,7 @@ AES
"Other Grammar","Column Definition","
columnName dataType
[ VISIBLE | INVISIBLE ]
[ { DEFAULT expression | AS computedColumnExpression } ] [ [ NOT ] NULL ]
[ { AUTO_INCREMENT | IDENTITY } [ ( startInt [, incrementInt ] ) ] ]
[ SELECTIVITY selectivity ] [ COMMENT expression ]
...
...
@@ -1771,12 +1778,16 @@ Identity and auto-increment columns are columns with a sequence as the
default. The column declared as the identity columns is implicitly the
primary key column of this table (unlike auto-increment columns).
The invisible column will not be displayed as a result of SELECT * query.
Otherwise, it works as normal column.
The options PRIMARY KEY, UNIQUE, and CHECK are not supported for ALTER statements.
Check constraints can reference columns of the table,
and they can reference objects that exist while the statement is executed.
Conditions are only checked when a row is added or modified
in the table where the constraint exists.
","
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255) DEFAULT '');
CREATE TABLE TEST(ID BIGINT IDENTITY);
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
237dda41
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Added support for invisible columns.
</li>
</ul>
<h2>
Version 1.4.194 (2017-03-10)
</h2>
...
...
h2/src/main/org/h2/command/CommandInterface.java
浏览文件 @
237dda41
...
...
@@ -461,6 +461,11 @@ public interface CommandInterface {
*/
int
EXPLAIN_ANALYZE
=
86
;
/**
* The type of a ALTER TABLE ALTER COLUMN SET INVISIBLE statement.
*/
int
ALTER_TABLE_ALTER_COLUMN_VISIBILITY
=
87
;
/**
* Get command type.
*
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
237dda41
...
...
@@ -3993,6 +3993,11 @@ public class Parser {
}
else
{
column
=
parseColumnWithType
(
columnName
);
}
if
(
readIf
(
"INVISIBLE"
))
{
column
.
setVisible
(
false
);
}
else
if
(
readIf
(
"VISIBLE"
))
{
column
.
setVisible
(
true
);
}
if
(
readIf
(
"NOT"
))
{
read
(
"NULL"
);
column
.
setNullable
(
false
);
...
...
@@ -5718,6 +5723,14 @@ public class Parser {
command
.
setType
(
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_DEFAULT
);
command
.
setDefaultExpression
(
defaultExpression
);
return
command
;
}
else
if
(
readIf
(
"INVISIBLE"
))
{
command
.
setType
(
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_VISIBILITY
);
command
.
setVisible
(
false
);
return
command
;
}
else
if
(
readIf
(
"VISIBLE"
))
{
command
.
setType
(
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_VISIBILITY
);
command
.
setVisible
(
true
);
return
command
;
}
}
else
if
(
readIf
(
"RESTART"
))
{
readIf
(
"WITH"
);
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
237dda41
...
...
@@ -44,6 +44,8 @@ import org.h2.util.New;
* ALTER TABLE ALTER COLUMN SET DEFAULT,
* ALTER TABLE ALTER COLUMN SET NOT NULL,
* ALTER TABLE ALTER COLUMN SET NULL,
* ALTER TABLE ALTER COLUMN SET VISIBLE,
* ALTER TABLE ALTER COLUMN SET INVISIBLE,
* ALTER TABLE DROP COLUMN
*/
public
class
AlterTableAlterColumn
extends
SchemaCommand
{
...
...
@@ -60,6 +62,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private
boolean
ifNotExists
;
private
ArrayList
<
Column
>
columnsToAdd
;
private
ArrayList
<
Column
>
columnsToRemove
;
private
boolean
newVisibility
;
public
AlterTableAlterColumn
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
...
...
@@ -156,9 +159,13 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
else
if
(!
oldColumn
.
isNullable
()
&&
newColumn
.
isNullable
())
{
checkNullable
(
table
);
}
if
(
oldColumn
.
getVisible
()
^
newColumn
.
getVisible
())
{
oldColumn
.
setVisible
(
newColumn
.
getVisible
());
}
convertAutoIncrementColumn
(
table
,
newColumn
);
copyData
(
table
);
}
table
.
setModified
();
break
;
}
case
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
:
{
...
...
@@ -192,6 +199,12 @@ public class AlterTableAlterColumn extends SchemaCommand {
db
.
updateMeta
(
session
,
table
);
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_VISIBILITY
:
{
oldColumn
.
setVisible
(
newVisibility
);
table
.
setModified
();
db
.
updateMeta
(
session
,
table
);
break
;
}
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
}
...
...
@@ -550,4 +563,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
public
void
setColumnsToRemove
(
ArrayList
<
Column
>
columnsToRemove
)
{
this
.
columnsToRemove
=
columnsToRemove
;
}
public
void
setVisible
(
boolean
visible
)
{
this
.
newVisibility
=
visible
;
}
}
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
237dda41
...
...
@@ -731,6 +731,9 @@ public class Select extends Query {
String
alias
=
filter
.
getTableAlias
();
Column
[]
columns
=
t
.
getColumns
();
for
(
Column
c
:
columns
)
{
if
(!
c
.
getVisible
())
{
continue
;
}
if
(
filter
.
isNaturalJoinColumn
(
c
))
{
continue
;
}
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
237dda41
...
...
@@ -98,13 +98,14 @@ ALTER TABLE [ IF EXISTS ] tableName RENAME oldConstraintName TO newConstraintNam
Renames a constraint."
"Commands (DDL)","ALTER TABLE ALTER COLUMN","
ALTER TABLE [ IF EXISTS ] tableName ALTER COLUMN columnName
{ { dataType [ DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
{ { dataType [
VISIBLE | INVISIBLE ] [
DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
| { RENAME TO name }
| { RESTART WITH long }
| { SELECTIVITY int }
| { SET DEFAULT expression }
| { SET NULL }
| { SET NOT NULL } }
| { SET NOT NULL }
| { SET { VISIBLE | INVISIBLE } } }
","
Changes the data type of a column, rename a column,
change the identity value, or change the selectivity."
...
...
@@ -555,6 +556,7 @@ AES
Only the algorithm AES (""AES-128"") is supported currently."
"Other Grammar","Column Definition","
columnName dataType
[ VISIBLE | INVISIBLE ]
[ { DEFAULT expression | AS computedColumnExpression } ] [ [ NOT ] NULL ]
[ { AUTO_INCREMENT | IDENTITY } [ ( startInt [, incrementInt ] ) ] ]
[ SELECTIVITY selectivity ] [ COMMENT expression ]
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
237dda41
...
...
@@ -86,6 +86,7 @@ public class Column {
private
SingleColumnResolver
resolver
;
private
String
comment
;
private
boolean
primaryKey
;
private
boolean
visible
=
true
;
public
Column
(
String
name
,
int
type
)
{
this
(
name
,
type
,
-
1
,
-
1
,
-
1
);
...
...
@@ -257,6 +258,14 @@ public class Column {
nullable
=
b
;
}
public
boolean
getVisible
()
{
return
visible
;
}
public
void
setVisible
(
boolean
b
)
{
visible
=
b
;
}
/**
* Validate the value, convert it if required, and update the sequence value
* if required. If the value is null, the default value (NULL if no default
...
...
@@ -436,6 +445,11 @@ public class Column {
default
:
}
}
if
(!
visible
)
{
buff
.
append
(
" INVISIBLE "
);
}
if
(
defaultExpression
!=
null
)
{
String
sql
=
defaultExpression
.
getSQL
();
if
(
sql
!=
null
)
{
...
...
@@ -748,6 +762,7 @@ public class Column {
isComputed
=
source
.
isComputed
;
selectivity
=
source
.
selectivity
;
primaryKey
=
source
.
primaryKey
;
visible
=
source
.
visible
;
}
}
h2/src/test/org/h2/test/testScript.sql
浏览文件 @
237dda41
...
...
@@ -4915,6 +4915,22 @@ SELECT group_concat(name) FROM TEST group by id;
drop table test;
> ok
create table test(a int primary key, b int invisible, c int);
> ok
select * from test;
> A C
> - -
> rows: 0
select a, b, c from test;
> A B C
> - - -
> rows: 0
drop table test;
> ok
--- script drop ---------------------------------------------------------------------------------------------
create memory table test (id int primary key, im_ie varchar(10));
> ok
...
...
@@ -6183,6 +6199,49 @@ SELECT * FROM TEST;
DROP TABLE TEST;
> ok
create table test(id int, name varchar invisible);
> ok
select * from test;
> ID
> --
> rows: 0
alter table test alter column name set visible;
> ok
select * from test;
> ID NAME
> -- ----
> rows: 0
alter table test add modify_date timestamp invisible before name;
> ok
select * from test;
> ID NAME
> -- ----
> rows: 0
alter table test alter column modify_date timestamp visible;
> ok
select * from test;
> ID MODIFY_DATE NAME
> -- ----------- ----
> rows: 0
alter table test alter column modify_date set invisible;
> ok
select * from test;
> ID NAME
> -- ----
> rows: 0
drop table test;
> ok
--- autoIncrement ----------------------------------------------------------------------------------------------
CREATE MEMORY TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR);
> ok
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
237dda41
...
...
@@ -697,7 +697,7 @@ vast vector vectors vendor venue verbatim verbose verification verified verifier
verifies verify verifying versa version versioned versioning versions versus
vertica vertical very verysmallint veto via vice victor videos view viewed viewer
viewport views vii viii violate violated violation violations virtual virus
viruses visible vision visit visited visitor visitors vista visual visualize
viruses visible visi
bility visi
on visit visited visitor visitors vista visual visualize
visualizer vividsolutions vladykin void volatile volume volunteer volunteers von
vpda vulnerabilities vulnerability wait waited waiting waits waives wake wakes
walk walker want wants war warehouse warehouses warn warned warning warnings
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论