提交 475ed92e authored 作者: Thomas Mueller's avatar Thomas Mueller

The JDBC client did not detect that it was not talking to an H2 server.

上级 4658e526
......@@ -88,7 +88,7 @@
90064=Savepoint is unnamed
90065=Savepoint is named
90066=Duplicate property {0}
90067=Connection is broken
90067=Connection is broken\: {0}
90068=Order by expression {0} must be in the result list in this case
90069=Role {0} already exists
90070=Role {0} not found
......
......@@ -410,7 +410,7 @@ public class Session extends SessionWithState {
*/
public Command prepareLocal(String sql) throws SQLException {
if (closed) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN);
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "session closed");
}
Parser parser = new Parser(this);
return parser.prepareCommand(sql);
......
......@@ -461,7 +461,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
*/
public void checkClosed() throws SQLException {
if (isClosed()) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN);
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "session closed");
}
}
......@@ -524,6 +524,10 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
transferList = null;
} else if (status == STATUS_OK_STATE_CHANGED) {
sessionStateChanged = true;
} else if (status == STATUS_OK) {
// ok
} else {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "unexpected status " + status);
}
}
......
......@@ -88,7 +88,7 @@
90064=Savepoint hat keinen Namen
90065=Savepoint hat einen Namen
90066=Doppeltes Merkmahl {0}
90067=Verbindung ist unterbrochen
90067=Verbindung ist unterbrochen\: {0}
90068=Sortier-Ausdruck {0} muss in diesem Fall im Resultat vorkommen
90069=Rolle {0} besteht bereits
90070=Rolle {0} nicht gefunden
......
......@@ -88,7 +88,7 @@
90064=Savepoint is unnamed
90065=Savepoint is named
90066=Duplicate property {0}
90067=Connection is broken
90067=Connection is broken\: {0}
90068=Order by expression {0} must be in the result list in this case
90069=Role {0} already exists
90070=Role {0} not found
......
......@@ -88,7 +88,7 @@
90064=Savepoint sin nombre
90065=Savepoint con nombre
90066=Propiedad Duplicada {0}
90067=Conexi\u00F3n rota
90067=Conexi\u00F3n rota\: {0}
90068=Expresi\u00F3n Order by {0} debe estar en la lista de campos a devolver en este caso
90069=Role {0} ya existe
90070=Role {0} no encontrado
......
......@@ -88,7 +88,7 @@
90064=\u30BB\u30FC\u30D6\u30DD\u30A4\u30F3\u30C8\u306E\u540D\u524D\u3092\u524A\u9664\u3057\u307E\u3057\u305F
90065=\u30BB\u30FC\u30D6\u30DD\u30A4\u30F3\u30C8\u306B\u540D\u524D\u3092\u8A2D\u5B9A\u3057\u307E\u3057\u305F
90066=\u30D7\u30ED\u30D1\u30C6\u30A3 {0} \u304C\u91CD\u8907\u3057\u3066\u3044\u307E\u3059
90067=\u63A5\u7D9A\u304C\u58CA\u308C\u3066\u3044\u307E\u3059
90067=\u63A5\u7D9A\u304C\u58CA\u308C\u3066\u3044\u307E\u3059\: {0}
90068=order by \u5BFE\u8C61\u306E\u5F0F {0} \u306F\u3001\u7D50\u679C\u30EA\u30B9\u30C8\u306B\u542B\u307E\u308C\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059
90069=\u30ED\u30FC\u30EB {0} \u306F\u3059\u3067\u306B\u5B58\u5728\u3057\u307E\u3059
90070=\u30ED\u30FC\u30EB {0} \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093
......
......@@ -88,7 +88,7 @@
90064=Zakladka jest bez nazwy
90065=Zakladka jest nazwana
90066=Zduplikowana wlasciwosc {0}
90067=Polaczenie uszkodzone
90067=Polaczenie uszkodzone\: {0}
90068=Wyrazenie sortowania {0} musi byc na liscie wyboru w tym przypadku
90069=Rola {0} juz istnieje
90070=Rola {0} nie istnieje
......
......@@ -88,7 +88,7 @@
90064=Savepoint n\u00E3o est\u00E1 nomeado
90065=Savepoint est\u00E1 nomeado
90066=Propriedade {0} duplicada
90067=A conec\u00E7\u00E3o est\u00E1 quebrada
90067=A conec\u00E7\u00E3o est\u00E1 quebrada\: {0}
90068=Express\u00E3o order by {0} deve estar na lista neste caso
90069=Regra {0} j\u00E1 existe
90070=Regra {0} n\u00E3o foi encontrada
......
......@@ -88,7 +88,7 @@
90064=Savepoint \u043D\u0435 \u0438\u043C\u0435\u0435\u0442 \u0438\u043C\u0435\u043D\u0438
90065=Savepoint \u044F\u0432\u043B\u044F\u0435\u0442\u0441\u044F \u0438\u043C\u0435\u043D\u043E\u0432\u0430\u043D\u043D\u044B\u043C
90066=\u041F\u043E\u0432\u0442\u043E\u0440 \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u0430 \u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u044F {0}
90067=\u0421\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u0435 \u0440\u0430\u0437\u043E\u0440\u0432\u0430\u043D\u043E
90067=\u0421\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u0435 \u0440\u0430\u0437\u043E\u0440\u0432\u0430\u043D\u043E\: {0}
90068=\u0421\u0442\u043E\u043B\u0431\u0446\u044B \u043F\u0440\u0435\u0434\u043B\u043E\u0436\u0435\u043D\u0438\u044F ORDER BY {0} \u0432 \u0434\u0430\u043D\u043D\u043E\u043C \u0441\u043B\u0443\u0447\u0430\u0435 \u0434\u043E\u043B\u0436\u043D\u044B \u0441\u043E\u0434\u0435\u0440\u0436\u0430\u0442\u044C\u0441\u044F \u0432 \u0432\u044B\u0431\u0438\u0440\u0430\u0435\u043C\u043E\u043C \u0441\u043F\u0438\u0441\u043A\u0435
90069=\u0420\u043E\u043B\u044C {0} \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442
90070=\u0420\u043E\u043B\u044C {0} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430
......
......@@ -27,7 +27,6 @@ import java.sql.Time;
import java.sql.Timestamp;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.SessionInterface;
import org.h2.message.Message;
......@@ -361,22 +360,22 @@ public class Transfer {
break;
case Value.BLOB: {
long length = v.getPrecision();
if (SysProperties.CHECK && length < 0) {
Message.throwInternalError("length: " + length);
if (length < 0) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "length=" + length);
}
writeLong(length);
InputStream in = v.getInputStream();
long written = IOUtils.copyAndCloseInput(in, out);
if (SysProperties.CHECK && written != length) {
Message.throwInternalError("length:" + length + " written:" + written);
if (written != length) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "length:" + length + " written:" + written);
}
writeInt(LOB_MAGIC);
break;
}
case Value.CLOB: {
long length = v.getPrecision();
if (SysProperties.CHECK && length < 0) {
Message.throwInternalError("length: " + length);
if (length < 0) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "length=" + length);
}
writeLong(length);
Reader reader = v.getReader();
......@@ -390,8 +389,8 @@ public class Transfer {
};
Writer writer = new BufferedWriter(new OutputStreamWriter(out2, Constants.UTF8));
long written = IOUtils.copyAndCloseInput(reader, writer);
if (SysProperties.CHECK && written != length) {
Message.throwInternalError("length:" + length + " written:" + written);
if (written != length) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "length:" + length + " written:" + written);
}
writer.flush();
writeInt(LOB_MAGIC);
......@@ -430,7 +429,7 @@ public class Transfer {
break;
}
default:
Message.throwInternalError("type=" + type);
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "type=" + type);
}
}
......@@ -484,16 +483,18 @@ public class Transfer {
case Value.BLOB: {
long length = readLong();
ValueLob v = ValueLob.createBlob(in, length, session.getDataHandler());
if (readInt() != LOB_MAGIC) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN);
int magic = readInt();
if (magic != LOB_MAGIC) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "magic=" + magic);
}
return v;
}
case Value.CLOB: {
long length = readLong();
ValueLob v = ValueLob.createClob(new ExactUTF8InputStreamReader(in), length, session.getDataHandler());
if (readInt() != LOB_MAGIC) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN);
int magic = readInt();
if (magic != LOB_MAGIC) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "magic=" + magic);
}
return v;
}
......@@ -524,7 +525,7 @@ public class Transfer {
return ValueResultSet.get(rs);
}
default:
throw Message.throwInternalError("type="+type);
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "type=" + type);
}
}
......
......@@ -10,6 +10,8 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
......@@ -19,6 +21,7 @@ import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Random;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
......@@ -55,6 +58,7 @@ public class TestTools extends TestBase {
return;
}
org.h2.Driver.load();
testWrongServer();
deleteDb("utils");
testDeleteFiles();
testScriptRunscriptLob();
......@@ -71,6 +75,33 @@ public class TestTools extends TestBase {
deleteDb("utils");
}
private void testWrongServer() throws Exception {
final ServerSocket serverSocket = new ServerSocket(9001);
Thread thread = new Thread() {
public void run() {
try {
Socket socket = serverSocket.accept();
byte[] data = new byte[1024];
data[0] = 'x';
socket.getOutputStream().write(data);
socket.close();
} catch (Exception e) {
// ignore
}
}
};
thread.start();
try {
Connection conn = getConnection("jdbc:h2:tcp://localhost:9001/test");
conn.close();
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.CONNECTION_BROKEN_1, e.getErrorCode());
}
serverSocket.close();
thread.join();
}
private void testDeleteFiles() throws SQLException {
deleteDb("utilsMore");
Connection conn = getConnection("utilsMore");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论