@Test
public void testRowCountIsStateless() throws SqlJetException {
db.runReadTransaction(new ISqlJetTransaction() {
public Object run(SqlJetDb db) throws SqlJetException {
SqlJetScope scope = new SqlJetScope(new Object[] {"AB"}, new Object[] {"BC"});
ISqlJetCursor cursor = db.getTable("table").scope("names_idx", scope);
Assert.assertTrue(!cursor.eof());
long count = cursor.getRowCount();
Assert.assertTrue(count > 0);
Assert.assertTrue(!cursor.eof());
Assert.assertTrue(!cursor.eof());
Assert.assertTrue(cursor.getRowCount() > 0);
cursor.close();
cursor = db.getTable("table").scope("names_idx", scope);
// now at 0.
count = cursor.getRowCount();
Assert.assertTrue(count > 0);
Assert.assertTrue(!cursor.eof());
Assert.assertTrue(cursor.getRowCount() > 0);
Assert.assertTrue(!cursor.eof());
Assert.assertTrue(cursor.next());
// now at 1.
Assert.assertFalse(cursor.eof());
Assert.assertTrue(cursor.getRowCount() == 3);
Assert.assertTrue(cursor.next());
// now at 2.
Assert.assertFalse(cursor.eof());
Assert.assertFalse(cursor.eof());
Assert.assertTrue(cursor.getRowCount() == 3);
Assert.assertFalse(cursor.next());
// now at eof
Assert.assertTrue(cursor.eof());
Assert.assertTrue(cursor.previous());
// at 2.
Assert.assertTrue(cursor.getRowCount() == 3);
Assert.assertFalse(cursor.eof());
Assert.assertTrue(cursor.previous());
// at 1.
Assert.assertTrue(cursor.getRowCount() == 3);
Assert.assertFalse(cursor.eof());
Assert.assertTrue(cursor.previous());
// at 0.
Assert.assertFalse(cursor.previous());
Assert.assertTrue(cursor.eof());
Assert.assertTrue(cursor.getRowCount() == 3);
Assert.assertTrue(cursor.first());
Assert.assertFalse(cursor.eof());
Assert.assertTrue(cursor.getRowCount() == 3);
Assert.assertTrue(cursor.last());
Assert.assertFalse(cursor.eof());
Assert.assertTrue(cursor.getRowCount() == 3);
cursor.close();
return null;
}
});
}