Search in sources :

Example 11 with Select

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

the class ExistsTest method testExistsEmptyResult.

/**
     * Should return {@code false} since the where-clause matches zero rows and thus the result set
     * is empty.
     */
public void testExistsEmptyResult() {
    cleanTable();
    populateTable();
    From from = new Select().from(MockModel.class).where("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 12 with Select

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

the class ExistsTest method testCountOrderBySql.

/**
     * Shouldn't include <i>order by</i> as it has no influence on the result of <i>exists</i> and
     * should improve performance.
     */
public void testCountOrderBySql() {
    final String expected = "SELECT EXISTS(SELECT 1 FROM MockModel WHERE intField <> ? GROUP BY intField )";
    String actual = new Select().from(MockModel.class).groupBy("intField").orderBy("intField").where("intField <> ?", 0).toExistsSql();
    assertEquals(expected, actual);
}
Also used : Select(com.activeandroid.query.Select)

Example 13 with Select

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

the class SelectTest method testSelectDistinct.

public void testSelectDistinct() {
    assertSqlEquals("SELECT DISTINCT * ", new Select().distinct());
    assertSqlEquals("SELECT DISTINCT * ", new Select().all().distinct());
}
Also used : Select(com.activeandroid.query.Select)

Example 14 with Select

use of com.activeandroid.query.Select in project nmid-headline by miao1007.

the class FavFeedFragment method loadNewFeeds.

@Override
void loadNewFeeds() {
    List<Feed> feeds = new ArrayList<>();
    feeds = new Select().from(Feed.class).orderBy("idMember desc").limit(this.feed_limit).execute();
    if (feeds == null || feeds.isEmpty()) {
        showErrorView(View.VISIBLE);
    } else {
        newsBeans.addAll(feeds);
        adapter.notifyDataSetChanged();
    }
    mSwipeRefreshLayout.setRefreshing(false);
}
Also used : ArrayList(java.util.ArrayList) Select(com.activeandroid.query.Select) Feed(cn.edu.cqupt.nmid.headline.support.repository.headline.bean.Feed)

Example 15 with Select

use of com.activeandroid.query.Select in project AnimeTaste by daimajia.

the class Animation method addToFavorite.

public void addToFavorite(final UpdateFinishCallback callback) {
    IsFav = true;
    new Thread() {

        @Override
        public void run() {
            super.run();
            boolean exist = new Select().from(Animation.class).where("AnimationId='" + AnimationId + "'").executeSingle() != null;
            if (!exist)
                save();
            else
                new com.activeandroid.query.Update(Animation.class).set("IsFavorite='1'").where("AnimationId='" + AnimationId + "'").execute();
            Message msg = Message.obtain();
            Looper.prepare();
            msg.setTarget(new FavoriteHandler(callback, Method.ADD_FAVORITE));
            msg.sendToTarget();
            Looper.loop();
        }
    }.start();
}
Also used : Update(com.activeandroid.query.Update) Message(android.os.Message) Select(com.activeandroid.query.Select)

Aggregations

Select (com.activeandroid.query.Select)24 From (com.activeandroid.query.From)11 MockModel (com.activeandroid.test.MockModel)11 ArrayList (java.util.ArrayList)3 Update (com.activeandroid.query.Update)2 Message (android.os.Message)1 Feed (cn.edu.cqupt.nmid.headline.support.repository.headline.bean.Feed)1 Delete (com.activeandroid.query.Delete)1 TypeSerializer (com.activeandroid.serializer.TypeSerializer)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Date (java.util.Date)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1