提交 f974e8b5 authored 作者: thomasmueller's avatar thomasmueller

Formatting, javadocs

上级 de02c023
......@@ -197,7 +197,7 @@ WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
select
","
Can be used to create a recursive or non-recursive query (common table expression).
Can be used to create a recursive or non-recursive query (common table expression).
For recursive queries the first select has to be a UNION.
One or more common table entries can be referred to by name.
Column name declarations are now optional - the column names will be inferred from the named select queries.
......@@ -213,8 +213,7 @@ SELECT sum(n) FROM t;
","
WITH t1 AS (
SELECT 1 AS FIRST_COLUMN
),
t2 AS (
), t2 AS (
SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1
)
SELECT sum(FIRST_COLUMN) FROM t2;
......
......@@ -71,7 +71,7 @@ WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
select
","
Can be used to create a recursive query."
Can be used to create a recursive or non-recursive query (common table expression)."
"Commands (DDL)","ALTER INDEX RENAME","
ALTER INDEX [ IF EXISTS ] indexName RENAME TO newIndexName
","
......
......@@ -144,7 +144,7 @@ public class RangeTable extends Table {
@Override
public TableType getTableType() {
return TableType.SYSTEM_TABLE;
return TableType.SYSTEM_TABLE;
}
@Override
......
......@@ -207,7 +207,8 @@ public class TableView extends Table {
// If it can't be compiled, then it's a 'zero column table'
// this avoids problems when creating the view when opening the
// database.
// If it can not be compiled - it could also be a recursive common table expression query.
// If it can not be compiled - it could also be a recursive common
// table expression query.
if (isRecursiveQueryExceptionDetected(createException)) {
this.isRecursiveQueryDetected = true;
}
......@@ -673,6 +674,8 @@ public class TableView extends Table {
/**
* Was query recursion detected during compiling.
*
* @return true if yes
*/
public boolean isRecursiveQueryDetected() {
return isRecursiveQueryDetected;
......
......@@ -16,7 +16,7 @@ import org.h2.test.TestBase;
*/
public class TestGeneralCommonTableQueries extends TestBase {
/**
/**
* Run just this test.
*
* @param a ignored
......@@ -45,14 +45,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
final String simple_two_column_query = "with " +
"t1(n) as (select 1 as first) " +
",t2(n) as (select 2 as first) " +
"select * from t1 union all select * from t2";
"select * from t1 union all select * from t2";
rs = stat.executeQuery(simple_two_column_query);
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement(simple_two_column_query);
rs = prep.executeQuery();
assertTrue(rs.next());
......@@ -60,7 +60,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("with " +
"t1(n) as (select 2 as first) " +
",t2(n) as (select 3 as first) " +
......@@ -72,7 +72,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("with " +
"t1(n) as (select 2 as first) " +
",t2(n) as (select 3 as first) " +
......@@ -85,7 +85,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
conn.close();
deleteDb("commonTableExpressionQueries");
}
......@@ -95,7 +95,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
Connection conn = getConnection("commonTableExpressionQueries");
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement("with " +
"t1 as (select 2 as first_col) " +
",t2 as (select first_col+1 from t1) " +
......@@ -110,98 +110,100 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertFalse(rs.next());
assertEquals(rs.getMetaData().getColumnCount(),1);
assertEquals("FIRST_COL",rs.getMetaData().getColumnLabel(1));
conn.close();
deleteDb("commonTableExpressionQueries");
}
private void testChainedQuery() throws Exception {
deleteDb("commonTableExpressionQueries");
Connection conn = getConnection("commonTableExpressionQueries");
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement(" WITH t1 AS ("
+" SELECT 1 AS FIRST_COLUMN"
+"),"
+" t2 AS ("
+" SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1 "
+") "
+"SELECT sum(FIRST_COLUMN) FROM t2");
prep = conn.prepareStatement(
" WITH t1 AS (" +
" SELECT 1 AS FIRST_COLUMN" +
")," +
" t2 AS (" +
" SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1 " +
") " +
"SELECT sum(FIRST_COLUMN) FROM t2");
rs = prep.executeQuery();
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
conn.close();
deleteDb("commonTableExpressionQueries");
}
}
private void testParameterizedQuery() throws Exception {
deleteDb("commonTableExpressionQueries");
Connection conn = getConnection("commonTableExpressionQueries");
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement("WITH t1 AS ("
+" SELECT X, 'T1' FROM SYSTEM_RANGE(?,?)"
+"),"
+"t2 AS ("
+" SELECT X, 'T2' FROM SYSTEM_RANGE(?,?)"
+") "
+"SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?,?)");
prep.setInt(1, 1);
prep.setInt(2, 2);
prep.setInt(3, 3);
prep.setInt(4, 4);
prep.setInt(5, 5);
prep.setInt(6, 6);
prep = conn.prepareStatement("WITH t1 AS (" +
" SELECT X, 'T1' FROM SYSTEM_RANGE(?,?)" +
")," +
"t2 AS (" +
" SELECT X, 'T2' FROM SYSTEM_RANGE(?,?)" +
") " +
"SELECT * FROM t1 UNION ALL SELECT * FROM t2 " +
"UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?,?)");
prep.setInt(1, 1);
prep.setInt(2, 2);
prep.setInt(3, 3);
prep.setInt(4, 4);
prep.setInt(5, 5);
prep.setInt(6, 6);
rs = prep.executeQuery();
for(int n: new int[]{1,2,3,4,5,6} ){
assertTrue(rs.next());
assertEquals(n, rs.getInt(1));
assertTrue(rs.next());
assertEquals(n, rs.getInt(1));
}
assertFalse(rs.next());
// call it twice
rs = prep.executeQuery();
for(int n: new int[]{1,2,3,4,5,6} ){
assertTrue(rs.next());
assertEquals(n, rs.getInt(1));
assertTrue(rs.next());
assertEquals(n, rs.getInt(1));
}
assertFalse(rs.next());
conn.close();
deleteDb("commonTableExpressionQueries");
}
private void testNumberedParameterizedQuery() throws Exception {
deleteDb("commonTableExpressionQueries");
Connection conn = getConnection("commonTableExpressionQueries");
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement("WITH t1 AS ("
+" SELECT R.X, 'T1' FROM SYSTEM_RANGE(?1,?2) R"
+"),"
+"t2 AS ("
+" SELECT R.X, 'T2' FROM SYSTEM_RANGE(?3,?4) R"
+") "
+"SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?5,?6)");
prep.setInt(1, 1);
prep.setInt(2, 2);
prep.setInt(3, 3);
prep.setInt(4, 4);
prep.setInt(5, 5);
prep.setInt(6, 6);
+" SELECT R.X, 'T1' FROM SYSTEM_RANGE(?1,?2) R"
+"),"
+"t2 AS ("
+" SELECT R.X, 'T2' FROM SYSTEM_RANGE(?3,?4) R"
+") "
+"SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT X, 'Q' FROM SYSTEM_RANGE(?5,?6)");
prep.setInt(1, 1);
prep.setInt(2, 2);
prep.setInt(3, 3);
prep.setInt(4, 4);
prep.setInt(5, 5);
prep.setInt(6, 6);
rs = prep.executeQuery();
for(int n: new int[]{1,2,3,4,5,6} ){
assertTrue(rs.next());
assertEquals(n, rs.getInt(1));
for (int n : new int[] { 1, 2, 3, 4, 5, 6 }) {
assertTrue(rs.next());
assertEquals(n, rs.getInt(1));
}
assertEquals("X",rs.getMetaData().getColumnLabel(1));
assertEquals("'T1'",rs.getMetaData().getColumnLabel(2));
......@@ -210,5 +212,5 @@ public class TestGeneralCommonTableQueries extends TestBase {
conn.close();
deleteDb("commonTableExpressionQueries");
}
}
}
......@@ -736,3 +736,4 @@ arbonaut exposing obscure determined turkey buildings indexhints acct
choosing optimise arte preparator katzyn bla jenkins tot artes pgserver npe
suffers closeablem mni significance vise identiy vitalus aka ilike uppercasing reentrant
aff ignite warm upstream producing sfu jit smtm affinity stashed tbl
stumc numbered
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论