Skip to content

Commit c5f11a5

Browse files
authored
Merge pull request #3378 from katzyn/lob
Fix LOBs in data change delta tables
2 parents ccaadc0 + 1392152 commit c5f11a5

File tree

7 files changed

+64
-10
lines changed

7 files changed

+64
-10
lines changed

h2/src/docsrc/html/changelog.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ <h1>Change Log</h1>
2121

2222
<h2>Next Version (unreleased)</h2>
2323
<ul>
24+
<li>Issue #3376: Data cannot be read after insert of clob data > MAX_LENGTH_INPLACE_LOB with data change delta table
25+
</li>
26+
<li>PR #3377: Add -webExternalNames setting and fix WebServer.getConnection()
27+
</li>
2428
<li>PR #3367: Use faster checks of dimension systems of geometries
2529
</li>
2630
<li>PR #3369: Added v2 changes in migration docs

h2/src/main/org/h2/command/Parser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,10 @@ private Table readDataChangeDeltaTable(String resultOptionName, int backupIndex)
19891989
throw getSyntaxError();
19901990
}
19911991
read(CLOSE_PAREN);
1992+
if (currentSelect != null) {
1993+
// Lobs aren't copied, so use it for more safety
1994+
currentSelect.setNeverLazy(true);
1995+
}
19921996
return new DataChangeDeltaTable(getSchemaWithDefault(), session, statement, resultOption);
19931997
}
19941998

h2/src/main/org/h2/result/LocalResult.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static LocalResult forTable(SessionLocal session, Table table) {
6262
private int visibleColumnCount;
6363
private int resultColumnCount;
6464
private Expression[] expressions;
65+
private boolean forDataChangeDeltaTable;
6566
private long rowId, rowCount;
6667
private ArrayList<Value[]> rows;
6768
private SortOrder sort;
@@ -140,6 +141,13 @@ public void setMaxMemoryRows(int maxValue) {
140141
this.maxMemoryRows = maxValue;
141142
}
142143

144+
/**
145+
* Sets value collection mode for data change delta tables.
146+
*/
147+
public void setForDataChangeDeltaTable() {
148+
forDataChangeDeltaTable = true;
149+
}
150+
143151
/**
144152
* Create a shallow copy of the result set. The data and a temporary table
145153
* (if there is any) is not copied.
@@ -343,10 +351,14 @@ private void cloneLobs(Value[] values) {
343351
for (int i = 0; i < values.length; i++) {
344352
Value v = values[i];
345353
if (v instanceof ValueLob) {
346-
ValueLob v2 = ((ValueLob) v).copyToResult();
347-
if (v2 != v) {
354+
if (forDataChangeDeltaTable) {
348355
containsLobs = true;
349-
values[i] = session.addTemporaryLob(v2);
356+
} else {
357+
ValueLob v2 = ((ValueLob) v).copyToResult();
358+
if (v2 != v) {
359+
containsLobs = true;
360+
values[i] = session.addTemporaryLob(v2);
361+
}
350362
}
351363
}
352364
}

h2/src/main/org/h2/server/web/WebThread.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,22 @@ private boolean process() throws IOException {
184184
message += "Transfer-Encoding: chunked\r\n";
185185
message += "\r\n";
186186
trace(message);
187-
output.write(message.getBytes());
187+
output.write(message.getBytes(StandardCharsets.ISO_8859_1));
188188
while (it.hasNext()) {
189189
String s = it.next();
190190
s = PageParser.parse(s, session.map);
191191
bytes = s.getBytes(StandardCharsets.UTF_8);
192192
if (bytes.length == 0) {
193193
continue;
194194
}
195-
output.write(Integer.toHexString(bytes.length).getBytes());
196-
output.write("\r\n".getBytes());
195+
output.write(Integer.toHexString(bytes.length).getBytes(StandardCharsets.ISO_8859_1));
196+
output.write(RN);
197197
output.write(bytes);
198-
output.write("\r\n".getBytes());
198+
output.write(RN);
199199
output.flush();
200200
}
201-
output.write("0\r\n\r\n".getBytes());
201+
output.write('0');
202+
output.write(RNRN);
202203
output.flush();
203204
return keepAlive;
204205
}
@@ -217,7 +218,7 @@ private boolean process() throws IOException {
217218
message += "Content-Length: " + bytes.length + "\r\n";
218219
message += "\r\n";
219220
trace(message);
220-
output.write(message.getBytes());
221+
output.write(message.getBytes(StandardCharsets.ISO_8859_1));
221222
output.write(bytes);
222223
output.flush();
223224
return keepAlive;
@@ -252,6 +253,9 @@ private boolean checkHost(String host) throws IOException {
252253
if (index >= 0) {
253254
host = host.substring(0, index);
254255
}
256+
if (host.isEmpty()) {
257+
return false;
258+
}
255259
if (host.equals(server.getHost()) || host.equals("localhost") || host.equals("127.0.0.1")) {
256260
return true;
257261
}

h2/src/main/org/h2/store/fs/encrypt/FileEncrypt.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.ByteBuffer;
1111
import java.nio.channels.FileChannel;
1212
import java.nio.channels.FileLock;
13+
import java.nio.charset.StandardCharsets;
1314
import java.util.Arrays;
1415
import org.h2.security.AES;
1516
import org.h2.security.SHA256;
@@ -37,7 +38,7 @@ public class FileEncrypt extends FileBaseDefault {
3738
*/
3839
static final int HEADER_LENGTH = BLOCK_SIZE;
3940

40-
private static final byte[] HEADER = "H2encrypt\n".getBytes();
41+
private static final byte[] HEADER = "H2encrypt\n".getBytes(StandardCharsets.ISO_8859_1);
4142
private static final int SALT_POS = HEADER.length;
4243

4344
/**

h2/src/main/org/h2/table/DataChangeDeltaTable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public ResultInterface getResult(SessionLocal session) {
116116
statement.prepare();
117117
int columnCount = expressions.length;
118118
LocalResult result = new LocalResult(session, expressions, columnCount, columnCount);
119+
result.setForDataChangeDeltaTable();
119120
statement.update(result, resultOption);
120121
return result;
121122
}

h2/src/test/org/h2/test/scripts/other/data-change-delta-table.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,31 @@ SELECT * FROM NEW TABLE (MERGE INTO TEST_VIEW TEST USING
387387

388388
DROP TABLE TEST CASCADE;
389389
> ok
390+
391+
CREATE TABLE TEST(ID BIGINT, DATA CHARACTER LARGE OBJECT);
392+
> ok
393+
394+
INSERT INTO TEST VALUES (1, REPEAT('A', 1000));
395+
> update count: 1
396+
397+
SELECT ID FROM FINAL TABLE (INSERT INTO TEST VALUES (2, REPEAT('B', 1000)));
398+
>> 2
399+
400+
SELECT ID, SUBSTRING(DATA FROM 1 FOR 2) FROM TEST;
401+
> ID SUBSTRING(DATA FROM 1 FOR 2)
402+
> -- ----------------------------
403+
> 1 AA
404+
> 2 BB
405+
> rows: 2
406+
407+
@reconnect
408+
409+
SELECT ID, SUBSTRING(DATA FROM 1 FOR 2) FROM TEST;
410+
> ID SUBSTRING(DATA FROM 1 FOR 2)
411+
> -- ----------------------------
412+
> 1 AA
413+
> 2 BB
414+
> rows: 2
415+
416+
DROP TABLE TEST;
417+
> ok

0 commit comments

Comments
 (0)