Search in sources :

Example 36 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method testSetBinaryStreamLengthLess65KOnBlob.

public void testSetBinaryStreamLengthLess65KOnBlob() throws IOException, SQLException {
    int length = 65 * 1024;
    setBinaryStreamOnBlob(key, length, -1, 0, true);
    psFetchBlob.setInt(1, key);
    ResultSet rs = psFetchBlob.executeQuery();
    assertTrue("Empty resultset", rs.next());
    LoopingAlphabetStream s1 = new LoopingAlphabetStream(length);
    assertEquals(new LoopingAlphabetStream(length), rs.getBinaryStream(1));
    assertFalse("Resultset should have been exhausted", rs.next());
    rs.close();
}
Also used : ResultSet(java.sql.ResultSet) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 37 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method testSetAsciiStreamLengthLess32KOnClob.

public void testSetAsciiStreamLengthLess32KOnClob() throws IOException, SQLException {
    int length = 32 * 1024;
    setAsciiStream(psInsertClob, key, length, -1, 0, true);
    psFetchClob.setInt(1, key);
    ResultSet rs = psFetchClob.executeQuery();
    assertTrue("Empty resultset", rs.next());
    assertEquals(new LoopingAlphabetStream(length), rs.getAsciiStream(1));
    assertFalse("Resultset should have been exhausted", rs.next());
    rs.close();
}
Also used : ResultSet(java.sql.ResultSet) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 38 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method testSetAsciiStreamLengthLess65KOnClob.

public void testSetAsciiStreamLengthLess65KOnClob() throws IOException, SQLException {
    int length = 65 * 1024;
    setAsciiStream(psInsertClob, key, length, -1, 0, true);
    psFetchClob.setInt(1, key);
    ResultSet rs = psFetchClob.executeQuery();
    assertTrue("Empty resultset", rs.next());
    assertEquals(new LoopingAlphabetStream(length), rs.getAsciiStream(1));
    assertFalse("Resultset should have been exhausted", rs.next());
    rs.close();
}
Also used : ResultSet(java.sql.ResultSet) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 39 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method testSetAsciiStreamLengthLess1KOnClob.

public void testSetAsciiStreamLengthLess1KOnClob() throws IOException, SQLException {
    int length = 1 * 1024;
    setAsciiStream(psInsertClob, key, length, -1, 0, true);
    psFetchClob.setInt(1, key);
    ResultSet rs = psFetchClob.executeQuery();
    assertTrue("Empty resultset", rs.next());
    assertEquals(new LoopingAlphabetStream(length), rs.getAsciiStream(1));
    assertFalse("Resultset should have been exhausted", rs.next());
    rs.close();
}
Also used : ResultSet(java.sql.ResultSet) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 40 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method setAsciiStream.

/**
 * Insert data into a column with setAsciiStream.
 * The prepared statement passed must have two positional parameters;
 * one int and one more. Depending on the last parameter, the execute
 * might succeed or it might fail. This is intended behavior, and should
 * be handled by the caller. For instance, calling this method on an
 * INT-column would fail, calling it on a CLOB-column would succeed.
 *
 * @param id unique id for inserted row
 * @param actualLength the actual length of the stream
 * @param specifiedLength the specified length of the stream
 * @param trailingBlanks number of characters at the end that is blank
 * @param lengthLess whether to use the length less overloads or not
 */
private void setAsciiStream(PreparedStatement ps, int id, int actualLength, int specifiedLength, int trailingBlanks, boolean lengthLess) throws SQLException {
    ps.setInt(1, id);
    if (lengthLess) {
        ps.setAsciiStream(2, new LoopingAlphabetStream(actualLength, trailingBlanks));
    } else {
        ps.setAsciiStream(2, new LoopingAlphabetStream(actualLength, trailingBlanks), specifiedLength);
    }
    assertEquals("Insert with setAsciiStream failed", 1, ps.executeUpdate());
}
Also used : LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Aggregations

LoopingAlphabetStream (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)61 PreparedStatement (java.sql.PreparedStatement)33 InputStream (java.io.InputStream)31 ResultSet (java.sql.ResultSet)31 Statement (java.sql.Statement)20 Blob (java.sql.Blob)10 SQLException (java.sql.SQLException)9 LoopingAlphabetReader (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)9 PositionedStoreStream (org.apache.derby.impl.jdbc.PositionedStoreStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Connection (java.sql.Connection)7 OutputStream (java.io.OutputStream)5 Reader (java.io.Reader)5 Clob (java.sql.Clob)3 Timestamp (java.sql.Timestamp)3 DataInputStream (java.io.DataInputStream)2 EOFException (java.io.EOFException)2 CallableStatement (java.sql.CallableStatement)2 Date (java.sql.Date)2 Time (java.sql.Time)2