提交 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
<h1>Change Log</h1>
<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>
<h2>Version 1.3.150 Beta (2011-01-28)</h2>
......
......@@ -444,8 +444,11 @@ public class FileLock implements Runnable {
if (fileName != null) {
try {
Properties prop = load();
String serverId = prop.getProperty("server") + "/" + prop.getProperty("id");
e = e.addSQL(serverId);
String server = prop.getProperty("server");
if (server != null) {
String serverId = server + "/" + prop.getProperty("id");
e = e.addSQL(serverId);
}
} catch (DbException e2) {
// ignore
}
......
......@@ -13,6 +13,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.api.DatabaseEventListener;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.tools.Server;
......@@ -51,6 +52,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
}
public void test() throws Exception {
testWrongUrl();
autoServer = true;
testReconnect();
autoServer = false;
......@@ -58,6 +60,38 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
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 {
deleteDb("autoReconnect");
if (autoServer) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论