提交 37526e6e authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 279: Auto-Server mode: unclear error message when trying to connect using…

Issue 279: Auto-Server mode: unclear error message when trying to connect using AUTO_SERVER if the database is already open without the flag (Connection is broken: "null").
上级 b79844b3
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Issue 238: Can drop a column that has a single-column constraint. <ul><li>Issue 279: Auto-Server mode: unclear error message when trying to connect using AUTO_SERVER
if the database is already open without the flag (Connection is broken: "null").
</li><li>Issue 238: Can drop a column that has a single-column constraint.
</li></ul> </li></ul>
<h2>Version 1.3.150 Beta (2011-01-28)</h2> <h2>Version 1.3.150 Beta (2011-01-28)</h2>
......
...@@ -444,8 +444,11 @@ public class FileLock implements Runnable { ...@@ -444,8 +444,11 @@ public class FileLock implements Runnable {
if (fileName != null) { if (fileName != null) {
try { try {
Properties prop = load(); Properties prop = load();
String serverId = prop.getProperty("server") + "/" + prop.getProperty("id"); String server = prop.getProperty("server");
e = e.addSQL(serverId); if (server != null) {
String serverId = server + "/" + prop.getProperty("id");
e = e.addSQL(serverId);
}
} catch (DbException e2) { } catch (DbException e2) {
// ignore // ignore
} }
......
...@@ -13,6 +13,7 @@ import java.sql.ResultSet; ...@@ -13,6 +13,7 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Server; import org.h2.tools.Server;
...@@ -51,6 +52,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener ...@@ -51,6 +52,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
} }
public void test() throws Exception { public void test() throws Exception {
testWrongUrl();
autoServer = true; autoServer = true;
testReconnect(); testReconnect();
autoServer = false; autoServer = false;
...@@ -58,6 +60,38 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener ...@@ -58,6 +60,38 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
deleteDb("autoReconnect"); deleteDb("autoReconnect");
} }
private void testWrongUrl() throws Exception {
deleteDb("autoReconnect");
Server tcp = Server.createTcpServer().start();
try {
Connection conn = getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;AUTO_SERVER=TRUE");
try {
getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;OPEN_NEW=TRUE");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.DATABASE_ALREADY_OPEN_1, e.getErrorCode());
}
try {
getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;OPEN_NEW=TRUE");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.DATABASE_ALREADY_OPEN_1, e.getErrorCode());
}
conn.close();
conn = getConnection("jdbc:h2:tcp://localhost/" + getBaseDir() + "/autoReconnect");
try {
getConnection("jdbc:h2:" + getBaseDir() + "/autoReconnect;AUTO_SERVER=TRUE;OPEN_NEW=TRUE");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.DATABASE_ALREADY_OPEN_1, e.getErrorCode());
}
conn.close();
} finally {
tcp.stop();
}
}
private void testReconnect() throws Exception { private void testReconnect() throws Exception {
deleteDb("autoReconnect"); deleteDb("autoReconnect");
if (autoServer) { if (autoServer) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论