提交 99216697 authored 作者: Noel Grandin's avatar Noel Grandin

Merge branch 'master' of https://github.com/h2database/h2database

......@@ -125,7 +125,7 @@ public class JdbcBlob extends TraceObject implements Blob {
}
/**
* [Not supported] Sets some bytes of the object.
* Sets some bytes of the object.
*
* @param pos the write position
* @param bytes the bytes to set
......@@ -136,7 +136,19 @@ public class JdbcBlob extends TraceObject implements Blob {
@Override
public int setBytes(long pos, byte[] bytes, int offset, int len)
throws SQLException {
throw unsupported("LOB update");
try {
if (isDebugEnabled()) {
debugCode("setBytes(" + pos + ", " + quoteBytes(bytes) + ", " + offset + ", " + len + ");");
}
checkClosed();
if (pos != 1) {
throw DbException.getInvalidValueException("pos", pos);
}
value = conn.createBlob(new ByteArrayInputStream(bytes, offset, len), -1);
return (int) value.getPrecision();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
......
......@@ -21,6 +21,7 @@ import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.message.DbException;
import org.h2.message.TraceObject;
import org.h2.store.RangeReader;
import org.h2.util.IOUtils;
import org.h2.util.Task;
import org.h2.value.Value;
......@@ -227,12 +228,34 @@ public class JdbcClob extends TraceObject implements NClob
}
/**
* [Not supported] Sets a substring.
* Fills the Clob. This is only supported for new, empty Clob objects that
* were created with Connection.createClob() or createNClob(). The position
* must be 1, meaning the whole Clob data is set.
*
* @param pos where to start writing (the first character is at position 1)
* @param str the string to add
* @param offset the string offset
* @param len the number of characters to read
* @return the length of the added text
*/
@Override
public int setString(long pos, String str, int offset, int len)
throws SQLException {
throw unsupported("LOB update");
try {
if (isDebugEnabled()) {
debugCode("setString(" + pos + ", " + quote(str) + ", " + offset + ", " + len + ");");
}
checkClosed();
if (pos != 1) {
throw DbException.getInvalidValueException("pos", pos);
} else if (str == null) {
throw DbException.getInvalidValueException("str", str);
}
value = conn.createClob(new RangeReader(new StringReader(str), offset, len), -1);
return (int) value.getPrecision();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
......
......@@ -86,8 +86,6 @@ public class TestLobApi extends TestBase {
truncate(0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).
setAsciiStream(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).
setString(1, "", 0, 1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).
position("", 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).
......@@ -96,8 +94,6 @@ public class TestLobApi extends TestBase {
Blob blob = rs.getBlob(3);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).
truncate(0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).
setBytes(1, new byte[0], 0, 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).
position(new byte[1], 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).
......@@ -237,30 +233,43 @@ public class TestLobApi extends TestBase {
prep.setInt(1, 2);
b = conn.createBlob();
b.setBytes(1, data);
assertEquals(length, b.setBytes(1, data));
prep.setBlob(2, b);
prep.execute();
prep.setInt(1, 3);
prep.setBlob(2, new ByteArrayInputStream(data));
Blob b2 = conn.createBlob();
byte[] xdata = new byte[length + 2];
System.arraycopy(data, 0, xdata, 1, length);
assertEquals(length, b2.setBytes(1, xdata, 1, length));
prep.setBlob(2, b2);
prep.execute();
prep.setInt(1, 4);
prep.setBlob(2, new ByteArrayInputStream(data));
prep.execute();
prep.setInt(1, 5);
prep.setBlob(2, new ByteArrayInputStream(data), -1);
prep.execute();
ResultSet rs;
rs = stat.executeQuery("select * from test");
rs.next();
Blob b2 = rs.getBlob(2);
assertEquals(length, b2.length());
Blob b3 = rs.getBlob(2);
assertEquals(length, b3.length());
byte[] bytes = b.getBytes(1, length);
byte[] bytes2 = b2.getBytes(1, length);
byte[] bytes2 = b3.getBytes(1, length);
assertEquals(bytes, bytes2);
rs.next();
b3 = rs.getBlob(2);
assertEquals(length, b3.length());
bytes2 = b3.getBytes(1, length);
assertEquals(bytes, bytes2);
rs.next();
b2 = rs.getBlob(2);
assertEquals(length, b2.length());
bytes2 = b2.getBytes(1, length);
b3 = rs.getBlob(2);
assertEquals(length, b3.length());
bytes2 = b3.getBytes(1, length);
assertEquals(bytes, bytes2);
while (rs.next()) {
bytes2 = rs.getBytes(2);
......@@ -311,20 +320,28 @@ public class TestLobApi extends TestBase {
NClob nc;
nc = conn.createNClob();
nc.setString(1, new String(data));
assertEquals(length, nc.setString(1, new String(data)));
prep.setInt(1, 5);
prep.setNClob(2, nc);
prep.execute();
prep.setInt(1, 5);
nc = conn.createNClob();
char[] xdata = new char[length + 2];
System.arraycopy(data, 0, xdata, 1, length);
assertEquals(length, nc.setString(1, new String(xdata), 1, length));
prep.setInt(1, 6);
prep.setNClob(2, nc);
prep.execute();
prep.setInt(1, 7);
prep.setNClob(2, new StringReader(new String(data)));
prep.execute();
prep.setInt(1, 6);
prep.setInt(1, 8);
prep.setNClob(2, new StringReader(new String(data)), -1);
prep.execute();
prep.setInt(1, 7);
prep.setInt(1, 9);
prep.setNString(2, new String(data));
prep.execute();
......
......@@ -249,6 +249,8 @@ td.index {
margin: 0px 0px;
border: 2px solid;
-moz-border-radius: 0.4em;
-webkit-border-radius: 0.4em;
-khtml-border-radius: 0.4em;
border-radius: 0.4em;
background-color: #fff;
}
......@@ -259,9 +261,10 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
width: 16px;
height: 24px;
background-image: url(images/div-ts.png);
width: 16px;
background-size: 16px 512px;
}
.ls {
......@@ -270,9 +273,10 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
width: 16px;
height: 24px;
background-image: url(images/div-ls.png);
width: 16px;
background-size: 16px 512px;
}
.ks {
......@@ -281,9 +285,10 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
width: 16px;
height: 24px;
background-image: url(images/div-ks.png);
width: 16px;
background-size: 16px 512px;
}
.te {
......@@ -292,9 +297,10 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
width: 16px;
height: 24px;
background-image: url(images/div-te.png);
width: 16px;
background-size: 16px 512px;
}
.le {
......@@ -303,9 +309,10 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
width: 16px;
height: 24px;
background-image: url(images/div-le.png);
width: 16px;
background-size: 16px 512px;
}
.ke {
......@@ -314,9 +321,10 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
width: 16px;
height: 24px;
background-image: url(images/div-ke.png);
width: 16px;
background-size: 16px 512px;
}
.d {
......@@ -325,8 +333,8 @@ td.index {
margin: 0px;
border-collapse: collapse;
vertical-align: top;
min-width: 16px;
height: 24px;
background-image: url(images/div-d.png);
background-repeat: repeat-x;
min-width: 16px;
background-size: 1024px 512px;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论