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());
}
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());
}
Aggregations