-2

I am using greendao for the first time. and it is going good. I have generated code and entities. I have put the basic data and checked it using sqlite browser and all data is there in specific fields.

Now there are some method in the dao class and I have used the insert method to insert the data. But Now I have to get data so looking how to return the data. here are my some of the questions:

  1. How to get data ?

  2. Is there any built in method in there ? or I need to make my own and where?

  3. I need to know when should I need to close connection and what things I need to take in account while using greendao ?

please provide some source code or any demo code on How I can get data. I have no source code to share on , As rest is basic code generated by the dao. And I think it would be childish question , but I have not found any documentation telling about its method it have etc. Please help me in my problem described above and also clear my confusions.

Allay Khalil
  • 674
  • 3
  • 11
  • 31

1 Answers1

5

To retrieve your data you have to use greenDao Queries. You can specify your own conditions to match rows.

Example (extracted from docs):

List joes = userDao.queryBuilder()
    .where(Properties.FirstName.eq("Joe"))
    .orderAsc(Properties.LastName)
    .list();

Here is the docs (with demos): http://greenrobot.org/greendao/documentation/queries/

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
  • where should I write these lines ? – Allay Khalil Mar 10 '16 at 13:34
  • @AllayKhalil You can write this in your `Activity`. You have to get a instance of your `Dao` class, and use `queryBuilder` method to filter data, as in above **example**. I suggest you to read this great tutorial: http://www.devteam83.com/en/tutorial-greendao-from-scratch-part-1/ – Allan Pereira Mar 10 '16 at 13:53
  • great One thing more, While reading your link in the answer I saw two things one is .list() and other is listLazy () , I got little by their explanation and that is , it loads the items in the list like lazy list ? but I am confused as lazy list is graphical thing ? – Allay Khalil Mar 10 '16 at 14:07
  • The `list()` method run the query, build the list with entities and load it into memory. When using `listLazy()`, the entities are loaded into memory only when are accessed. Therefore, you if do not access the entity, it is not loaded into memory. – Allan Pereira Mar 10 '16 at 14:55