Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5ab7b5ae
提交
5ab7b5ae
authored
10月 20, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added default naming rules
上级
8565a071
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
126 行增加
和
18 行删除
+126
-18
Set.java
h2/src/main/org/h2/command/dml/Set.java
+11
-0
SetTypes.java
h2/src/main/org/h2/command/dml/SetTypes.java
+7
-0
Session.java
h2/src/main/org/h2/engine/Session.java
+2
-2
ColumnNamer.java
h2/src/main/org/h2/util/ColumnNamer.java
+106
-16
没有找到文件。
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
5ab7b5ae
...
@@ -23,6 +23,7 @@ import org.h2.result.RowFactory;
...
@@ -23,6 +23,7 @@ import org.h2.result.RowFactory;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.CompressTool
;
import
org.h2.util.ColumnNamer
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.CompareMode
;
import
org.h2.value.CompareMode
;
...
@@ -534,6 +535,16 @@ public class Set extends Prepared {
...
@@ -534,6 +535,16 @@ public class Set extends Prepared {
database
.
setAllowBuiltinAliasOverride
(
value
==
1
);
database
.
setAllowBuiltinAliasOverride
(
value
==
1
);
break
;
break
;
}
}
case
SetTypes
.
COLUMN_NAME_RULES
:
{
session
.
getUser
().
checkAdmin
();
System
.
out
.
println
(
"1"
+
stringValue
);
System
.
out
.
println
(
"2"
+
expression
.
getColumnName
());
System
.
out
.
println
(
"3"
+
expression
.
getSQL
());
ColumnNamer
.
configure
(
expression
.
getColumnName
());
break
;
}
default
:
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
DbException
.
throwInternalError
(
"type="
+
type
);
}
}
...
...
h2/src/main/org/h2/command/dml/SetTypes.java
浏览文件 @
5ab7b5ae
...
@@ -247,6 +247,11 @@ public class SetTypes {
...
@@ -247,6 +247,11 @@ public class SetTypes {
* The type of SET BUILTIN_ALIAS_OVERRIDE statement.
* The type of SET BUILTIN_ALIAS_OVERRIDE statement.
*/
*/
public
static
final
int
BUILTIN_ALIAS_OVERRIDE
=
47
;
public
static
final
int
BUILTIN_ALIAS_OVERRIDE
=
47
;
/**
* The type of a SET COLUMN_NAME_RULES statement.
*/
public
static
final
int
COLUMN_NAME_RULES
=
48
;
private
static
final
ArrayList
<
String
>
TYPES
=
New
.
arrayList
();
private
static
final
ArrayList
<
String
>
TYPES
=
New
.
arrayList
();
...
@@ -304,6 +309,8 @@ public class SetTypes {
...
@@ -304,6 +309,8 @@ public class SetTypes {
list
.
add
(
FORCE_JOIN_ORDER
,
"FORCE_JOIN_ORDER"
);
list
.
add
(
FORCE_JOIN_ORDER
,
"FORCE_JOIN_ORDER"
);
list
.
add
(
LAZY_QUERY_EXECUTION
,
"LAZY_QUERY_EXECUTION"
);
list
.
add
(
LAZY_QUERY_EXECUTION
,
"LAZY_QUERY_EXECUTION"
);
list
.
add
(
BUILTIN_ALIAS_OVERRIDE
,
"BUILTIN_ALIAS_OVERRIDE"
);
list
.
add
(
BUILTIN_ALIAS_OVERRIDE
,
"BUILTIN_ALIAS_OVERRIDE"
);
list
.
add
(
COLUMN_NAME_RULES
,
"COLUMN_NAME_RULES"
);
}
}
/**
/**
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
5ab7b5ae
...
@@ -374,7 +374,7 @@ public class Session extends SessionWithState {
...
@@ -374,7 +374,7 @@ public class Session extends SessionWithState {
*/
*/
public
void
removeLocalTempTable
(
Table
table
)
{
public
void
removeLocalTempTable
(
Table
table
)
{
// Exception thrown in org.h2.engine.Database.removeMeta if line below is missing with TestGeneralCommonTableQueries
// Exception thrown in org.h2.engine.Database.removeMeta if line below is missing with TestGeneralCommonTableQueries
//
database.lockMeta(this);
database
.
lockMeta
(
this
);
modificationId
++;
modificationId
++;
localTempTables
.
remove
(
table
.
getName
());
localTempTables
.
remove
(
table
.
getName
());
synchronized
(
database
)
{
synchronized
(
database
)
{
...
@@ -977,7 +977,7 @@ public class Session extends SessionWithState {
...
@@ -977,7 +977,7 @@ public class Session extends SessionWithState {
table
.
setModified
();
table
.
setModified
();
it
.
remove
();
it
.
remove
();
// Exception thrown in org.h2.engine.Database.removeMeta if line below is missing with TestDeadlock
// Exception thrown in org.h2.engine.Database.removeMeta if line below is missing with TestDeadlock
//
database.lockMeta(this);
database
.
lockMeta
(
this
);
table
.
removeChildrenAndResources
(
this
);
table
.
removeChildrenAndResources
(
this
);
if
(
closeSession
)
{
if
(
closeSession
)
{
// need to commit, otherwise recovery might
// need to commit, otherwise recovery might
...
...
h2/src/main/org/h2/util/ColumnNamer.java
浏览文件 @
5ab7b5ae
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.PatternSyntaxException
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
public
class
ColumnNamer
{
public
class
ColumnNamer
{
private
static
final
String
DEFAULT_COLUMN_NAME
=
"DEFAULT"
;
private
static
final
String
DEFAULT_COMMAND
=
"DEFAULT"
;
private
static
final
String
REGULAR_EXPRESSION_MATCH_DISALLOWED
=
"REGULAREXPRESSIONMATCHDISALLOWED = "
;
private
static
final
String
REGULAR_EXPRESSION_MATCH_ALLOWED
=
"REGULAREXPRESSIONMATCHALLOWED = "
;
private
static
final
String
DEFAULT_COLUMN_NAME_PATTERN
=
"DEFAULTCOLUMNNAMEPATTERN = "
;
private
static
final
String
MAX_IDENTIFIER_LENGTH
=
"MAXIDENTIFIERLENGTH = "
;
/**
/**
* Create a standardized column name that isn't null and doesn't have a CR/LF in it.
* Create a standardized column name that isn't null and doesn't have a CR/LF in it.
* @param columnExp the column expression
* @param columnExp the column expression
...
@@ -40,39 +51,39 @@ public class ColumnNamer {
...
@@ -40,39 +51,39 @@ public class ColumnNamer {
String
columnName
=
null
;
String
columnName
=
null
;
if
(
columnNameOverride
!=
null
){
if
(
columnNameOverride
!=
null
){
columnName
=
columnNameOverride
;
columnName
=
columnNameOverride
;
//
if(!isAllowableColumnName(columnName)){
if
(!
isAllowableColumnName
(
columnName
)){
// columnName = columnName.replace("\n", " ").replace("\r", " "
);
columnName
=
fixColumnName
(
columnName
);
//
}
}
//
if(!isAllowableColumnName(columnName)){
if
(!
isAllowableColumnName
(
columnName
)){
//
columnName = null;
columnName
=
null
;
//
}
}
return
columnName
;
return
columnName
;
}
}
// try a name from the column alias
// try a name from the column alias
if
(
columnName
==
null
&&
columnExp
.
getAlias
()!=
null
){
if
(
columnName
==
null
&&
columnExp
.
getAlias
()!=
null
&&
!
DEFAULT_COLUMN_NAME
.
equals
(
columnExp
.
getAlias
())
){
columnName
=
columnExp
.
getAlias
();
columnName
=
columnExp
.
getAlias
();
if
(!
isAllowableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
columnName
.
replace
(
"\n"
,
" "
).
replace
(
"\r"
,
" "
);
columnName
=
fixColumnName
(
columnName
);
}
}
if
(!
isAllowableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
null
;
columnName
=
null
;
}
}
}
}
// try a name derived from the column expression SQL
// try a name derived from the column expression SQL
if
(
columnName
==
null
&&
columnExp
.
getColumnName
()!=
null
){
if
(
columnName
==
null
&&
columnExp
.
getColumnName
()!=
null
&&
!
DEFAULT_COLUMN_NAME
.
equals
(
columnExp
.
getColumnName
())
){
columnName
=
columnExp
.
getColumnName
();
columnName
=
columnExp
.
getColumnName
();
if
(!
isAllowableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
columnName
.
replace
(
"\n"
,
" "
).
replace
(
"\r"
,
" "
);
columnName
=
fixColumnName
(
columnName
);
}
}
if
(!
isAllowableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
null
;
columnName
=
null
;
}
}
}
}
// try a name derived from the column expression plan SQL
// try a name derived from the column expression plan SQL
if
(
columnName
==
null
&&
columnExp
.
getSQL
()!=
null
){
if
(
columnName
==
null
&&
columnExp
.
getSQL
()!=
null
&&
!
DEFAULT_COLUMN_NAME
.
equals
(
columnExp
.
getSQL
())
){
columnName
=
columnExp
.
getSQL
();
columnName
=
columnExp
.
getSQL
();
if
(!
isAllowableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
columnName
.
replace
(
"\n"
,
" "
).
replace
(
"\r"
,
" "
);
columnName
=
fixColumnName
(
columnName
);
}
}
if
(!
isAllowableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
null
;
columnName
=
null
;
...
@@ -80,19 +91,98 @@ public class ColumnNamer {
...
@@ -80,19 +91,98 @@ public class ColumnNamer {
}
}
// go with a innocuous default name pattern
// go with a innocuous default name pattern
if
(
columnName
==
null
){
if
(
columnName
==
null
){
columnName
=
"_unnamed_column_"
+(
indexOfColumn
+
1
)+
"_"
;
columnName
=
defaultColumnNamePattern
.
replace
(
"$$"
,
""
+(
indexOfColumn
+
1
))
;
}
}
return
columnName
;
return
columnName
;
}
}
public
static
boolean
isAllowableColumnName
(
String
proposedName
){
public
static
boolean
isAllowableColumnName
(
String
proposedName
){
// check null
if
(
proposedName
==
null
){
if
(
proposedName
==
null
){
return
false
;
return
false
;
}
}
//if(proposedName.contains("\n") || proposedName.contains("\r")){
// check size limits
// return false;
if
(
proposedName
.
length
()
>
maxIdentiferLength
||
proposedName
.
length
()==
0
){
//}
return
false
;
}
Matcher
match
=
compiledRegularExpressionMatchAllowed
.
matcher
(
proposedName
);
if
(!
match
.
matches
()){
return
false
;
}
return
true
;
return
true
;
}
}
private
static
String
fixColumnName
(
String
proposedName
)
{
Matcher
match
=
compiledRegularExpressionMatchDisallowed
.
matcher
(
proposedName
);
proposedName
=
match
.
replaceAll
(
""
);
// check size limits - then truncate
if
(
proposedName
.
length
()
>
maxIdentiferLength
){
proposedName
=
proposedName
.
substring
(
0
,
maxIdentiferLength
);
}
return
proposedName
;
}
static
int
maxIdentiferLength
=
Integer
.
MAX_VALUE
;
static
String
regularExpressionMatchAllowed
=
"(?m)(?s).+"
;
static
String
regularExpressionMatchDisallowed
=
"(?m)(?s)[\\x00]"
;
static
String
defaultColumnNamePattern
=
"_unnamed_column_$$_"
;
static
Pattern
compiledRegularExpressionMatchAllowed
=
Pattern
.
compile
(
regularExpressionMatchAllowed
);
static
Pattern
compiledRegularExpressionMatchDisallowed
=
Pattern
.
compile
(
regularExpressionMatchDisallowed
);
public
static
void
configure
(
String
stringValue
)
{
try
{
if
(
stringValue
.
equalsIgnoreCase
(
DEFAULT_COMMAND
)){
maxIdentiferLength
=
Integer
.
MAX_VALUE
;
regularExpressionMatchAllowed
=
"(?m)(?s).+"
;
regularExpressionMatchDisallowed
=
"(?m)(?s)[\\x00]"
;
defaultColumnNamePattern
=
"_UNNAMED_$$"
;
}
else
if
(
stringValue
.
equalsIgnoreCase
(
"ORACLE128"
)){
maxIdentiferLength
=
128
;
regularExpressionMatchAllowed
=
"(?m)(?s)\"?[A-Za-z0-9_]+\"?"
;
regularExpressionMatchDisallowed
=
"(?m)(?s)[^A-Za-z0-9_\"]"
;
defaultColumnNamePattern
=
"_UNNAMED_$$"
;
}
else
if
(
stringValue
.
equalsIgnoreCase
(
"ORACLE30"
)){
maxIdentiferLength
=
30
;
regularExpressionMatchAllowed
=
"(?m)(?s)\"?[A-Za-z0-9_]+\"?"
;
regularExpressionMatchDisallowed
=
"(?m)(?s)[^A-Za-z0-9_\"]"
;
defaultColumnNamePattern
=
"_UNNAMED_$$"
;
}
else
if
(
stringValue
.
equalsIgnoreCase
(
"POSTGRES"
)){
maxIdentiferLength
=
31
;
regularExpressionMatchAllowed
=
"(?m)(?s)\"?[A-Za-z0-9_\"]+\"?"
;
regularExpressionMatchDisallowed
=
"(?m)(?s)[^A-Za-z0-9_\"]"
;
defaultColumnNamePattern
=
"_UNNAMED_$$"
;
}
else
if
(
stringValue
.
startsWith
(
MAX_IDENTIFIER_LENGTH
)){
maxIdentiferLength
=
Math
.
max
(
0
,
Integer
.
parseInt
(
stringValue
.
substring
(
MAX_IDENTIFIER_LENGTH
.
length
())));
}
else
if
(
stringValue
.
startsWith
(
DEFAULT_COLUMN_NAME_PATTERN
)){
defaultColumnNamePattern
=
stringValue
.
substring
(
DEFAULT_COLUMN_NAME_PATTERN
.
length
());
}
else
if
(
stringValue
.
startsWith
(
REGULAR_EXPRESSION_MATCH_ALLOWED
)){
regularExpressionMatchAllowed
=
stringValue
.
substring
(
REGULAR_EXPRESSION_MATCH_ALLOWED
.
length
());
}
else
if
(
stringValue
.
startsWith
(
REGULAR_EXPRESSION_MATCH_DISALLOWED
)){
regularExpressionMatchDisallowed
=
stringValue
.
substring
(
REGULAR_EXPRESSION_MATCH_DISALLOWED
.
length
());
}
else
{
throw
DbException
.
getInvalidValueException
(
"SET COLUMN_NAME_RULES: unknown id:"
+
stringValue
,
stringValue
);
}
// recompile RE patterns
compiledRegularExpressionMatchAllowed
=
Pattern
.
compile
(
regularExpressionMatchAllowed
);
compiledRegularExpressionMatchDisallowed
=
Pattern
.
compile
(
regularExpressionMatchDisallowed
);
}
//Including NumberFormatException|PatternSyntaxException
catch
(
RuntimeException
e
){
throw
DbException
.
getInvalidValueException
(
"SET COLUMN_NAME_RULES:"
+
e
.
getMessage
(),
stringValue
);
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论