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:
How to get data ?
Is there any built in method in there ? or I need to make my own and where?
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.
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/
Related
I need to get information that becomes from an external API client and show that information with an adapter.
My application must use retrofit to get the info from the API, save it into the database (sqlite) and show it using an adapter. An important think to consider is that I wont use retrofit every time I start my application (maybe I update the database once everyday or everyweek).
The dilemma comes when I dont know if I should use a SimpleCursorAdapter so I cannot directly update the adapter with the info I get from retrofit because I have to download the info, introduce the into the database and extract it from databse to show into adapter; or a normal adapter wich can update the adapter directly when i get the info from retrofit but when I dont want to use retrofit and i want just to get info from database I will have to create objects from the info i get from database to update it.
BTW i'm programming in Android. Thanks for helping!
Simplicity vs Customizability.
For me, I always choose default Adapter and create an inherited class as it gives more customizability. That's same reason of what you are saying;
when I dont want to use retrofit and i want just to get info from database I will have to create objects from the info i get from database to update it...
Sometimes the app might require cache (some temporary variable), or complex list output that cannot do only with single query.
I am working on an application whose purpose is to display a listview whose content will depend on which button the user clicks, and whose data come from a sql databse. It means my database will be using a "readable" attribute only, no need to change information from the database.
So, to learn how to do it, I am reading and doing lot of tutorials and i feel a bit lost about what is really required and what is optional in the design of the application.
Here is why. I have learned that to do so, my app will need:
- a ----Helper class (extending SQLiteOpenHelper)
- a ----Adapter class (to define my methods and queries for the database)
- a ----Table class (one class for each table of my database)
- my MainActivity (in my case, extending ListActivities)
And then, i found out that to do so I also need :
- CursorLoader
- ContentProvider
- fillData()
Every time I try to learn more, I find out about more and more classes or methods to use, it seems endless and I don't know if I really need to have that many classes for my application.
If someone can tell me if it seems right to have that many things, thanks in advance!
First of all, you need to have a high level overview of what exactly you are going to do with the database and how. And, what you have figured out is almost correct.
Basic Steps for any DB app in android are :
You will require Helper class, using which you can create or upgrade database along with tables.
Once you have database ready, there is a need for the class which will contain the data that you need to save in the database.
And lastly, there will be a class which will fire queries and retrieve data from database.
Till here, all backend functions are complete. Now you need to display the data that you have retrieved from db. For which, you use another class(in your class, one which extends ListActivity).
Don't get overwhelmed by number of classes, all the functionalities are kept in separate classes just to avoid cluttered code. But the basic steps remain same !
And then, i found out that to do so I also need :
- CursorLoader
- ContentProvider
- fillData()
Yes, these are different things that you could use to perform required function, like ContentProvider is used if you want to share data with other applications. So just figure out if you want to do that, and then only move ahead. Else the basic steps are enough.
Hope this helps!
You may refer a very nice tutorial on this : http://www.vogella.com/articles/AndroidSQLite/article.html
I am developing an App in which now i have to create database for more better user experience. Then i came to know about DB4o which is many times faster tool for creating database than other like SQLite, MySql etc, but the problem is i am not able to find any single example that explains about DB4o and how to create database using Db4o. If anybody has used it, please post an example or send me link.
To store the object in database use
db().store(exercise);
To retrieve All records from database, use
db().query(Object);
To retrieve particular record from database, use
db().queryByExample(Object);
If you need example, Try My blog example using db4o.
In this example, simple student object will be stored in database using db4o. Student object will contain student name, register number, and his age.
Thank you.
In the Parse android docs it says that by default, related ParsePbjects are not fetched, implying that there is a setting that will fetch them. It later says that they cannot be fetched without a call to fetchIfNeeded. Which is it? I definitely need to fetch the related ParseObject and would prefer to do so without having to make multiple requests. Is that possible?
By default, when fetching an object, related ParseObjects are not fetched. These objects' values cannot be retrieved until they have been fetched like so:
In the ParseQuery you are using to get the original object, you can use the include(key) method to tell it to also fetch the related object. This works for pointers and arrays of pointers.
No They Can't. I am also facing the similar problem. SO if you have two table and one table is having reference key from second table, then there is no such query where we can find relative data.
Its Sad. I wonder why they don't provide such a useful thing.
I am making an android hangman game which has two classes one that holds the data base and one that has the game, what I need to do is get a single value from my database column that holds the words and return it as a string to be used in the game class. My question is how should I write the method that will be in my database class to return the value from the sqlite database and set it as a string to be sent on. I just can't seem to figure out what the sql statement or method should be I have tried many things and have got nowhere with it for days now, please please please help if you can.
Essentially what you're asking us is the whole sqlite schema which is way too broad to express in one answer. Here are some videos that I used to learn. Kudos to Travis/thenewboston for teaching me how to programming from scratch. After trying these, ask again if you're having Amy trouble with anything :)
Open your database using getReadableDatabase().
Execute your query and get Cursor.
Call getString() in cursor with proper column index.
This is the basic steps to retrieve values from database