提交 bda9027c authored 作者: Thomas Mueller's avatar Thomas Mueller

LINKED TABLE: the schema name can now be set.

上级 48d406c3
...@@ -22,8 +22,18 @@ import org.h2.test.TestBase; ...@@ -22,8 +22,18 @@ import org.h2.test.TestBase;
*/ */
public class TestLinkedTable extends TestBase { public class TestLinkedTable extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
new TestLinkedTable().init().test();
}
public void test() throws SQLException { public void test() throws SQLException {
// testLinkAutoAdd(); // testLinkAutoAdd();
testMultipleSchemas();
testReadOnlyLinkedTable(); testReadOnlyLinkedTable();
testLinkOtherSchema(); testLinkOtherSchema();
testLinkDrop(); testLinkDrop();
...@@ -53,6 +63,30 @@ public class TestLinkedTable extends TestBase { ...@@ -53,6 +63,30 @@ public class TestLinkedTable extends TestBase {
// cb.close(); // cb.close();
// } // }
private void testMultipleSchemas() throws SQLException {
org.h2.Driver.load();
Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
Connection cb = DriverManager.getConnection("jdbc:h2:mem:two", "sa", "sa");
Statement sa = ca.createStatement();
Statement sb = cb.createStatement();
sa.execute("CREATE TABLE TEST(ID INT)");
sa.execute("CREATE SCHEMA P");
sa.execute("CREATE TABLE P.TEST(X INT)");
sa.execute("INSERT INTO TEST VALUES(1)");
try {
sb.execute("CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')");
fail();
} catch (SQLException e) {
assertKnownException(e);
}
sb.execute("CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC', 'TEST')");
sb.execute("CREATE LINKED TABLE T2(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'P', 'TEST')");
sa.execute("DROP ALL OBJECTS");
sb.execute("DROP ALL OBJECTS");
ca.close();
cb.close();
}
private void testReadOnlyLinkedTable() throws SQLException { private void testReadOnlyLinkedTable() throws SQLException {
org.h2.Driver.load(); org.h2.Driver.load();
Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa"); Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
...@@ -118,7 +152,7 @@ public class TestLinkedTable extends TestBase { ...@@ -118,7 +152,7 @@ public class TestLinkedTable extends TestBase {
Connection conn2 = DriverManager.getConnection("jdbc:h2:mem:two"); Connection conn2 = DriverManager.getConnection("jdbc:h2:mem:two");
Statement stat2 = conn2.createStatement(); Statement stat2 = conn2.createStatement();
stat2.execute("CREATE LINKED TABLE one('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'Y.A');"); stat2.execute("CREATE LINKED TABLE one('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'Y.A');");
stat2.execute("CREATE LINKED TABLE two('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'A');"); stat2.execute("CREATE LINKED TABLE two('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC.A');");
ResultSet rs = stat2.executeQuery("SELECT * FROM one"); ResultSet rs = stat2.executeQuery("SELECT * FROM one");
rs.next(); rs.next();
assertEquals(rs.getInt(1), 2); assertEquals(rs.getInt(1), 2);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论