Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e78ce27d
提交
e78ce27d
authored
1月 16, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clear CTE views on parsing or preparation error
上级
e063498f
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
52 行增加
和
10 行删除
+52
-10
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+31
-9
Parser.java
h2/src/main/org/h2/command/Parser.java
+15
-1
with.sql
h2/src/test/org/h2/test/scripts/dml/with.sql
+6
-0
没有找到文件。
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
e78ce27d
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
command
;
package
org
.
h2
.
command
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.command.dml.Explain
;
import
org.h2.command.dml.Explain
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.Query
;
...
@@ -27,6 +28,35 @@ public class CommandContainer extends Command {
...
@@ -27,6 +28,35 @@ public class CommandContainer extends Command {
private
boolean
readOnlyKnown
;
private
boolean
readOnlyKnown
;
private
boolean
readOnly
;
private
boolean
readOnly
;
/**
* Clears CTE views for a specified statement.
*
* @param session the session
* @param prepared prepared statement
*/
static
void
clearCTE
(
Session
session
,
Prepared
prepared
)
{
List
<
TableView
>
cteCleanups
=
prepared
.
getCteCleanups
();
if
(
cteCleanups
!=
null
)
{
clearCTE
(
session
,
cteCleanups
);
}
}
/**
* Clears CTE views.
*
* @param session the session
* @param views list of view
*/
static
void
clearCTE
(
Session
session
,
List
<
TableView
>
views
)
{
for
(
TableView
view
:
views
)
{
// check if view was previously deleted as their name is set to
// null
if
(
view
.
getName
()
!=
null
)
{
session
.
removeLocalTempTable
(
view
);
}
}
}
CommandContainer
(
Session
session
,
String
sql
,
Prepared
prepared
)
{
CommandContainer
(
Session
session
,
String
sql
,
Prepared
prepared
)
{
super
(
session
,
sql
);
super
(
session
,
sql
);
prepared
.
setCommand
(
this
);
prepared
.
setCommand
(
this
);
...
@@ -123,15 +153,7 @@ public class CommandContainer extends Command {
...
@@ -123,15 +153,7 @@ public class CommandContainer extends Command {
super
.
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
)
{
clearCTE
(
session
,
prepared
);
for
(
TableView
view
:
prepared
.
getCteCleanups
())
{
// check if view was previously deleted as their name is set to
// null
if
(
view
.
getName
()
!=
null
)
{
session
.
removeLocalTempTable
(
view
);
}
}
}
}
}
@Override
@Override
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e78ce27d
...
@@ -672,7 +672,12 @@ public class Parser {
...
@@ -672,7 +672,12 @@ public class Parser {
if
(!
hasMore
&&
currentTokenType
!=
END
)
{
if
(!
hasMore
&&
currentTokenType
!=
END
)
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
}
try
{
p
.
prepare
();
p
.
prepare
();
}
catch
(
Throwable
t
)
{
CommandContainer
.
clearCTE
(
session
,
p
);
throw
t
;
}
Command
c
=
new
CommandContainer
(
session
,
sql
,
p
);
Command
c
=
new
CommandContainer
(
session
,
sql
,
p
);
if
(
hasMore
)
{
if
(
hasMore
)
{
String
remaining
=
originalSQL
.
substring
(
parseIndex
);
String
remaining
=
originalSQL
.
substring
(
parseIndex
);
...
@@ -6128,6 +6133,15 @@ public class Parser {
...
@@ -6128,6 +6133,15 @@ public class Parser {
private
Prepared
parseWith
()
{
private
Prepared
parseWith
()
{
List
<
TableView
>
viewsCreated
=
new
ArrayList
<>();
List
<
TableView
>
viewsCreated
=
new
ArrayList
<>();
try
{
return
parseWith1
(
viewsCreated
);
}
catch
(
Throwable
t
)
{
CommandContainer
.
clearCTE
(
session
,
viewsCreated
);
throw
t
;
}
}
private
Prepared
parseWith1
(
List
<
TableView
>
viewsCreated
)
{
readIf
(
"RECURSIVE"
);
readIf
(
"RECURSIVE"
);
// This WITH statement is not a temporary view - it is part of a persistent view
// This WITH statement is not a temporary view - it is part of a persistent view
...
...
h2/src/test/org/h2/test/scripts/dml/with.sql
浏览文件 @
e78ce27d
...
@@ -146,5 +146,11 @@ WITH CTE_TEST AS (TABLE TEST) ((TABLE CTE_TEST));
...
@@ -146,5 +146,11 @@ WITH CTE_TEST AS (TABLE TEST) ((TABLE CTE_TEST));
>
1
2
>
1
2
>
rows
:
1
>
rows
:
1
WITH
CTE_TEST
AS
(
TABLE
TEST
)
((
SELECT
A
,
B
FROM
CTE_TEST2
));
>
exception
TABLE_OR_VIEW_NOT_FOUND_1
WITH
CTE_TEST
AS
(
TABLE
TEST
)
((
SELECT
A
,
B
,
C
FROM
CTE_TEST
));
>
exception
COLUMN_NOT_FOUND_1
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论