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