Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b8c1ca70
提交
b8c1ca70
authored
10月 15, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removing CR/LF from column names
上级
adfc2afa
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
39 行增加
和
57 行删除
+39
-57
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+1
-8
Parser.java
h2/src/main/org/h2/command/Parser.java
+3
-3
Prepared.java
h2/src/main/org/h2/command/Prepared.java
+0
-4
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-5
Session.java
h2/src/main/org/h2/engine/Session.java
+0
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+0
-12
ColumnNamer.java
h2/src/main/org/h2/util/ColumnNamer.java
+12
-8
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+22
-16
没有找到文件。
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
b8c1ca70
...
...
@@ -102,7 +102,6 @@ public class CommandContainer extends Command {
int
updateCount
=
prepared
.
update
();
prepared
.
trace
(
startTimeNanos
,
updateCount
);
setProgress
(
DatabaseEventListener
.
STATE_STATEMENT_END
);
System
.
out
.
println
(
"CommandContainer.update.end"
);
return
updateCount
;
}
...
...
@@ -115,14 +114,11 @@ public class CommandContainer extends Command {
ResultInterface
result
=
prepared
.
query
(
maxrows
);
prepared
.
trace
(
startTimeNanos
,
result
.
isLazy
()
?
0
:
result
.
getRowCount
());
setProgress
(
DatabaseEventListener
.
STATE_STATEMENT_END
);
System
.
out
.
println
(
"CommandContainer.query.end"
);
return
result
;
}
@Override
public
void
stop
()
{
System
.
out
.
println
(
"CommandContainer.stop.stop"
);
super
.
stop
();
// Clean up after the command was run in the session.
// Must restart query (and dependency construction) to reuse.
if
(
prepared
.
getCteCleanups
()
!=
null
)
{
...
...
@@ -130,14 +126,11 @@ public class CommandContainer extends Command {
// check if view was previously deleted as their name is set to
// null
if
(
view
.
getName
()
!=
null
)
{
System
.
out
.
println
(
"!!!!!!!removeLocalTempTable.worked="
+
view
.
getName
());
session
.
removeLocalTempTable
(
view
);
}
else
{
System
.
out
.
println
(
"!!!!!!!removeLocalTempTable=(null local name)"
+
view
.
toString
());
}
}
}
super
.
stop
();
}
@Override
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
b8c1ca70
...
...
@@ -4938,7 +4938,6 @@ public class Parser {
Query
query
=
parseSelectUnion
();
query
.
setPrepareAlways
(
true
);
query
.
setNeverLazy
(
true
);
System
.
out
.
println
(
"class="
+
query
.
getClass
());
p
=
query
;
}
else
if
(
readIf
(
"INSERT"
))
{
...
...
@@ -5048,11 +5047,11 @@ public class Parser {
// No easy way to determine if this is a recursive query up front, so we just compile
// it twice - once without the flag set, and if we didn't see a recursive term,
// then we just compile it again.
System
.
out
.
println
(
"parseSingleCommonTableExpression.querySQL="
+
querySQL
);
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
true
/* recursive */
,
false
);
if
(!
view
.
isRecursiveQueryDetected
())
{
session
.
removeLocalTempTable
(
view
);
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
false
/* recursive */
,
false
);
...
...
@@ -5060,7 +5059,8 @@ public class Parser {
view
.
setTableExpression
(
true
);
view
.
setTemporary
(
true
);
session
.
addLocalTempTable
(
view
);
view
.
setOnCommitDrop
(
true
);
view
.
setOnCommitDrop
(
false
);
view
.
setHidden
(
true
);
return
view
;
}
...
...
h2/src/main/org/h2/command/Prepared.java
浏览文件 @
b8c1ca70
...
...
@@ -445,10 +445,6 @@ public abstract class Prepared {
* Get the temporary views created for CTE's.
*/
public
List
<
TableView
>
getCteCleanups
()
{
System
.
out
.
println
(
"getCteCleanups:"
+
cteCleanups
);
if
(
cteCleanups
!=
null
){
System
.
out
.
println
(
"getCteCleanups:"
+
cteCleanups
.
size
());
}
return
cteCleanups
;
}
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
b8c1ca70
...
...
@@ -839,13 +839,9 @@ 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
.
isReasonableColumnName
(
e
.
getAlias
())){
System
.
out
.
println
(
"Added alias="
+
columnName
);
if
(!
ColumnNamer
.
isAllowableColumnName
(
e
.
getAlias
())){
e
=
new
Alias
(
e
,
columnName
,
true
);
}
else
{
System
.
out
.
println
(
"Acceptable column name="
+
columnName
);
}
expressions
.
set
(
i
,
e
.
optimize
(
session
));
}
if
(
condition
!=
null
)
{
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
b8c1ca70
...
...
@@ -364,7 +364,6 @@ public class Session extends SessionWithState {
table
.
getSQL
());
}
modificationId
++;
System
.
out
.
println
(
"addLocalTempTable.worked="
+
table
.
getName
()+
table
.
toString
());
localTempTables
.
put
(
table
.
getName
(),
table
);
}
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
b8c1ca70
...
...
@@ -417,13 +417,6 @@ public class TableView extends Table {
@Override
public
void
removeChildrenAndResources
(
Session
session
)
{
System
.
out
.
println
(
"invalidating="
+
getName
());
try
{
throw
new
RuntimeException
(
"snapshot"
);
}
catch
(
RuntimeException
e
){
e
.
printStackTrace
();
}
removeViewFromTables
();
super
.
removeChildrenAndResources
(
session
);
database
.
removeMeta
(
session
,
getId
());
...
...
@@ -447,8 +440,6 @@ public class TableView extends Table {
@Override
public
String
getSQL
()
{
if
(
isTemporary
())
{
System
.
out
.
println
(
"table view name="
+
getName
());
System
.
out
.
println
(
this
.
toString
()+
".getSQL().querySQL="
+
querySQL
);
return
"(\n"
+
StringUtils
.
indent
(
querySQL
)
+
")"
;
}
return
super
.
getSQL
();
...
...
@@ -512,11 +503,8 @@ public class TableView extends Table {
private
void
removeViewFromTables
()
{
if
(
tables
!=
null
)
{
System
.
out
.
println
(
"removeViewFromTables.tables="
+
tables
);
System
.
out
.
println
(
"removeViewFromTables.this="
+
this
);
for
(
Table
t
:
tables
)
{
t
.
removeView
(
this
);
System
.
out
.
println
(
"removeViewFromTables.tables."
+
t
.
getName
()+
"="
+
t
.
getViews
());
}
tables
.
clear
();
}
...
...
h2/src/main/org/h2/util/ColumnNamer.java
浏览文件 @
b8c1ca70
...
...
@@ -13,13 +13,16 @@ public class ColumnNamer {
}
if
(
columnName
==
null
&&
columnExp
.
getAlias
()!=
null
){
columnName
=
columnExp
.
getAlias
();
if
(!
is
Reason
ableColumnName
(
columnName
)){
if
(!
is
Allow
ableColumnName
(
columnName
)){
columnName
=
null
;
}
}
if
(
columnName
==
null
&&
columnExp
.
getColumnName
()!=
null
){
columnName
=
columnExp
.
getColumnName
();
if
(!
isReasonableColumnName
(
columnName
)){
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
columnName
.
replace
(
'\n'
,
' '
).
replace
(
'\r'
,
' '
);
}
if
(!
isAllowableColumnName
(
columnName
)){
columnName
=
null
;
}
}
...
...
@@ -29,15 +32,16 @@ public class ColumnNamer {
return
columnName
;
}
private
static
Pattern
reasonableNamePatternRE
=
Pattern
.
compile
(
"[A-Z_][A-Z0-9_
]*"
);
public
static
boolean
is
Reason
ableColumnName
(
String
proposedName
){
//private static final Pattern reasonableNameCharactersPatternRE = Pattern.compile("[a-zA-Z0-9_'\\(\\)\\*,\\.\\+\\-\\*/:=\\<\\>!\\|@ \\t\\?\"\\$
]*");
public
static
boolean
is
Allow
ableColumnName
(
String
proposedName
){
if
(
proposedName
==
null
){
return
false
;
}
Matcher
m
=
reasonableNamePatternRE
.
matcher
(
proposedName
.
toUpperCase
());
boolean
isReasonableName
=
m
.
matches
();
return
isReasonableName
;
if
(
proposedName
.
contains
(
"\n"
)
||
proposedName
.
contains
(
"\r"
)){
return
false
;
}
return
true
;
}
}
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
b8c1ca70
...
...
@@ -9,7 +9,6 @@ import java.sql.Connection;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.test.TestBase
;
...
...
@@ -219,7 +218,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertEquals
(
n
,
rs
.
getInt
(
1
));
}
assertEquals
(
"X"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
assertEquals
(
"
_unnamed_column_2_
"
,
rs
.
getMetaData
().
getColumnLabel
(
2
));
assertEquals
(
"
'T1'
"
,
rs
.
getMetaData
().
getColumnLabel
(
2
));
assertFalse
(
rs
.
next
());
...
...
@@ -511,32 +510,39 @@ public class TestGeneralCommonTableQueries extends TestBase {
+
"FROM A \n"
+
"GROUP BY A.val"
;
for
(
int
queryTries:
new
int
[]{
1
,
2
,
3
}){
System
.
out
.
println
(
"Try#"
+
queryTries
);
for
(
@SuppressWarnings
(
"unused"
)
int
queryRunTries:
new
int
[]{
1
,
2
,
3
}){
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
SETUP_SQL
);
stat
.
close
();
prep
=
conn
.
prepareStatement
(
WITH_QUERY
);
rs
=
prep
.
executeQuery
();
for
(
int
columnIndex
=
1
;
columnIndex
<=
rs
.
getMetaData
().
getColumnCount
();
columnIndex
++){
System
.
out
.
print
(
"|"
+
rs
.
getMetaData
().
getColumnLabel
(
columnIndex
));
}
System
.
out
.
println
();
// previously the column label was null or had \n or \r in the string
assertTrue
(
rs
.
getMetaData
().
getColumnLabel
(
columnIndex
)!=
null
);
assertFalse
(
rs
.
getMetaData
().
getColumnLabel
(
columnIndex
).
contains
(
"\n"
));
assertFalse
(
rs
.
getMetaData
().
getColumnLabel
(
columnIndex
).
contains
(
"\r"
));
}
int
rowNdx
=
0
;
while
(
rs
.
next
())
{
//assertTrue(rs.next());
//assertContains("ab",rs.getString(1));
//assertEquals(rs.getString(1),keyLetter);
//assertTrue(rs.getInt(2)!=0);
StringBuffer
buf
=
new
StringBuffer
();
for
(
int
columnIndex
=
1
;
columnIndex
<=
rs
.
getMetaData
().
getColumnCount
();
columnIndex
++){
System
.
out
.
print
(
"|"
+
rs
.
getString
(
columnIndex
));
buf
.
append
(
"|"
+
rs
.
getString
(
columnIndex
));
}
System
.
out
.
println
();
}
String
[]
expectedRow
=
new
String
[]{
"|meat|null"
,
"|fruit|3"
,
"|veg|2"
};
assertEquals
(
expectedRow
[
rowNdx
],
buf
.
toString
());
rowNdx
++;
}
assertEquals
(
3
,
rowNdx
);
rs
.
close
();
prep
.
close
();
}
conn
.
close
();
//System.out.println("conn.close();");
deleteDb
(
"commonTableExpressionQueries"
);
//System.out.println("deleteDb(commonTableExpressionQueries);");
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论