提交 79914c41 authored 作者: Thomas Mueller's avatar Thomas Mueller

Data types CLOB and BLOB: the maximum precision was Integer.MAX_VALUE, it is now Long.MAX_VALUE.

上级 c5dddee9
...@@ -25,6 +25,7 @@ import org.h2.compress.Compressor; ...@@ -25,6 +25,7 @@ import org.h2.compress.Compressor;
import org.h2.compress.LZFInputStream; import org.h2.compress.LZFInputStream;
import org.h2.compress.LZFOutputStream; import org.h2.compress.LZFOutputStream;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.MemoryUtils; import org.h2.util.MemoryUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -35,7 +36,7 @@ import org.h2.util.StringUtils; ...@@ -35,7 +36,7 @@ import org.h2.util.StringUtils;
public class CompressTool { public class CompressTool {
private static final CompressTool INSTANCE = new CompressTool(); private static final CompressTool INSTANCE = new CompressTool();
private static final int MAX_BUFFER_SIZE = 64 * 1024; private static final int MAX_BUFFER_SIZE = 3 * Constants.IO_BUFFER_SIZE_COMPRESS;
private byte[] cachedBuffer; private byte[] cachedBuffer;
private CompressTool() { private CompressTool() {
......
...@@ -30,6 +30,7 @@ import org.h2.test.db.TestFullText; ...@@ -30,6 +30,7 @@ import org.h2.test.db.TestFullText;
import org.h2.test.db.TestFunctionOverload; import org.h2.test.db.TestFunctionOverload;
import org.h2.test.db.TestFunctions; import org.h2.test.db.TestFunctions;
import org.h2.test.db.TestIndex; import org.h2.test.db.TestIndex;
import org.h2.test.db.TestLargeBlob;
import org.h2.test.db.TestLinkedTable; import org.h2.test.db.TestLinkedTable;
import org.h2.test.db.TestListener; import org.h2.test.db.TestListener;
import org.h2.test.db.TestLob; import org.h2.test.db.TestLob;
...@@ -431,6 +432,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1` ...@@ -431,6 +432,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
test(); test();
smallLog = false; smallLog = false;
networked = false;
ssl = false; ssl = false;
logMode = 0; logMode = 0;
traceLevelFile = 0; traceLevelFile = 0;
...@@ -476,6 +478,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1` ...@@ -476,6 +478,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
new TestFunctions().runTest(this); new TestFunctions().runTest(this);
new TestFunctionOverload().runTest(this); new TestFunctionOverload().runTest(this);
new TestIndex().runTest(this); new TestIndex().runTest(this);
new TestLargeBlob().runTest(this);
new TestLinkedTable().runTest(this); new TestLinkedTable().runTest(this);
new TestListener().runTest(this); new TestListener().runTest(this);
new TestLob().runTest(this); new TestLob().runTest(this);
......
...@@ -398,7 +398,7 @@ public abstract class TestBase { ...@@ -398,7 +398,7 @@ public abstract class TestBase {
* *
* @param s the message * @param s the message
*/ */
protected void println(String s) { public void println(String s) {
long time = System.currentTimeMillis() - start; long time = System.currentTimeMillis() - start;
printlnWithTime(time, getClass().getName() + " " + s); printlnWithTime(time, getClass().getName() + " " + s);
} }
......
/*
* Copyright 2004-2009 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.db;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Test a BLOB larger than Integer.MAX_VALUE
*/
public class TestLargeBlob 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 {
if (!config.big || config.memory || config.mvcc || config.networked) {
return;
}
deleteDb("largeBlob");
String url = getURL("largeBlob;TRACE_LEVEL_FILE=0", true);
Connection conn = getConnection(url);
final long testLength = Integer.MAX_VALUE + 110L;
Statement stat = conn.createStatement();
stat.execute("set COMPRESS_LOB LZF");
stat.execute("create table test(x blob)");
PreparedStatement prep = conn.prepareStatement(
"insert into test values(?)");
prep.setBinaryStream(1, new InputStream() {
long remaining = testLength;
int p;
byte[] oneByte = new byte[1];
public void close() {
// ignore
}
public int read(byte[] buff, int off, int len) {
len = (int) Math.min(remaining, len);
remaining -= len;
if (p++ % 5000 == 0) {
println("" + remaining);
}
return len == 0 ? -1 : len;
}
public int read() {
return read(oneByte, 0, 1) < 0 ? -1 : oneByte[0];
}
}, -1);
prep.executeUpdate();
ResultSet rs = stat.executeQuery(
"select length(x) from test");
rs.next();
assertEquals(testLength, rs.getLong(1));
rs = stat.executeQuery("select x from test");
rs.next();
InputStream in = rs.getBinaryStream(1);
byte[] buff = new byte[4 * 1024];
long length = 0;
while (true) {
int len = in.read(buff);
if (len < 0) {
break;
}
length += len;
}
assertEquals(testLength, length);
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论