Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
18ef6e09
提交
18ef6e09
authored
10月 15, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added standard column namer
上级
1b67892f
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
81 行增加
和
58 行删除
+81
-58
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+1
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-1
SelectListColumnResolver.java
h2/src/main/org/h2/command/dml/SelectListColumnResolver.java
+3
-5
SelectUnion.java
h2/src/main/org/h2/command/dml/SelectUnion.java
+1
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+1
-3
ColumnNamer.java
h2/src/main/org/h2/util/ColumnNamer.java
+74
-47
没有找到文件。
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
18ef6e09
...
@@ -234,7 +234,7 @@ public class CreateTable extends SchemaCommand {
...
@@ -234,7 +234,7 @@ public class CreateTable extends SchemaCommand {
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
Expression
expr
=
expressions
.
get
(
i
);
Expression
expr
=
expressions
.
get
(
i
);
int
type
=
expr
.
getType
();
int
type
=
expr
.
getType
();
String
name
=
ColumnNamer
.
getColumnName
(
expr
,
i
,
null
);
String
name
=
ColumnNamer
.
getColumnName
(
expr
,
i
);
long
precision
=
expr
.
getPrecision
();
long
precision
=
expr
.
getPrecision
();
int
displaySize
=
expr
.
getDisplaySize
();
int
displaySize
=
expr
.
getDisplaySize
();
DataType
dt
=
DataType
.
getDataType
(
type
);
DataType
dt
=
DataType
.
getDataType
(
type
);
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
18ef6e09
...
@@ -842,8 +842,8 @@ public class Select extends Query {
...
@@ -842,8 +842,8 @@ public class Select extends Query {
}
}
for
(
int
i
=
0
;
i
<
expressions
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
expressions
.
size
();
i
++)
{
Expression
e
=
expressions
.
get
(
i
);
Expression
e
=
expressions
.
get
(
i
);
String
columnName
=
ColumnNamer
.
getColumnName
(
e
,
i
,
null
);
if
(!
ColumnNamer
.
isAllowableColumnName
(
e
.
getAlias
())){
if
(!
ColumnNamer
.
isAllowableColumnName
(
e
.
getAlias
())){
String
columnName
=
ColumnNamer
.
getColumnName
(
e
,
i
);
e
=
new
Alias
(
e
,
columnName
,
true
);
e
=
new
Alias
(
e
,
columnName
,
true
);
}
}
expressions
.
set
(
i
,
e
.
optimize
(
session
));
expressions
.
set
(
i
,
e
.
optimize
(
session
));
...
...
h2/src/main/org/h2/command/dml/SelectListColumnResolver.java
浏览文件 @
18ef6e09
...
@@ -11,6 +11,7 @@ import org.h2.expression.ExpressionColumn;
...
@@ -11,6 +11,7 @@ import org.h2.expression.ExpressionColumn;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.ColumnNamer
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
/**
/**
...
@@ -37,11 +38,8 @@ public class SelectListColumnResolver implements ColumnResolver {
...
@@ -37,11 +38,8 @@ public class SelectListColumnResolver implements ColumnResolver {
ArrayList
<
Expression
>
columnList
=
select
.
getExpressions
();
ArrayList
<
Expression
>
columnList
=
select
.
getExpressions
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
Expression
expr
=
columnList
.
get
(
i
);
Expression
expr
=
columnList
.
get
(
i
);
String
columnName
=
expr
.
getAlias
();
String
columnName
=
ColumnNamer
.
getColumnName
(
expr
,
i
);
if
(
columnName
==
null
){
Column
column
=
new
Column
(
columnName
,
Value
.
NULL
);
columnName
=
"_col_"
+(
i
+
1
);
}
Column
column
=
new
Column
(
expr
.
getAlias
(),
Value
.
NULL
);
column
.
setTable
(
null
,
i
);
column
.
setTable
(
null
,
i
);
columns
[
i
]
=
column
;
columns
[
i
]
=
column
;
expressions
[
i
]
=
expr
.
getNonAliasExpression
();
expressions
[
i
]
=
expr
.
getNonAliasExpression
();
...
...
h2/src/main/org/h2/command/dml/SelectUnion.java
浏览文件 @
18ef6e09
...
@@ -337,7 +337,7 @@ public class SelectUnion extends Query {
...
@@ -337,7 +337,7 @@ public class SelectUnion extends Query {
long
prec
=
Math
.
max
(
l
.
getPrecision
(),
r
.
getPrecision
());
long
prec
=
Math
.
max
(
l
.
getPrecision
(),
r
.
getPrecision
());
int
scale
=
Math
.
max
(
l
.
getScale
(),
r
.
getScale
());
int
scale
=
Math
.
max
(
l
.
getScale
(),
r
.
getScale
());
int
displaySize
=
Math
.
max
(
l
.
getDisplaySize
(),
r
.
getDisplaySize
());
int
displaySize
=
Math
.
max
(
l
.
getDisplaySize
(),
r
.
getDisplaySize
());
String
columnName
=
ColumnNamer
.
getColumnName
(
l
,
i
,
null
);
String
columnName
=
ColumnNamer
.
getColumnName
(
l
,
i
);
Column
col
=
new
Column
(
columnName
,
type
,
prec
,
scale
,
displaySize
);
Column
col
=
new
Column
(
columnName
,
type
,
prec
,
scale
,
displaySize
);
Expression
e
=
new
ExpressionColumn
(
session
.
getDatabase
(),
col
);
Expression
e
=
new
ExpressionColumn
(
session
.
getDatabase
(),
col
);
expressions
.
add
(
e
);
expressions
.
add
(
e
);
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
18ef6e09
...
@@ -168,9 +168,7 @@ public class TableView extends Table {
...
@@ -168,9 +168,7 @@ public class TableView extends Table {
name
=
columnTemplates
[
i
].
getName
();
name
=
columnTemplates
[
i
].
getName
();
type
=
columnTemplates
[
i
].
getType
();
type
=
columnTemplates
[
i
].
getType
();
}
}
if
(
name
==
null
)
{
name
=
ColumnNamer
.
getColumnName
(
expr
,
i
,
name
);
name
=
ColumnNamer
.
getColumnName
(
expr
,
i
,
null
);
}
if
(
type
==
Value
.
UNKNOWN
)
{
if
(
type
==
Value
.
UNKNOWN
)
{
type
=
expr
.
getType
();
type
=
expr
.
getType
();
}
}
...
...
h2/src/main/org/h2/util/ColumnNamer.java
浏览文件 @
18ef6e09
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.util.regex.Matcher
;
import
org.h2.expression.Expression
;
import
java.util.regex.Pattern
;
import
org.h2.expression.Expression
;
public
class
ColumnNamer
{
public
class
ColumnNamer
{
/**
* Create a standardized column name that isn't null or and doesn't have a CR/LF in it.
public
static
String
getColumnName
(
Expression
columnExp
,
int
indexOfColumn
,
String
[]
columnNameOverides
){
* @param columnExp the column expression
String
columnName
=
null
;
* @param indexOfColumn index of column in below array
if
(
columnNameOverides
!=
null
&&
columnNameOverides
.
length
>
indexOfColumn
){
* @return
columnName
=
columnNameOverides
[
indexOfColumn
];
*/
}
public
static
String
getColumnName
(
Expression
expr
,
int
indexOfColumn
)
{
if
(
columnName
==
null
&&
columnExp
.
getAlias
()!=
null
){
return
getColumnName
(
expr
,
indexOfColumn
,(
String
)
null
);
columnName
=
columnExp
.
getAlias
();
}
if
(!
isAllowableColumnName
(
columnName
)){
/**
columnName
=
null
;
* Create a standardized column name that isn't null or and doesn't have a CR/LF in it.
}
* @param columnExp the column expression
}
* @param indexOfColumn index of column in below array
if
(
columnName
==
null
&&
columnExp
.
getColumnName
()!=
null
){
* @param columnNameOverides array of overriding column names
columnName
=
columnExp
.
getColumnName
();
* @return the new column name
if
(!
isAllowableColumnName
(
columnName
)){
*/
columnName
=
columnName
.
replace
(
'\n'
,
' '
).
replace
(
'\r'
,
' '
);
public
static
String
getColumnName
(
Expression
columnExp
,
int
indexOfColumn
,
String
[]
columnNameOverides
){
}
String
columnNameOverride
=
null
;
if
(!
isAllowableColumnName
(
columnName
)){
if
(
columnNameOverides
!=
null
&&
columnNameOverides
.
length
>
indexOfColumn
){
columnName
=
null
;
columnNameOverride
=
columnNameOverides
[
indexOfColumn
];
}
}
}
return
getColumnName
(
columnExp
,
indexOfColumn
,
columnNameOverride
);
if
(
columnName
==
null
){
}
columnName
=
"_unnamed_column_"
+(
indexOfColumn
+
1
)+
"_"
;
}
/**
return
columnName
;
* Create a standardized column name that isn't null or and doesn't have a CR/LF in it.
}
* @param columnExp the column expression
* @param indexOfColumn index of column in below array
//private static final Pattern reasonableNameCharactersPatternRE = Pattern.compile("[a-zA-Z0-9_'\\(\\)\\*,\\.\\+\\-\\*/:=\\<\\>!\\|@ \\t\\?\"\\$]*");
* @param columnNameOverride single overriding column name
* @return the new column name
public
static
boolean
isAllowableColumnName
(
String
proposedName
){
*/
if
(
proposedName
==
null
){
public
static
String
getColumnName
(
Expression
columnExp
,
int
indexOfColumn
,
String
columnNameOverride
)
{
return
false
;
String
columnName
=
null
;
}
if
(
columnNameOverride
!=
null
){
if
(
proposedName
.
contains
(
"\n"
)
||
proposedName
.
contains
(
"\r"
)){
columnName
=
columnNameOverride
;
return
false
;
}
}
if
(
columnName
==
null
&&
columnExp
.
getAlias
()!=
null
){
return
true
;
columnName
=
columnExp
.
getAlias
();
}
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
null
;
}
}
}
if
(
columnName
==
null
&&
columnExp
.
getColumnName
()!=
null
){
columnName
=
columnExp
.
getColumnName
();
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
columnName
.
replace
(
'\n'
,
' '
).
replace
(
'\r'
,
' '
);
}
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
null
;
}
}
if
(
columnName
==
null
){
columnName
=
"_unnamed_column_"
+(
indexOfColumn
+
1
)+
"_"
;
}
return
columnName
;
}
public
static
boolean
isAllowableColumnName
(
String
proposedName
){
if
(
proposedName
==
null
){
return
false
;
}
if
(
proposedName
.
contains
(
"\n"
)
||
proposedName
.
contains
(
"\r"
)){
return
false
;
}
return
true
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论