use of org.apache.derbyTesting.functionTests.util.TestInputStream in project derby by apache.
the class AlterTableTest method testJira4256.
public void testJira4256() throws SQLException {
Statement st = createStatement();
createTestObjects(st);
// increase the maximum size of the clob
int val = 1;
int size = 15 * 1024;
InputStream stream;
st.executeUpdate("create table clob_tab(c1 int,clob_col clob(10K))");
commit();
PreparedStatement pSt = prepareStatement("INSERT INTO clob_tab values (?,?)");
stream = new TestInputStream(size, val);
// this insert fails(size>10K)
pSt.setInt(1, val);
pSt.setAsciiStream(2, stream, size);
assertStatementError("XJ001", pSt);
pSt.close();
rollback();
st.executeUpdate("ALTER TABLE clob_tab ALTER COLUMN " + "clob_col SET DATA TYPE clob(20K)");
pSt = prepareStatement("INSERT INTO clob_tab values (?,?)");
stream = new TestInputStream(size, val);
// this insert succeed (maximum blob size not increased to 20K)
pSt.setInt(1, val);
pSt.setAsciiStream(2, stream, size);
pSt.executeUpdate();
pSt.close();
// increase the maximum size of the blob
st.executeUpdate("CREATE TABLE blob_tab ( C1 INTEGER," + "blob_col BLOB(10K) NOT NULL)");
commit();
pSt = prepareStatement("INSERT INTO blob_tab values (?,?)");
stream = new TestInputStream(size, val);
// this insert fails(size>10K)
pSt.setInt(1, val);
pSt.setBinaryStream(2, stream, size);
assertStatementError("22001", pSt);
pSt.close();
rollback();
st.executeUpdate("ALTER TABLE blob_tab ALTER COLUMN " + "blob_col SET DATA TYPE blob(20K)");
pSt = prepareStatement("INSERT INTO blob_tab values (?,?)");
stream = new TestInputStream(size, val);
// this insert succeed (maximum blob size not increased to 20K)
pSt.setInt(1, val);
pSt.setBinaryStream(2, stream, size);
pSt.executeUpdate();
pSt.close();
rollback();
}
use of org.apache.derbyTesting.functionTests.util.TestInputStream in project derby by apache.
the class BLOBDataModelSetup method setUp.
/**
* The setup creates a Connection to the database, and creates a table
* with blob columns.
* @exception Exception any exception will cause test to fail with error.
*/
protected final void setUp() throws Exception {
Connection con = getConnection();
con.setAutoCommit(false);
// Create table:
final Statement statement = con.createStatement();
statement.executeUpdate("CREATE TABLE " + tableName + " (" + " val INTEGER," + " length INTEGER, " + " data BLOB(2G) NOT NULL)");
statement.close();
// Insert some data:
final PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO " + tableName + "(val, length, data) VALUES (?,?, ?)");
// Insert 10 records with size of 1MB
for (int i = 0; i < regularBlobs; i++) {
final int val = i;
final InputStream stream = new TestInputStream(size, val);
preparedStatement.setInt(1, val);
preparedStatement.setInt(2, size);
preparedStatement.setBinaryStream(3, stream, size);
preparedStatement.executeUpdate();
}
// Insert 1 record with size of 64 MB
BaseJDBCTestCase.println("Insert BLOB with size = " + bigSize);
preparedStatement.setInt(1, bigVal);
preparedStatement.setInt(2, bigSize);
final InputStream stream = new TestInputStream(bigSize, bigVal);
preparedStatement.setBinaryStream(3, stream, bigSize);
BaseJDBCTestCase.println("Execute update");
preparedStatement.executeUpdate();
preparedStatement.close();
BaseJDBCTestCase.println("Commit");
con.commit();
}
use of org.apache.derbyTesting.functionTests.util.TestInputStream in project derby by apache.
the class BLOBTest method testUpdateBlobWithPositionedUpdate.
/**
* Tests updating the Blob using positioned updates
* @param rs result set, currently positioned on row to be updated
* @param newVal new value in val column and blob data
* @param newSize new size of Blob
* @exception SQLException causes test to fail with error
* @exception IOException causes test to fail with error
*/
private void testUpdateBlobWithPositionedUpdate(final ResultSet rs, final int newVal, final int newSize) throws SQLException, IOException {
final PreparedStatement preparedStatement = prepareStatement("UPDATE " + BLOBDataModelSetup.getBlobTableName() + " SET val=?, length = ?, data = ? WHERE CURRENT OF " + rs.getCursorName());
println("UpdateBlob");
final TestInputStream newStream = new TestInputStream(newSize, newVal);
preparedStatement.setInt(1, newVal);
preparedStatement.setInt(2, newSize);
preparedStatement.setBinaryStream(3, newStream, newSize);
preparedStatement.executeUpdate();
println("Verify updated blob with another query");
verifyNewValueInTable(newVal, newSize);
}
use of org.apache.derbyTesting.functionTests.util.TestInputStream in project derby by apache.
the class BLOBTest method testUpdateBlobWithResultSetMethods.
/**
* Tests updating the Blob using result set update methods.
* @param rs result set, currently positioned on row to be updated
* @param newVal new value in val column and blob data
* @param newSize new size of Blob
* @exception SQLException causes test to fail with error
* @exception IOException causes test to fail with error
*/
private void testUpdateBlobWithResultSetMethods(final ResultSet rs, final int newVal, final int newSize) throws SQLException, IOException {
int val = rs.getInt("VAL");
int size = rs.getInt("LENGTH");
println("VerifyBlob");
verifyBlob(val, size, rs.getBlob("DATA"));
println("UpdateBlob");
final TestInputStream newStream = new TestInputStream(newSize, newVal);
rs.updateInt("VAL", newVal);
rs.updateInt("LENGTH", newSize);
rs.updateBinaryStream("DATA", newStream, newSize);
rs.updateRow();
println("Verify updated blob with another query");
verifyNewValueInTable(newVal, newSize);
}
Aggregations