提交 5562f5a9 authored 作者: Thomas Mueller's avatar Thomas Mueller

Lob in databases: two small BLOB or CLOB values were always considered equal.

上级 5cd78d7a
......@@ -242,7 +242,10 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
protected int compareSecure(Value v, CompareMode mode) {
if (v instanceof ValueLobDb) {
ValueLobDb v2 = (ValueLobDb) v;
if (lobId == v2.lobId) {
if (v == this) {
return 0;
}
if (lobId == v2.lobId && small == null && v2.small == null) {
return 0;
}
}
......
......@@ -23,6 +23,7 @@ import java.sql.Savepoint;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.store.FileLister;
import org.h2.store.fs.FileSystem;
......@@ -49,6 +50,7 @@ public class TestLob extends TestBase {
}
public void test() throws Exception {
testUniqueIndex();
testConvert();
testCreateAsSelect();
testDropAllObjects();
......@@ -85,6 +87,30 @@ public class TestLob extends TestBase {
FileSystem.getInstance(TEMP_DIR).deleteRecursive(TEMP_DIR, true);
}
private void testUniqueIndex() throws Exception {
deleteDb("lob");
Connection conn;
Statement stat;
conn = getConnection("lob");
stat = conn.createStatement();
stat.execute("create table test(x clob unique)");
stat.execute("insert into test values('hello')");
stat.execute("insert into test values('world')");
try {
stat.execute("insert into test values('world')");
} catch (SQLException e) {
assertEquals(ErrorCode.DUPLICATE_KEY_1, e.getErrorCode());
}
stat.execute("insert into test values(space(10000) || 'a')");
try {
stat.execute("insert into test values(space(10000) || 'a')");
} catch (SQLException e) {
assertEquals(ErrorCode.DUPLICATE_KEY_1, e.getErrorCode());
}
stat.execute("insert into test values(space(10000) || 'b')");
conn.close();
}
private void testConvert() throws Exception {
deleteDb("lob");
Connection conn;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论