Search in sources :

Example 11 with SimpleStatementListener

use of org.firebirdsql.gds.ng.wire.SimpleStatementListener in project jaybird by FirebirdSQL.

the class BaseTestBlob method getBlobId.

/**
 * Queries the blob table for the blob id of the record with the specified (row) id.
 * @param testId Id of the row
 * @param db database to use
 * @return Blob id
 * @throws SQLException For errors executing the query
 */
protected long getBlobId(int testId, FbDatabase db) throws SQLException {
    listener = new SimpleStatementListener();
    transaction = getTransaction(db);
    statement = db.createStatement(transaction);
    statement.addStatementListener(listener);
    statement.prepare(SELECT_BLOB_TABLE);
    FieldValue param1 = new FieldValue(db.getDatatypeCoder().encodeInt(testId));
    statement.execute(RowValue.of(param1));
    assertEquals("Expected hasResultSet to be set to true", Boolean.TRUE, listener.hasResultSet());
    statement.fetchRows(1);
    assertEquals("Expected a row", 1, listener.getRows().size());
    RowValue row = listener.getRows().get(0);
    FieldValue blobIdFieldValue = row.getFieldValue(0);
    return db.getDatatypeCoder().decodeLong(blobIdFieldValue.getFieldData());
}
Also used : SimpleStatementListener(org.firebirdsql.gds.ng.wire.SimpleStatementListener) RowValue(org.firebirdsql.gds.ng.fields.RowValue) FieldValue(org.firebirdsql.gds.ng.fields.FieldValue)

Example 12 with SimpleStatementListener

use of org.firebirdsql.gds.ng.wire.SimpleStatementListener in project jaybird by FirebirdSQL.

the class TestJnaStatement method testMultipleExecute.

@Test
public void testMultipleExecute() throws Exception {
    allocateStatement();
    statement.prepare("SELECT RDB$DESCRIPTION AS \"Description\", RDB$RELATION_ID, RDB$SECURITY_CLASS, RDB$CHARACTER_SET_NAME " + "FROM RDB$DATABASE");
    final SimpleStatementListener statementListener = new SimpleStatementListener();
    statement.addStatementListener(statementListener);
    statement.execute(RowValue.EMPTY_ROW_VALUE);
    assertEquals("Expected hasResultSet to be set to true", Boolean.TRUE, statementListener.hasResultSet());
    assertEquals("Expected hasSingletonResult to be set to false", Boolean.FALSE, statementListener.hasSingletonResult());
    assertNull("Expected allRowsFetched not set yet", statementListener.isAllRowsFetched());
    assertEquals("Expected no rows to be fetched yet", 0, statementListener.getRows().size());
    // JNAStatement only executes a single fetch to prevent problems with positioned updates,
    // so this doesn't get all rows fetched immediately
    statement.fetchRows(10);
    assertEquals("Expected allRowsFetched to haven't been called yet", null, statementListener.isAllRowsFetched());
    assertEquals("Expected a single row to have been fetched", 1, statementListener.getRows().size());
    statement.fetchRows(1);
    assertEquals("Expected allRowsFetched to be set to true", Boolean.TRUE, statementListener.isAllRowsFetched());
    assertEquals("Expected a single row to have been fetched", 1, statementListener.getRows().size());
    statement.closeCursor();
    final SimpleStatementListener statementListener2 = new SimpleStatementListener();
    statement.addStatementListener(statementListener2);
    statement.execute(RowValue.EMPTY_ROW_VALUE);
    assertEquals("Expected hasResultSet to be set to true", Boolean.TRUE, statementListener2.hasResultSet());
    assertEquals("Expected hasSingletonResult to be set to false", Boolean.FALSE, statementListener2.hasSingletonResult());
    assertNull("Expected allRowsFetched not set yet", statementListener2.isAllRowsFetched());
    assertEquals("Expected no rows to be fetched yet", 0, statementListener2.getRows().size());
    // JNAStatement only executes a single fetch to prevent problems with positioned updates,
    // so this doesn't get all rows fetched immediately
    statement.fetchRows(10);
    assertEquals("Expected allRowsFetched to haven't been called yet", null, statementListener2.isAllRowsFetched());
    assertEquals("Expected a single row to have been fetched", 1, statementListener2.getRows().size());
    statement.fetchRows(1);
    assertEquals("Expected allRowsFetched to be set to true", Boolean.TRUE, statementListener2.isAllRowsFetched());
    assertEquals("Expected a single row to have been fetched", 1, statementListener2.getRows().size());
}
Also used : SimpleStatementListener(org.firebirdsql.gds.ng.wire.SimpleStatementListener) AbstractStatementTest(org.firebirdsql.gds.ng.AbstractStatementTest) Test(org.junit.Test)

Aggregations

SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)12 Test (org.junit.Test)9 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)5 AbstractStatementTest (org.firebirdsql.gds.ng.AbstractStatementTest)3 RowValue (org.firebirdsql.gds.ng.fields.RowValue)2 Encoding (org.firebirdsql.encodings.Encoding)1 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)1 DatatypeCoder (org.firebirdsql.gds.ng.DatatypeCoder)1 FbBlob (org.firebirdsql.gds.ng.FbBlob)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)1 RowDescriptor (org.firebirdsql.gds.ng.fields.RowDescriptor)1 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)1