提交 19a80ed5 authored 作者: Thomas Mueller's avatar Thomas Mueller

Older versions of H2 (version 1.2.127 and older) could not connect to a new…

Older versions of H2 (version 1.2.127 and older) could not connect to a new version (version 1.2.129 and newer). The connection blocked when trying to connect. Now the connection no longer blocks, instead a SQL exception is thrown.
上级 b13afc6d
...@@ -67,7 +67,7 @@ public class CommandRemote implements CommandInterface { ...@@ -67,7 +67,7 @@ public class CommandRemote implements CommandInterface {
s.traceOperation("SESSION_PREPARE", id); s.traceOperation("SESSION_PREPARE", id);
transfer.writeInt(SessionRemote.SESSION_PREPARE).writeInt(id).writeString(sql); transfer.writeInt(SessionRemote.SESSION_PREPARE).writeInt(id).writeString(sql);
} }
s.convert(transfer); s.done(transfer);
isQuery = transfer.readBoolean(); isQuery = transfer.readBoolean();
readonly = transfer.readBoolean(); readonly = transfer.readBoolean();
paramCount = transfer.readInt(); paramCount = transfer.readInt();
...@@ -122,7 +122,7 @@ public class CommandRemote implements CommandInterface { ...@@ -122,7 +122,7 @@ public class CommandRemote implements CommandInterface {
try { try {
session.traceOperation("COMMAND_GET_META_DATA", id); session.traceOperation("COMMAND_GET_META_DATA", id);
transfer.writeInt(SessionRemote.COMMAND_GET_META_DATA).writeInt(id).writeInt(objectId); transfer.writeInt(SessionRemote.COMMAND_GET_META_DATA).writeInt(id).writeInt(objectId);
session.convert(transfer); session.done(transfer);
int columnCount = transfer.readInt(); int columnCount = transfer.readInt();
result = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE); result = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
break; break;
...@@ -155,7 +155,7 @@ public class CommandRemote implements CommandInterface { ...@@ -155,7 +155,7 @@ public class CommandRemote implements CommandInterface {
} }
transfer.writeInt(fetch); transfer.writeInt(fetch);
sendParameters(transfer); sendParameters(transfer);
session.convert(transfer); session.done(transfer);
int columnCount = transfer.readInt(); int columnCount = transfer.readInt();
if (result != null) { if (result != null) {
result.close(); result.close();
...@@ -187,7 +187,7 @@ public class CommandRemote implements CommandInterface { ...@@ -187,7 +187,7 @@ public class CommandRemote implements CommandInterface {
session.traceOperation("COMMAND_EXECUTE_UPDATE", id); session.traceOperation("COMMAND_EXECUTE_UPDATE", id);
transfer.writeInt(SessionRemote.COMMAND_EXECUTE_UPDATE).writeInt(id); transfer.writeInt(SessionRemote.COMMAND_EXECUTE_UPDATE).writeInt(id);
sendParameters(transfer); sendParameters(transfer);
session.convert(transfer); session.done(transfer);
updateCount = transfer.readInt(); updateCount = transfer.readInt();
autoCommit = transfer.readBoolean(); autoCommit = transfer.readBoolean();
} catch (IOException e) { } catch (IOException e) {
......
...@@ -203,7 +203,7 @@ public class ResultRemote implements ResultInterface { ...@@ -203,7 +203,7 @@ public class ResultRemote implements ResultInterface {
if (sendFetch) { if (sendFetch) {
session.traceOperation("RESULT_FETCH_ROWS", id); session.traceOperation("RESULT_FETCH_ROWS", id);
transfer.writeInt(SessionRemote.RESULT_FETCH_ROWS).writeInt(id).writeInt(fetch); transfer.writeInt(SessionRemote.RESULT_FETCH_ROWS).writeInt(id).writeInt(fetch);
session.convert(transfer); session.done(transfer);
} }
for (int r = 0; r < fetch; r++) { for (int r = 0; r < fetch; r++) {
boolean row = transfer.readBoolean(); boolean row = transfer.readBoolean();
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.tools.Server;
/**
* Tests the compatibility with older versions
*/
public class TestOldVersion extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws Exception {
URL[] urls = new URL[] { new URL("file:ext/h2-1.2.127.jar") };
ClassLoader cl = new URLClassLoader(urls, null);
// cl = getClass().getClassLoader();
Class< ? > driverClass = cl.loadClass("org.h2.Driver");
Method m = driverClass.getMethod("load");
Driver driver = (Driver) m.invoke(null);
Connection conn = driver.connect("jdbc:h2:mem:", null);
assertEquals("1.2.127 (2010-01-15)", conn.getMetaData().getDatabaseProductVersion());
Server server = org.h2.tools.Server.createTcpServer("-tcpPort", "9001");
server.start();
try {
conn = driver.connect("jdbc:h2:tcp://localhost:9001/mem:test", null);
} catch (SQLException e) {
assertEquals(ErrorCode.DRIVER_VERSION_ERROR_2, e.getErrorCode());
}
server.stop();
Class< ? > serverClass = cl.loadClass("org.h2.tools.Server");
m = serverClass.getMethod("createTcpServer", String[].class);
Object serverOld = m.invoke(null, new Object[]{new String[]{"-tcpPort", "9001"}});
m = serverOld.getClass().getMethod("start");
m.invoke(serverOld);
conn = org.h2.Driver.load().connect("jdbc:h2:mem:", null);
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("call 1");
rs.next();
assertEquals(1, rs.getInt(1));
conn.close();
m = serverOld.getClass().getMethod("stop");
m.invoke(serverOld);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论