Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor for CursorAdapter? #155

Closed
emmx opened this issue Sep 1, 2014 · 5 comments · Fixed by #312
Closed

Cursor for CursorAdapter? #155

emmx opened this issue Sep 1, 2014 · 5 comments · Fixed by #312
Labels
Milestone

Comments

@emmx
Copy link

emmx commented Sep 1, 2014

Is there a way to get a cursor from queries such as the following ones?

Select
    .from(TestRecord.class)
    .where(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2))
    .list()
Book.listAll(Book.class)

I don't want to get a list of all matching items since I expect to have quite a lot of them. I want a cursor instead to use in a CursorAdapter to fill a ListView.

What's the way to go here?

@ScottEAdams
Copy link

I answered my own question about this yesterday in #154

public static Cursor getCursor() {
        SQLiteDatabase db = new SugarDb(MyApp.getInstance()).getDB();
        return db.rawQuery("Select * etc etc", null);
    }

@emmx
Copy link
Author

emmx commented Sep 2, 2014

I saw your workaround. I'm writing a couple of thoughts about it below.

You're writing the query yourself, it's not a good practice. Even if you don't mind doing so, there should be a .getSQL() or something so that we can use the query builder instead. Additionally, I've seen that internally Sugar uses cursors, it just doesn't provide a method to get a reference of it. Using SQLiteDatabase directly kind of break the abstraction layer. It's not entirely bad, but I added Sugar to this project in which I'm working so I didn't have to do that!

I just realized there is no way to inflate a SugarRecord given a cursor, or I couldn't find such a method. There is one .inflate() in SugarRecord but it's defined as private.

@martintama
Copy link

Are there any updates on this?

@whoshuu
Copy link
Collaborator

whoshuu commented Apr 2, 2015

This has been requested a few times. I'll get it into 1.4.0! If someone can put up a pull request I'd be happy to merge it in

@whoshuu whoshuu added this to the 1.4.0 milestone Apr 2, 2015
@whoshuu whoshuu added the feature label Apr 2, 2015
@benohalloran
Copy link
Contributor

@whoshuu see PR 312

@sibelius sibelius modified the milestones: 1.4.0, 1.5.0 Nov 12, 2015
sibelius added a commit that referenced this issue Nov 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants