Description
PROBLEM:
If one creates a table with a large blob column (say 100K), and then tries to insert a CONCATENATED blob value into the table, where one of the blobs to be concatenated is larger than 32672 bytes, a truncation error occurs even though the blob column is large enough to hold the value without truncation.
REPRODUCTION:
Code snippet used to reproduce is as follows:
// Create an array of bytes to be used as the input parameter.
// NOTE: Size of the parameter is greater than 32672.
byte [] bData = new byte[32700];
for (int i = 0; i < bData.length; i++)
bData[i] = (byte)(i % 10);
Statement st = conn1.createStatement();
try
catch (SQLException se)
{ se.printStackTrace(); }NOTES:
It turns out that the truncation error is for the parameter itself, not for the blob column.
As mentioned on the derby-dev list by Dan and Satheesh, it looks like the concatenation operator is promoting the parameter to VARCHAR FOR BIT DATA instead of BLOB. The cause for that particular choice of type could be one of two things: 1) the type of the "?" parameter is mapped to VARCHAR(32762) FOR BIT DATA, and thus the concatentation operator uses that type to infer the result type; or 2) the parameter type is mapped to BLOB, but the concat operator is incorrectly inferring that the result is VARCHAR FOR BIT DATA.
In the case of #1, the question becomes that of what type should the parameter be mapped to? Is VARCHAR FOR BIT DATA correct since we're using "setBytes", or should it in fact be BLOB? Of course, whether or not the parameter mapping needs to change, it would appear that the concatenation operator is going to need modification so that it can determine the correct result type for blobs...