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