提交 f95cb15d authored 作者: devnied's avatar devnied

Add missing schema with command "WITH RECURSIVE" and add quoteIdentifier for table name

Add some tests for table name with quote
上级 43a6faed
...@@ -13,6 +13,7 @@ import java.util.Map; ...@@ -13,6 +13,7 @@ import java.util.Map;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Parser;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -1158,7 +1159,9 @@ public class Select extends Query { ...@@ -1158,7 +1159,9 @@ public class Select extends Query {
// since using a with statement will re-create the common table expression // since using a with statement will re-create the common table expression
// views. // views.
} else { } else {
buff.append("WITH RECURSIVE ").append(t.getName()).append('('); buff.append("WITH RECURSIVE ")
.append(t.getSchema().getSQL()).append('.').append(Parser.quoteIdentifier(t.getName()))
.append('(');
buff.resetCount(); buff.resetCount();
for (Column c : t.getColumns()) { for (Column c : t.getColumns()) {
buff.appendExceptFirst(","); buff.appendExceptFirst(",");
......
...@@ -778,7 +778,7 @@ public class TableFilter implements ColumnResolver { ...@@ -778,7 +778,7 @@ public class TableFilter implements ColumnResolver {
return buff.toString(); return buff.toString();
} }
if (table.isView() && ((TableView) table).isRecursive()) { if (table.isView() && ((TableView) table).isRecursive()) {
buff.append(table.getSchema().getSQL()).append('.').append(table.getName()); buff.append(table.getSchema().getSQL()).append('.').append(Parser.quoteIdentifier(table.getName()));
} else { } else {
buff.append(table.getSQL()); buff.append(table.getSQL());
} }
......
...@@ -6,7 +6,14 @@ explain with recursive r(n) as ( ...@@ -6,7 +6,14 @@ explain with recursive r(n) as (
(select 1) union all (select n+1 from r where n < 3) (select 1) union all (select n+1 from r where n < 3)
) )
select n from r; select n from r;
>> WITH RECURSIVE R(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC.R /* PUBLIC.R.tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC.R R /* null */ >> WITH RECURSIVE PUBLIC.R(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC.R /* PUBLIC.R.tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC.R R /* null */
explain with recursive "r"(n) as (
(select 1) union all (select n+1 from "r" where n < 3)
)
select n from "r";
>> WITH RECURSIVE PUBLIC."r"(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC."r" /* PUBLIC."r".tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC."r" "r" /* null */
select sum(n) from ( select sum(n) from (
with recursive r(n) as ( with recursive r(n) as (
...@@ -16,6 +23,14 @@ select sum(n) from ( ...@@ -16,6 +23,14 @@ select sum(n) from (
); );
>> 6 >> 6
select sum(n) from (
with recursive "r"(n) as (
(select 1) union all (select n+1 from "r" where n < 3)
)
select n from "r"
);
>> 6
select sum(n) from (select 0) join ( select sum(n) from (select 0) join (
with recursive r(n) as ( with recursive r(n) as (
(select 1) union all (select n+1 from r where n < 3) (select 1) union all (select n+1 from r where n < 3)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论