提交 591a799e authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 334: SimpleResultSet.getString now also works for Clob columns.

上级 f478beb6
...@@ -28,6 +28,7 @@ import java.util.Calendar; ...@@ -28,6 +28,7 @@ import java.util.Calendar;
import java.util.Map; import java.util.Map;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.value.DataType; import org.h2.value.DataType;
...@@ -472,7 +473,15 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -472,7 +473,15 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
*/ */
public String getString(int columnIndex) throws SQLException { public String getString(int columnIndex) throws SQLException {
Object o = get(columnIndex); Object o = get(columnIndex);
return o == null ? null : o.toString(); if (o == null) {
return null;
}
switch (columns.get(columnIndex - 1).sqlType) {
case Types.CLOB:
Clob c = (Clob) o;
return c.getSubString(1, MathUtils.convertLongToInt(c.length()));
}
return o.toString();
} }
/** /**
......
...@@ -79,6 +79,7 @@ public class TestTools extends TestBase { ...@@ -79,6 +79,7 @@ public class TestTools extends TestBase {
return; return;
} }
org.h2.Driver.load(); org.h2.Driver.load();
testSimpleResultSet();
testTcpServerWithoutPort(); testTcpServerWithoutPort();
testConsole(); testConsole();
testJdbcDriverUtils(); testJdbcDriverUtils();
...@@ -99,7 +100,6 @@ public class TestTools extends TestBase { ...@@ -99,7 +100,6 @@ public class TestTools extends TestBase {
testScriptRunscript(); testScriptRunscript();
testBackupRestore(); testBackupRestore();
testRecover(); testRecover();
testSimpleResultSet();
deleteDb("utils"); deleteDb("utils");
FileUtils.delete(getBaseDir() + "/b2.sql"); FileUtils.delete(getBaseDir() + "/b2.sql");
FileUtils.delete(getBaseDir() + "/b2.sql.txt"); FileUtils.delete(getBaseDir() + "/b2.sql.txt");
...@@ -293,6 +293,8 @@ public class TestTools extends TestBase { ...@@ -293,6 +293,8 @@ public class TestTools extends TestBase {
assertTrue(clob == rs.getClob("k")); assertTrue(clob == rs.getClob("k"));
assertTrue(clob == rs.getClob(11)); assertTrue(clob == rs.getClob(11));
assertEquals("Hello World", rs.getString("k"));
assertEquals("Hello World", rs.getString(11));
assertTrue(blob == rs.getBlob("l")); assertTrue(blob == rs.getBlob("l"));
assertTrue(blob == rs.getBlob(12)); assertTrue(blob == rs.getBlob(12));
...@@ -910,7 +912,7 @@ public class TestTools extends TestBase { ...@@ -910,7 +912,7 @@ public class TestTools extends TestBase {
} }
public String getSubString(long pos, int length) throws SQLException { public String getSubString(long pos, int length) throws SQLException {
throw new UnsupportedOperationException(); return data;
} }
public long length() throws SQLException { public long length() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论