Search in sources :

Example 1 with From

use of com.activeandroid.query.From in project ActiveAndroid by pardom.

the class CountTest method testCountGroupBy.

/**
     * Should return the total number of rows, even if the rows are grouped. May seem weird, just
     * test it in an SQL explorer.
     */
public void testCountGroupBy() {
    cleanTable();
    populateTable();
    From from = new Select().from(MockModel.class).groupBy("intField").having("intField = 1");
    final List<MockModel> list = from.execute();
    final int count = from.count();
    assertEquals(2, count);
    assertEquals(1, list.size());
}
Also used : MockModel(com.activeandroid.test.MockModel) Select(com.activeandroid.query.Select) From(com.activeandroid.query.From)

Example 2 with From

use of com.activeandroid.query.From in project ActiveAndroid by pardom.

the class CountTest method testCountEmptyResult.

/**
     * Should return the same count as there are entries in the result set if the where-clause
     * matches zero entries.
     */
public void testCountEmptyResult() {
    cleanTable();
    populateTable();
    From from = new Select().from(MockModel.class).where("intField = ?", 3);
    final List<MockModel> list = from.execute();
    final int count = from.count();
    assertEquals(0, count);
    assertEquals(list.size(), count);
}
Also used : MockModel(com.activeandroid.test.MockModel) Select(com.activeandroid.query.Select) From(com.activeandroid.query.From)

Example 3 with From

use of com.activeandroid.query.From in project ActiveAndroid by pardom.

the class ExistsTest method testCountGroupBy.

/**
     * Should not change the result if group by is used.
     */
public void testCountGroupBy() {
    cleanTable();
    populateTable();
    From from = new Select().from(MockModel.class).groupBy("intField").having("intField = 1");
    final List<MockModel> list = from.execute();
    final boolean exists = from.exists();
    assertTrue(exists);
    assertTrue(list.size() > 0);
}
Also used : MockModel(com.activeandroid.test.MockModel) Select(com.activeandroid.query.Select) From(com.activeandroid.query.From)

Example 4 with From

use of com.activeandroid.query.From in project ActiveAndroid by pardom.

the class ExistsTest method testCountGroupByEmpty.

/**
     * Should not exist if group by eliminates all rows.
     */
public void testCountGroupByEmpty() {
    cleanTable();
    populateTable();
    From from = new Select().from(MockModel.class).groupBy("intField").having("intField = 3");
    final List<MockModel> list = from.execute();
    final boolean exists = from.exists();
    assertFalse(exists);
    assertFalse(list.size() > 0);
}
Also used : MockModel(com.activeandroid.test.MockModel) Select(com.activeandroid.query.Select) From(com.activeandroid.query.From)

Example 5 with From

use of com.activeandroid.query.From in project ActiveAndroid by pardom.

the class ExistsTest method testExistsWhereClause.

/**
     * Should return {@code true} since the where-clause matches rows and thus the result set isn't
     * empty.
     */
public void testExistsWhereClause() {
    cleanTable();
    populateTable();
    From from = new Select().from(MockModel.class).where("intField = ?", 1);
    final List<MockModel> list = from.execute();
    final boolean exists = from.exists();
    assertTrue(exists);
    assertTrue(list.size() > 0);
}
Also used : MockModel(com.activeandroid.test.MockModel) Select(com.activeandroid.query.Select) From(com.activeandroid.query.From)

Aggregations

From (com.activeandroid.query.From)18 Select (com.activeandroid.query.Select)11 MockModel (com.activeandroid.test.MockModel)11